From eef397f2e814b8b0c7c1be82679cc2ecd05f314c Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Tue, 20 Feb 2024 20:12:09 +0000 Subject: [PATCH] HLS: Don't include map data if discontinuity/end of playlist was decrypted The decrypt() call just before it would have included the map data for us, as it was needed to decrypt. Therefore, it would not need to be added again when merge_discontinuity() is called. In some cases re-adding the map data can cause playback or final merge failure. --- devine/core/manifests/hls.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index 8cdcd20..611f89a 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -365,7 +365,7 @@ class HLS: return decrypted_path - def merge_discontinuity(include_this_segment: bool): + def merge_discontinuity(include_this_segment: bool, include_map_data: bool = True): """ Merge all segments of the discontinuity. @@ -377,6 +377,8 @@ class HLS: list of segments to merge and decrypt. This should be False if decrypting on EXT-X-KEY changes, or True when decrypting on the last segment. + include_map_data: Whether to prepend the init map data before the + segment files when merging. """ last_segment_i = max(0, i - int(not include_this_segment)) @@ -392,7 +394,7 @@ class HLS: to=to_path, via=files, delete=True, - include_map_data=True + include_map_data=include_map_data ) if isinstance(track, Subtitle): @@ -408,7 +410,10 @@ class HLS: if segment.discontinuity and i != 0: if encryption_data: decrypt(include_this_segment=False) - merge_discontinuity(include_this_segment=False) + merge_discontinuity( + include_this_segment=False, + include_map_data=not encryption_data or not encryption_data[2] + ) discon_i += 1 range_offset = 0 # TODO: Should this be reset or not? @@ -468,7 +473,10 @@ class HLS: # required as it won't end with EXT-X-DISCONTINUITY nor a new key if encryption_data: decrypt(include_this_segment=True) - merge_discontinuity(include_this_segment=True) + merge_discontinuity( + include_this_segment=True, + include_map_data=not encryption_data or not encryption_data[2] + ) progress(advance=1)