Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor configuration loading logic in config.js and update version to 2.0.4 #47

Merged
merged 4 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down
97 changes: 54 additions & 43 deletions stream_fusion/static/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions stream_fusion/utils/debrid/realdebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions stream_fusion/utils/torrent/torrent_smart_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion stream_fusion/web/root/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)