fix: update innertube clients and fix HLS/DASH quality switching
All checks were successful
CI / test (push) Successful in 53s

- Update innertube client versions to match yt-dlp (android 21.02.35,
  ios 21.02.3, web 2.20260114.08.00, android_vr 1.65.10)
- Remove obsolete clients (android-test-suite, ios_vr)
- Replace tv_embedded with TVHTML5_SIMPLY (cn 75)
- Add new clients: web_embedded, mweb, tv
- Fix HLS freeze on quality switch: use nextLevel instead of
  currentLevel, handle bufferStalledError, stream proxy segments
  instead of buffering in memory
- Populate DASH quality selector with actual sources (no Auto)
- Render quality-select empty in template, let JS populate per mode
This commit is contained in:
2026-05-03 12:32:55 -05:00
parent 50ad959a80
commit 8d66143c90
9 changed files with 467 additions and 246 deletions

82
youtube/watch_formats.py Normal file
View File

@@ -0,0 +1,82 @@
"""Video format helpers for yt-local."""
import math
from typing import Any, Dict, Optional
def codec_name(vcodec: str) -> str:
"""Extract codec short name from codec string."""
if vcodec.startswith('avc'):
return 'h264'
elif vcodec.startswith('av01'):
return 'av1'
elif vcodec.startswith('vp'):
return 'vp'
else:
return 'unknown'
def video_quality_string(fmt: Dict[str, Any]) -> str:
"""Return video quality string (e.g., '1920x1080 30fps')."""
if fmt.get('vcodec'):
result = f"{fmt.get('width') or '?'}x{fmt.get('height') or '?'}"
if fmt.get('fps'):
result += f" {fmt['fps']}fps"
return result
elif fmt.get('acodec'):
return 'audio only'
return '?'
def short_video_quality_string(fmt: Dict[str, Any]) -> str:
"""Return short video quality string (e.g., '1080p60 AV1')."""
result = f"{fmt.get('quality') or '?'}p"
if fmt.get('fps'):
result += str(fmt['fps'])
vcodec = fmt.get('vcodec', '')
if vcodec.startswith('av01'):
result += ' AV1'
elif vcodec.startswith('avc'):
result += ' h264'
else:
result += f" {vcodec}"
return result
def audio_quality_string(fmt: Dict[str, Any]) -> str:
"""Return audio quality string (e.g., '128k 44.1kHz')."""
if fmt.get('acodec'):
if fmt.get('audio_bitrate'):
result = f"{fmt['audio_bitrate']}k"
else:
result = '?k'
if fmt.get('audio_sample_rate'):
result += f" {'%.3G' % (fmt['audio_sample_rate']/1000)}kHz"
return result
elif fmt.get('vcodec'):
return 'video only'
return '?'
def format_bytes(bytes_val: Optional[float]) -> str:
"""Convert bytes to human-readable string (e.g., '1.5 MiB')."""
if bytes_val is None:
return 'N/A'
if type(bytes_val) is str:
bytes_val = float(bytes_val)
if bytes_val == 0.0:
exponent = 0
else:
exponent = int(math.log(bytes_val, 1024.0))
suffix = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'][exponent]
converted = float(bytes_val) / float(1024 ** exponent)
return '%.2f%s' % (converted, suffix)
__all__ = [
'codec_name',
'video_quality_string',
'short_video_quality_string',
'audio_quality_string',
'format_bytes',
]