"""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
