Add HLS support to multi-audio

This commit is contained in:
2026-04-05 14:56:51 -05:00
parent 62a028968e
commit f0649be5de
19 changed files with 2256 additions and 164 deletions

23
youtube/hls_cache.py Normal file
View File

@@ -0,0 +1,23 @@
"""Multi-audio track support via HLS streaming.
Instead of downloading all segments, we proxy the HLS playlist and
let the browser stream the audio directly. Zero local storage needed.
"""
_tracks = {} # cache_key -> {'hls_url': str, ...}
def register_track(cache_key, hls_playlist_url, content_length=0,
video_id=None, track_id=None):
print(f'[audio-track-cache] Registering track: {cache_key} -> {hls_playlist_url[:80]}...')
_tracks[cache_key] = {'hls_url': hls_playlist_url}
print(f'[audio-track-cache] Available tracks: {list(_tracks.keys())}')
def get_hls_url(cache_key):
entry = _tracks.get(cache_key)
if entry:
print(f'[audio-track-cache] Found track: {cache_key}')
else:
print(f'[audio-track-cache] Track not found: {cache_key}')
return entry['hls_url'] if entry else None