fix(manifests): keep service drm, rebase carried vtt cues, ship single-track mpds

DASH no longer drops service-set DRM when the manifest has none, and the WebVTT rebase allows a cue that starts one segment early. --remote also sends single-track manifests matched by track id.
This commit is contained in:
imSp4rky
2026-10-27 11:38:47 -06:00
parent 84fd0a4bee
commit 0440f2ba54
7 changed files with 90 additions and 17 deletions
+5 -4
View File
@@ -1560,11 +1560,12 @@ def extract_manifests(tracks) -> List[Dict[str, Any]]:
def extract_track_manifests(tracks) -> List[Dict[str, Any]]:
"""Build a one-AdaptationSet MPD for each track whose AdaptationSet the served manifest does not contain.
"""Build a one-AdaptationSet MPD for each track the client cannot find again in the served manifest.
A service can build an AdaptationSet of its own, out of merged segment timelines or
copied nodes, that never joins the manifest tree the server serialises. The client's
re-parse of that manifest cannot find it, so each of those tracks gets its own MPD.
copied nodes, that never joins the manifest tree the server serialises. A service can also
build a manifest that holds only its own track, which the client's attribute match cannot
tell apart from others. Each of those tracks gets its own MPD, matched by track id.
"""
import base64
import zlib
@@ -1583,7 +1584,7 @@ def extract_track_manifests(tracks) -> List[Dict[str, Any]]:
adaptation_set = dash.get("adaptation_set")
if manifest is None or adaptation_set is None:
continue
if adaptation_set.getroottree().getroot() is manifest:
if adaptation_set.getroottree().getroot() is manifest and len(manifest.findall(".//Representation")) > 1:
continue
root = etree.Element("MPD", dict(manifest.attrib))
+2 -2
View File
@@ -401,7 +401,7 @@ class DASH:
# Only override existing DRM if:
# 1. No existing DRM was set, OR
# 2. Existing DRM contains same type as manifest DRM, OR
# 3. Existing DRM is not Widevine (preserve Widevine when service explicitly set it)
# 3. Existing DRM is not Widevine and the manifest has DRM to replace it with
should_override_drm = (
not existing_drm
or (
@@ -409,7 +409,7 @@ class DASH:
and manifest_drm
and any(isinstance(existing, type(manifest)) for existing in existing_drm for manifest in manifest_drm)
)
or (existing_drm and not any(isinstance(drm, Widevine) for drm in existing_drm))
or (existing_drm and manifest_drm and not any(isinstance(drm, Widevine) for drm in existing_drm))
)
pre_existing_keys = {}
+6 -2
View File
@@ -286,8 +286,12 @@ class Subtitle(Track):
self.data["dash"]["adaptation_set"], self.data["dash"]["representation"]
)
if template is not None:
offset = template.get("presentationTimeOffset", "0")
text = rebase_webvtt(text, int(offset) * 1000 // int(template.get("timescale", "1")))
timescale = int(template.get("timescale", "1"))
text = rebase_webvtt(
text,
int(template.get("presentationTimeOffset", "0")) * 1000 // timescale,
int(template.get("duration", "0")) * 1000 // timescale,
)
if len(self.data["dash"]["segment_durations"]) > 1:
text = merge_segmented_webvtt(
text,
+4 -3
View File
@@ -79,14 +79,15 @@ def merge_segmented_webvtt(vtt_raw: str, segment_durations: Optional[list[int]]
return "WEBVTT\n\n" + "\n\n".join(blocks) + "\n"
def rebase_webvtt(text: str, offset_ms: int) -> str:
def rebase_webvtt(text: str, offset_ms: int, segment_ms: int = 0) -> str:
"""
Subtract offset_ms from every cue time when the cues sit on the media timeline of a DASH
period whose presentationTimeOffset is offset_ms, as a live replay's do. Cues that start
below the offset are already presentation times, so the text stays as it is.
more than one segment below the offset are already presentation times, so the text stays
as it is. A cue carried into the first segment can start up to one segment early.
"""
first = CUE_TIMES.search(text)
if offset_ms <= 0 or not first or timestamp_ms(first[2]) < offset_ms:
if offset_ms <= 0 or not first or timestamp_ms(first[2]) < offset_ms - segment_ms:
return text
def shift(ts: str) -> str: