diff --git a/pyproject.toml b/pyproject.toml index 721bcbe..2f20e05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "stream-fusion" -version = "2.0.2" +version = "2.0.4" description = "StreamFusion is an advanced plugin for Stremio that significantly enhances its streaming capabilities with debrid service." authors = ["LimeDrive "] readme = "README.md" diff --git a/stream_fusion/static/config.js b/stream_fusion/static/config.js index 4fc5541..1dc529c 100644 --- a/stream_fusion/static/config.js +++ b/stream_fusion/static/config.js @@ -273,51 +273,62 @@ function loadData() { const currentUrl = window.location.href; let data = currentUrl.match(/\/([^\/]+)\/configure$/); if (data && data[1]) { - try { - const decodedData = JSON.parse(atob(data[1])); - - document.getElementById('jackett').checked = decodedData.jackett; - document.getElementById('cache').checked = decodedData.cache; - document.getElementById('cacheUrl').value = decodedData.cacheUrl; - document.getElementById('zilean').checked = decodedData.zilean; - document.getElementById('yggflix').checked = decodedData.yggflix; - document.getElementById('sharewood').checked = decodedData.sharewood; - document.getElementById('rd_token_info').value = decodedData.RDToken; - document.getElementById('ad_token_info').value = decodedData.ADToken; - document.getElementById('sharewoodPasskey').value = decodedData.sharewoodPasskey; - document.getElementById('yggPasskey').value = decodedData.yggPasskey; - document.getElementById('ApiKey').value = decodedData.apiKey; - document.getElementById('exclusion-keywords').value = (decodedData.exclusionKeywords || []).join(', '); - document.getElementById('maxSize').value = decodedData.maxSize; - document.getElementById('resultsPerQuality').value = decodedData.resultsPerQuality; - document.getElementById('maxResults').value = decodedData.maxResults; - document.getElementById('minCachedResults').value = decodedData.minCachedResults; - document.getElementById('torrenting').checked = decodedData.torrenting; - document.getElementById('ctg_yggtorrent').checked = decodedData.yggtorrentCtg; - document.getElementById('ctg_yggflix').checked = decodedData.yggflixCtg; - document.getElementById('tmdb').checked = decodedData.metadataProvider === 'tmdb'; - document.getElementById('cinemeta').checked = decodedData.metadataProvider === 'cinemeta'; - document.getElementById('debrid_rd').checked = decodedData.service.includes('Real-Debrid'); - document.getElementById('debrid_ad').checked = decodedData.service.includes('AllDebrid'); - - sorts.forEach(sort => { - document.getElementById(sort).checked = decodedData.sort === sort; - }); - - qualityExclusions.forEach(quality => { - document.getElementById(quality).checked = decodedData.exclusion.includes(quality); - }); - - languages.forEach(language => { - document.getElementById(language).checked = decodedData.languages.includes(language); - }); - - updateProviderFields(); - } catch (error) { - console.error("Error decoding data:", error); + try { + const decodedData = JSON.parse(atob(data[1])); + + function setElementValue(id, value) { + const element = document.getElementById(id); + if (element) { + if (typeof value === 'boolean') { + element.checked = value; + } else { + element.value = value; + } + } } + + setElementValue('jackett', decodedData.jackett ?? false); + setElementValue('cache', decodedData.cache ?? false); + setElementValue('cacheUrl', decodedData.cacheUrl || ''); + setElementValue('zilean', decodedData.zilean ?? false); + setElementValue('yggflix', decodedData.yggflix ?? false); + setElementValue('sharewood', decodedData.sharewood ?? false); + setElementValue('rd_token_info', decodedData.RDToken || ''); + setElementValue('ad_token_info', decodedData.ADToken || ''); + setElementValue('sharewoodPasskey', decodedData.sharewoodPasskey || ''); + setElementValue('yggPasskey', decodedData.yggPasskey || ''); + setElementValue('ApiKey', decodedData.apiKey || ''); + setElementValue('exclusion-keywords', (decodedData.exclusionKeywords || []).join(', ')); + setElementValue('maxSize', decodedData.maxSize || ''); + setElementValue('resultsPerQuality', decodedData.resultsPerQuality || ''); + setElementValue('maxResults', decodedData.maxResults || ''); + setElementValue('minCachedResults', decodedData.minCachedResults || ''); + setElementValue('torrenting', decodedData.torrenting ?? false); + setElementValue('ctg_yggtorrent', decodedData.yggtorrentCtg ?? false); + setElementValue('ctg_yggflix', decodedData.yggflixCtg ?? false); + setElementValue('tmdb', decodedData.metadataProvider === 'tmdb'); + setElementValue('cinemeta', decodedData.metadataProvider === 'cinemeta'); + setElementValue('debrid_rd', decodedData.service?.includes('Real-Debrid') ?? false); + setElementValue('debrid_ad', decodedData.service?.includes('AllDebrid') ?? false); + + sorts.forEach(sort => { + setElementValue(sort, decodedData.sort === sort); + }); + + qualityExclusions.forEach(quality => { + setElementValue(quality, decodedData.exclusion?.includes(quality) ?? false); + }); + + languages.forEach(language => { + setElementValue(language, decodedData.languages?.includes(language) ?? false); + }); + + updateProviderFields(); + } catch (error) { + console.error("Error decoding data:", error); + } } -} + } function getLink(method) { const data = { diff --git a/stream_fusion/utils/debrid/realdebrid.py b/stream_fusion/utils/debrid/realdebrid.py index fc7e1cb..3b10d00 100644 --- a/stream_fusion/utils/debrid/realdebrid.py +++ b/stream_fusion/utils/debrid/realdebrid.py @@ -3,7 +3,6 @@ from urllib.parse import unquote from fastapi import HTTPException -import requests from stream_fusion.constants import NO_CACHE_VIDEO_URL from stream_fusion.services.rd_conn.token_manager import RDTokenManager @@ -65,7 +64,7 @@ def select_files(self, torrent_id, file_id): self._torrent_rate_limit() url = f"{self.base_url}/rest/1.0/torrents/selectFiles/{torrent_id}" data = {"files": str(file_id)} - requests.post(url, headers=self.get_headers(), data=data) + self.__session.post(url, headers=self.get_headers(), data=data) def unrestrict_link(self, link): url = f"{self.base_url}/rest/1.0/unrestrict/link" diff --git a/stream_fusion/utils/torrent/torrent_smart_container.py b/stream_fusion/utils/torrent/torrent_smart_container.py index 0a9f9e2..da3dc9a 100644 --- a/stream_fusion/utils/torrent/torrent_smart_container.py +++ b/stream_fusion/utils/torrent/torrent_smart_container.py @@ -106,6 +106,9 @@ def __save_to_cache(self): self.logger.info("Caching process completed") def update_availability(self, debrid_response, debrid_type, media): + if not debrid_response or debrid_response == {} or debrid_response == []: + self.logger.error("Debrid response is empty : " + str(debrid_response)) + return self.logger.info(f"Updating availability for {debrid_type.__name__}") if debrid_type is RealDebrid: self.__update_availability_realdebrid(debrid_response, media) diff --git a/stream_fusion/web/root/search/views.py b/stream_fusion/web/root/search/views.py index e3740e1..d866d2a 100644 --- a/stream_fusion/web/root/search/views.py +++ b/stream_fusion/web/root/search/views.py @@ -282,7 +282,7 @@ def stream_processing(search_results, media, config): streams = [Stream(**stream) for stream in stream_list] await redis_cache.set( stream_cache_key(media), streams, expiration=3600 - ) # Make the cache expire after 1 hour TODO: Make this configurable + ) total_time = time.time() - start logger.info(f"Request completed in {total_time:.2f} seconds") return SearchResponse(streams=streams) \ No newline at end of file