Skip to content

Commit

Permalink
HLS: Don't include map data if discontinuity/end of playlist was decr…
Browse files Browse the repository at this point in the history
…ypted

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.
  • Loading branch information
rlaphoenix committed Feb 20, 2024
1 parent b829ea5 commit eef397f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions devine/core/manifests/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def decrypt(include_this_segment: bool) -> 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.
Expand All @@ -377,6 +377,8 @@ def merge_discontinuity(include_this_segment: bool):
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))

Expand All @@ -392,7 +394,7 @@ def merge_discontinuity(include_this_segment: bool):
to=to_path,
via=files,
delete=True,
include_map_data=True
include_map_data=include_map_data
)

if isinstance(track, Subtitle):
Expand All @@ -408,7 +410,10 @@ def merge_discontinuity(include_this_segment: bool):
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?
Expand Down Expand Up @@ -468,7 +473,10 @@ def merge_discontinuity(include_this_segment: bool):
# 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)

Expand Down

0 comments on commit eef397f

Please sign in to comment.