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."""