From b5461e9dd27dac5e4b72d78451fc9f4b1133bc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20Einarsson=20-=20IMA?= Date: Mon, 14 Oct 2024 22:59:44 +0000 Subject: [PATCH] Changes to HLS stream mapping --- ruv-dl/ruv-dl.py | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/ruv-dl/ruv-dl.py b/ruv-dl/ruv-dl.py index 0ff92a7..8934258 100644 --- a/ruv-dl/ruv-dl.py +++ b/ruv-dl/ruv-dl.py @@ -266,20 +266,37 @@ def progress(seconds_done, eta): # Defines process output_title = attributes['title'] + attributes['file_format'] output_link = attributes['filepath'] + output_title - cmd = ['ffmpeg', - '-y', - '-loglevel', - 'error', - '-stats', - '-i', - f'{attributes["content_url"]}', - '-c', - 'copy', - f'{output_link}'] - - # Appends setting for correct stream if applicable - if attributes['content_url'].endswith('.m3u8'): - cmd.extend(['-map', f'p:{attributes["resolution"]}']) + is_hls = attributes['content_url'].endswith('.m3u8') + + if is_hls: + # HLS content: map the correct video and audio streams based on resolution + # Calculate stream indices based on desired resolution + video_stream_index = 2 * (attributes['resolution'] + 1) + audio_stream_index = video_stream_index + 1 + cmd = [ + 'ffmpeg', + '-y', + '-loglevel', 'error', + '-stats', + '-i', f'{attributes["content_url"]}', + '-map', f'0:{video_stream_index}', + '-map', f'0:{audio_stream_index}', + '-c:v', 'copy', + '-c:a', 'copy', + '-async', '1', + f'{output_link}' + ] + else: + # Non-HLS content (radio): no stream mapping needed + cmd = [ + 'ffmpeg', + '-y', + '-loglevel', 'error', + '-stats', + '-i', f'{attributes["content_url"]}', + '-c', 'copy', + f'{output_link}' + ] process = subprocess.Popen(cmd, stdout=subprocess.PIPE,