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:
imSp4rky
2026-12-02 11:12:02 -07:00
parent ccdd14c845
commit 9842a61d3f
27 changed files with 404 additions and 62 deletions
+3 -1
View File
@@ -690,7 +690,9 @@ See the [DRM & CDM reference](../guide/drm-and-cdm.md) for the full picture.
Override any of these to react to pipeline stages (all no-ops by default):
`on_segment_downloaded`, `on_track_downloaded`, `on_track_decrypted`,
`on_track_repacked`, `on_track_multiplex`. `on_track_downloaded` runs once per track, after
unshackle decrypted the track and after `on_track_decrypted`. Also override `search()` to yield
unshackle decrypted the track and after `on_track_decrypted`. A `--remote` client runs none
of these hooks and no `track.downloader` of the service, so put what the client needs in
`track.data`, or leave it to core. Also override `search()` to yield
`SearchResult` objects for `unshackle search`.
!!! warning "Set `ANONYMOUS_SEARCH` only for a search that needs no account"
+3
View File
@@ -1137,6 +1137,8 @@ Get tracks and chapters for a specific title within the remote session. Body: `{
`manifests` holds each served DASH/ISM manifest once. For DASH, `filtered_period_ids` names the periods that the download skips, such as ad periods. A service can build an AdaptationSet of its own that the served manifest does not contain. `track_manifests` holds a one-track MPD for each such track, and the client re-parses that in place of the whole manifest. That MPD starts at the period of the track and keeps the content periods after it.
`hls_playlists` holds the media playlist text of each HLS track that the service holds as text, with the track URL. A `file:` URL is never sent: such an entry has `url` set to `null`. The client keeps an entry only when it parses as a media playlist whose segment URIs are absolute `http` or `https` URLs, and is for the same URL as its track. Otherwise it logs `Refusing track <id>: its HLS playlist ...` and drops the track.
=== "Response `200`"
```json
@@ -1149,6 +1151,7 @@ Get tracks and chapters for a specific title within the remote session. Body: `{
"attachments": [ { "url": "https://...", "name": "font.ttf", "mime_type": "font/ttf", "description": "" } ],
"manifests": [ { "type": "dash", "url": "https://...", "data": "<base64 zlib xml>", "filtered_period_ids": [ "ad-1" ] } ],
"track_manifests": [ { "track_id": "s-1", "type": "dash", "url": "https://...", "data": "<base64 zlib xml>" } ],
"hls_playlists": [ { "track_id": "v-1", "url": "https://...", "data": "<base64 zlib m3u8>" } ],
"session_headers": { "User-Agent": "..." },
"session_cookies": { "sid": "..." },
"session_cookie_jar": [ { "name": "sid", "value": "...", "domain": ".example.com", "path": "/", "secure": true } ],
+3 -1
View File
@@ -214,7 +214,9 @@ hood the client walks a remote session through its lifecycle.
downloading. A service can build an AdaptationSet of its own that the served
manifest does not contain. Each such track gets a one-track MPD in
`track_manifests`, with the content periods after its own, and the client
re-parses that instead. The client skips the same DASH periods as the server. Any
re-parses that instead. An HLS track whose service holds its media playlist as text
gets that text in `hls_playlists`. The client drops the track when the text is not a
media playlist with absolute `http` or `https` segment URIs. The client skips the same DASH periods as the server. Any
`session_headers` and cookies the server used are merged into the
client's local HTTP session. Each cookie in `session_cookie_jar` keeps its
domain, path and `secure` flag, so it goes only to its own hosts. `session_cookies` carries
+16
View File
@@ -295,6 +295,13 @@ track that it downloads. Over `--remote`, the client asks the server for the URL
each track it downloads, and the server calls the callable then. A track whose callable
fails gets no URL, and its download fails.
When the service has the media playlist of an HLS track as text and no playlist URL, set
`track.data["hls"]["playlist_text"]` to the text, and set `url` to a URL that its segment URIs
resolve against. unshackle downloads from the text and does not fetch a playlist. A `from_file`
playlist works the same way. Over `--remote` and in an export, the text goes with the track,
but a `file:` URL does not. The client accepts the text only as a media playlist whose segment
URIs are absolute `http` or `https` URLs, and drops the track otherwise.
### `Video`
`Video` adds `codec`, `range`, `bitrate`, `width`, `height`, `fps`, `scan_type`, and
@@ -310,6 +317,12 @@ closed-caption descriptors. The relevant enums:
Both `Video` and `Audio` store `bitrate` in **bits per second** (rounded up). The
string form displays kb/s, and `--vbitrate` and `--abitrate` compare in kb/s.
When the file of a track also holds a track of another kind, set `track.data["own_stream_only"] = True`
on the track. The mux then takes from that file only the track of the same kind: the video of a video
track, or the audio of an audio track. Use it for a video file with in-band audio that the
service also gives as audio tracks, or for an audio version that comes as a whole video file.
The value also goes to a `--remote` client. A track without it muxes everything in its file.
### `Audio`
`Audio` adds `bitrate`, `channels`, `joc` (Joint Object Coding, the Atmos indicator),
@@ -413,6 +426,9 @@ least one and no track is left.
- **HLS** re-fetches the media playlist at download time, recovers `SUPPLEMENTAL-CODECS`
from raw text (python-m3u8 drops it) to detect Dolby Vision composite streams, and uses
the media-sequence-number IV for AES-128 keys that have no explicit IV.
- **Segments** of each format: unshackle inflates a segment body that is one whole gzip member
before the merge, up to a size limit. A CDN can send such a body with no `Content-Encoding`
header. Any other body stays as it is, such as AES-128 ciphertext that starts with the gzip magic.
- **ISM** has no list of segments and no init segments: the parser synthesizes segment URLs
from the `<c>` fragment timeline, and rebuilds a `moov`/`ftyp` init box from `CodecPrivateData`
(supported for AVC, HEVC, DV-over-HEVC, AAC, EC-3, and TTML). A track id covers the manifest