Merge pull request #432 from g0ldyy/feat/sort-cached-uncached-together

feat: add configuration and UI option to sort cached and uncached stream results together
This commit is contained in:
Goldy
2026-01-02 18:59:23 +01:00
committed by GitHub
3 changed files with 13 additions and 1 deletions
+7 -1
View File
@@ -320,6 +320,7 @@ async def stream(
is_first = await is_first_search(media_id)
has_cached_results = len(torrent_manager.torrents) > 0
sort_mixed = config["sortCachedUncachedTogether"]
cached_results = []
non_cached_results = []
@@ -529,9 +530,14 @@ async def stream(
f"{request.url.scheme}://{request.url.netloc}/{b64config}/playback/{info_hash}/{torrent['fileIndex'] if torrent['cached'] and torrent['fileIndex'] is not None else 'n'}/{result_season}/{result_episode}/{quote(torrent_title)}?name={quote(title)}"
)
if torrent["cached"]:
if sort_mixed:
cached_results.append(the_stream)
elif torrent["cached"]:
cached_results.append(the_stream)
else:
non_cached_results.append(the_stream)
if sort_mixed:
return {"streams": cached_results}
return {"streams": cached_results + non_cached_results}
+1
View File
@@ -683,6 +683,7 @@ rtn_ranking_default = DefaultRanking()
class ConfigModel(BaseModel):
cachedOnly: Optional[bool] = False
sortCachedUncachedTogether: Optional[bool] = False
removeTrash: Optional[bool] = True
resultFormat: Optional[List[str]] = ["all"]
maxResultsPerResolution: Optional[int] = 0
+5
View File
@@ -450,6 +450,7 @@
help-text="Torrents ranked below this value will be excluded from results."></sl-input>
<sl-checkbox id="cachedOnly" help-text="Show only content that has already been cached.">Show Cached
Only</sl-checkbox>
<sl-checkbox id="sortCachedUncachedTogether" help-text="Disable the default behavior of sorting cached results first, and instead mixes cached and uncached results together.">Sort Cached and Uncached Together</sl-checkbox>
<sl-checkbox id="allowEnglishInLanguages"
help-text="Allows English language torrents to be included even if you excluded English from your language preferences.">Allow
English in Languages</sl-checkbox>
@@ -756,6 +757,7 @@
const maxResultsPerResolution = document.getElementById("maxResultsPerResolution").value;
const maxSize = document.getElementById("maxSize").value;
const cachedOnly = document.getElementById("cachedOnly").checked;
const sortCachedUncachedTogether = document.getElementById("sortCachedUncachedTogether").checked;
const removeTrash = document.getElementById("removeTrash").checked;
const allowEnglishInLanguages = document.getElementById("allowEnglishInLanguages").checked;
const removeUnknownLanguages = document.getElementById("removeUnknownLanguages").checked;
@@ -773,6 +775,7 @@
maxResultsPerResolution: parseInt(maxResultsPerResolution),
maxSize: parseFloat(maxSize * 1073741824),
cachedOnly: cachedOnly,
sortCachedUncachedTogether: sortCachedUncachedTogether,
removeTrash: removeTrash,
resultFormat: selectedResultFormat,
debridService: debridService,
@@ -835,6 +838,8 @@
function populateFormFromSettings(settings) {
if (settings.cachedOnly !== null)
document.getElementById("cachedOnly").checked = settings.cachedOnly;
if (settings.sortCachedUncachedTogether !== undefined && settings.sortCachedUncachedTogether !== null)
document.getElementById("sortCachedUncachedTogether").checked = settings.sortCachedUncachedTogether;
if (settings.removeTrash !== null)
document.getElementById("removeTrash").checked = settings.removeTrash;
if (settings.maxResultsPerResolution !== null)