mirror of
https://github.com/UrloMythus/UnHided.git
synced 2026-04-11 11:50:51 +00:00
New version
This commit is contained in:
@@ -172,9 +172,29 @@ def build_hls_playlist(mpd_dict: dict, profiles: list[dict], request: Request) -
|
||||
|
||||
# Add headers for only the first profile
|
||||
if index == 0:
|
||||
sequence = segments[0]["number"]
|
||||
first_segment = segments[0]
|
||||
extinf_values = [f["extinf"] for f in segments if "extinf" in f]
|
||||
target_duration = math.ceil(max(extinf_values)) if extinf_values else 3
|
||||
|
||||
# Calculate media sequence using adaptive logic for different MPD types
|
||||
mpd_start_number = profile.get("segment_template_start_number")
|
||||
if mpd_start_number and mpd_start_number >= 1000:
|
||||
# Amazon-style: Use absolute segment numbering
|
||||
sequence = first_segment.get("number", mpd_start_number)
|
||||
else:
|
||||
# Sky-style: Use time-based calculation if available
|
||||
time_val = first_segment.get("time")
|
||||
duration_val = first_segment.get("duration_mpd_timescale")
|
||||
if time_val is not None and duration_val and duration_val > 0:
|
||||
calculated_sequence = math.floor(time_val / duration_val)
|
||||
# For live streams with very large sequence numbers, use modulo to keep reasonable range
|
||||
if mpd_dict.get("isLive", False) and calculated_sequence > 100000:
|
||||
sequence = calculated_sequence % 100000
|
||||
else:
|
||||
sequence = calculated_sequence
|
||||
else:
|
||||
sequence = first_segment.get("number", 1)
|
||||
|
||||
hls.extend(
|
||||
[
|
||||
f"#EXT-X-TARGETDURATION:{target_duration}",
|
||||
|
||||
Reference in New Issue
Block a user