Fix resolution parsing in format quality sorting

Improves robustness of the get_quality function by handling None and non-string resolution values, and catching IndexError in addition to ValueError when parsing resolution.
This commit is contained in:
Your Name
2025-10-02 21:22:08 +03:00
parent d81adc4781
commit be122d77fe
+5 -2
View File
@@ -162,10 +162,13 @@ class FormatTableMixin:
# Sort formats by quality
def get_quality(f):
if f.get("vcodec") != "none":
res = f.get("resolution", "0x0").split("x")[-1]
resolution = f.get("resolution", "0x0")
if resolution is None or not isinstance(resolution, str):
return 0
try:
res = resolution.split("x")[-1]
return int(res)
except ValueError:
except (ValueError, IndexError):
return 0
else:
return f.get("abr", 0)