forked from kenzuya/unshackle
feat(hls): carry a held media playlist over --remote and export, inflate gzip segments, add own_stream_only mux opt-in
This commit is contained in:
@@ -617,6 +617,8 @@ class Track:
|
||||
- playlist: m3u8.model.Playlist - The primary track information.
|
||||
- media: m3u8.model.Media - The audio/subtitle track information.
|
||||
- segment_durations: list[int] - A list of each segment's duration.
|
||||
- playlist_text: str - The media playlist, set by a service that has its text and no
|
||||
playlist URL. Its segment URIs resolve against the track URL.
|
||||
- "dash" used by the DASH class.
|
||||
- manifest: lxml.ElementTree - DASH MPD manifest.
|
||||
- period: lxml.Element - The period of this track.
|
||||
@@ -625,6 +627,11 @@ class Track:
|
||||
- timescale: int - The timescale of the track's segments.
|
||||
- segment_durations: list[int] - A list of each segment's duration.
|
||||
|
||||
A service can set:
|
||||
|
||||
- "own_stream_only": bool - Mux only the track of the same kind from the file: a video
|
||||
without the audio its file holds, or an audio track without the video in its file.
|
||||
|
||||
You should not add, change, or remove any data within reserved keys.
|
||||
You may use their data, but note that these values can change or be removed
|
||||
at any point.
|
||||
@@ -998,6 +1005,24 @@ class Track:
|
||||
|
||||
return self.load_drm_from_playlist()
|
||||
|
||||
def held_playlist(self) -> str | None:
|
||||
"""The HLS media playlist text the track holds: ``data["hls"]["playlist_text"]``, else the ``from_file`` text."""
|
||||
text = (self.data.get("hls") or {}).get("playlist_text")
|
||||
if text is None and self.from_file:
|
||||
text = self.from_file.read_text(encoding="utf-8")
|
||||
return text
|
||||
|
||||
def playlist_text(self, session: Any, **kwargs: Any) -> str:
|
||||
"""The HLS media playlist text the track holds, else the one at its URL; a response that is not ok raises."""
|
||||
text = self.held_playlist()
|
||||
if text is None:
|
||||
assert isinstance(self.url, str)
|
||||
response = session.get(self.url, **kwargs)
|
||||
if not getattr(response, "ok", True):
|
||||
raise ValueError(f"Failed to request the media playlist of track {self.id}: {response.status_code}")
|
||||
text = utf8_text(response)
|
||||
return text
|
||||
|
||||
def load_drm_from_playlist(self, session: Any = None, bridge: bool = False) -> bool:
|
||||
"""Load the Widevine and PlayReady DRM of the EXT-X-KEY and EXT-X-SESSION-KEY tags of this track's playlist.
|
||||
|
||||
@@ -1015,7 +1040,7 @@ class Track:
|
||||
session = self.session or session or run_proxy.fallback_session()
|
||||
try:
|
||||
assert isinstance(self.url, str)
|
||||
playlist = m3u8.loads(utf8_text(session.get(self.url)), self.url)
|
||||
playlist = m3u8.loads(self.playlist_text(session), self.url)
|
||||
except Exception as e:
|
||||
raise ValueError(f"Failed to load DRM from playlist for track {self.id}: {e}") # noqa: B904
|
||||
|
||||
|
||||
Reference in New Issue
Block a user