From f0649be5dec84ce06a3164a2d9ee90f5385ac92f Mon Sep 17 00:00:00 2001 From: Astounds Date: Sun, 5 Apr 2026 14:56:51 -0500 Subject: Add HLS support to multi-audio --- youtube/hls_cache.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 youtube/hls_cache.py (limited to 'youtube/hls_cache.py') diff --git a/youtube/hls_cache.py b/youtube/hls_cache.py new file mode 100644 index 0000000..771fbd0 --- /dev/null +++ b/youtube/hls_cache.py @@ -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 -- cgit v1.2.3