From 963f17bb32bab8f618f7998fa7b9ee014315800b Mon Sep 17 00:00:00 2001 From: odium1963 Date: Wed, 22 Apr 2026 11:19:17 -0400 Subject: [PATCH] Fall back to nearest quality instead of highest when preferred unavailable Previously if the requested quality (e.g. 480p) was not in the source list, the downloader would silently jump to the highest available (1080p). Now it picks whichever quality is numerically closest to the requested one, so 480p falls back to 720p rather than 1080p. Co-Authored-By: odium1963 --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 76ee35c..1d235e5 100644 --- a/main.py +++ b/main.py @@ -332,11 +332,12 @@ def select_resolution(self, sources: list[dict[str, str]]) -> dict: for source in sources: if source["label"] == self.configuration.quality: return source - # Fall back to highest available quality + # Fall back to nearest available quality def _res(s): m = re.search(r"(\d+)", s.get("label", "0")) return int(m.group(1)) if m else 0 - return max(sources, key=_res) + target = _res({"label": self.configuration.quality}) + return min(sources, key=lambda s: abs(_res(s) - target)) def get_episodes(self, url: str) -> list[tuple[str, str]]: """Return list of (url, label_text) tuples from the listing page."""