fix(dl): add bitrate tolerance for video track selection

- Implement bitrate selection with a tolerance of +100 kbps and -800 kbps
- Ensure minimum bitrate does not go below 0 when calculating lower bound
- Update error message to reflect bitrate range instead of exact value
- Enhance logging for cases with no matching video tracks within tolerance range
This commit is contained in:
2025-08-30 01:14:34 +07:00
parent c7be94c0fc
commit bb85ac2767

View File

@@ -640,9 +640,12 @@ class dl:
self.log.warning(f"Skipping {color_range.name} video tracks as none are available.") self.log.warning(f"Skipping {color_range.name} video tracks as none are available.")
if vbitrate: if vbitrate:
title.tracks.select_video(lambda x: x.bitrate and x.bitrate // 1000 == vbitrate) # Tolerance: +100 kbps (upper), -800 kbps (lower)
min_bitrate = max(0, vbitrate - 800) # Don't go below 0
max_bitrate = vbitrate + 100
title.tracks.select_video(lambda x: x.bitrate and min_bitrate <= x.bitrate // 1000 <= max_bitrate)
if not title.tracks.videos: if not title.tracks.videos:
self.log.error(f"There's no {vbitrate}kbps Video Track...") self.log.error(f"There's no Video Track with bitrate between {min_bitrate}-{max_bitrate}kbps (requested {vbitrate}kbps)...")
sys.exit(1) sys.exit(1)
video_languages = [lang for lang in (v_lang or lang) if lang != "best"] video_languages = [lang for lang in (v_lang or lang) if lang != "best"]