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.
This commit is contained in:
rlaphoenix 2024-02-20 20:12:09 +00:00
parent b829ea5c5e
commit eef397f2e8
1 changed files with 12 additions and 4 deletions

View File

@ -365,7 +365,7 @@ class HLS:
return decrypted_path 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. Merge all segments of the discontinuity.
@ -377,6 +377,8 @@ class HLS:
list of segments to merge and decrypt. This should be False if list of segments to merge and decrypt. This should be False if
decrypting on EXT-X-KEY changes, or True when decrypting on the decrypting on EXT-X-KEY changes, or True when decrypting on the
last segment. 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)) last_segment_i = max(0, i - int(not include_this_segment))
@ -392,7 +394,7 @@ class HLS:
to=to_path, to=to_path,
via=files, via=files,
delete=True, delete=True,
include_map_data=True include_map_data=include_map_data
) )
if isinstance(track, Subtitle): if isinstance(track, Subtitle):
@ -408,7 +410,10 @@ class HLS:
if segment.discontinuity and i != 0: if segment.discontinuity and i != 0:
if encryption_data: if encryption_data:
decrypt(include_this_segment=False) 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 discon_i += 1
range_offset = 0 # TODO: Should this be reset or not? 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 # required as it won't end with EXT-X-DISCONTINUITY nor a new key
if encryption_data: if encryption_data:
decrypt(include_this_segment=True) 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) progress(advance=1)