Service API¶
Auto-generated reference for the Service base class that every
service plugin subclasses. See Creating a Service for a guided
walkthrough and Service Architecture for the wider object model.
TrackRequest
dataclass
¶
Holds what the user requested for video codec and range selection.
Services read from this instead of ctx.parent.params for vcodec/range.
Attributes:
| Name | Type | Description |
|---|---|---|
codecs |
list[Codec]
|
Requested codecs from CLI. Empty list means no filter (accept any). |
ranges |
list[Range]
|
Requested ranges from CLI. Defaults to [SDR]. |
Service
¶
The Service Base Class.
Source code in unshackle/core/service.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
get_session
staticmethod
¶
Creates a Python-requests Session, adds common headers from config, cookies, retry handler, and a proxy if available. :returns: Prepared Python-requests Session
Source code in unshackle/core/service.py
authenticate
¶
Authenticate the Service with Cookies and/or Credentials (Email/Username and Password).
This is effectively a login() function. Any API calls or object initializations needing to be made, should be made here. This will be run before any of the following abstract functions.
You should avoid storing or using the Credential outside this function. Make any calls you need for any Cookies, Tokens, or such, then use those.
The Cookie jar should also not be stored outside this function. However, you may load the Cookie jar into the service session.
Source code in unshackle/core/service.py
request_input
¶
Request interactive input from the user.
When running locally (CLI), prompts via the shared rich console so the
prompt renders correctly alongside Live progress / log handlers.
When running in serve mode with an :class:InputBridge attached,
delegates to the bridge which relays the prompt to the remote client.
Source code in unshackle/core/service.py
search
¶
Search by query for titles from the Service.
The query must be taken as a CLI argument by the Service class. Ideally just re-use the title ID argument (i.e. self.title).
Search results will be displayed in the order yielded.
Source code in unshackle/core/service.py
get_widevine_service_certificate
¶
Get the Widevine Service Certificate used for Privacy Mode.
:param challenge: The service challenge, providing this to a License endpoint should return the
privacy certificate that the service uses.
:param title: The current Title from get_titles that is being executed. This is provided in
case it has data needed to be used, e.g. for a HTTP request.
:param track: The current Track needing decryption. Provided for same reason as title.
:return: The Service Privacy Certificate as Bytes or a Base64 string. Don't Base64 Encode or
Decode the data, return as is to reduce unnecessary computations.
Source code in unshackle/core/service.py
get_widevine_license
¶
Get a Widevine License message by sending a License Request (challenge).
This License message contains the encrypted Content Decryption Keys and will be read by the Cdm and decrypted.
This is a very important request to get correct. A bad, unexpected, or missing value in the request can cause your key to be detected and promptly banned, revoked, disabled, or downgraded.
:param challenge: The license challenge from the Widevine CDM.
:param title: The current Title from get_titles that is being executed. This is provided in
case it has data needed to be used, e.g. for a HTTP request.
:param track: The current Track needing decryption. Provided for same reason as title.
:return: The License response as Bytes or a Base64 string. Don't Base64 Encode or
Decode the data, return as is to reduce unnecessary computations.
Source code in unshackle/core/service.py
get_playready_license
¶
Get a PlayReady License message by sending a License Request (challenge).
This License message contains the encrypted Content Decryption Keys and will be read by the CDM and decrypted.
This is a very important request to get correct. A bad, unexpected, or missing value in the request can cause your key to be detected and promptly banned, revoked, disabled, or downgraded.
:param challenge: The license challenge from the PlayReady CDM.
:param title: The current Title from get_titles that is being executed. This is provided in
case it has data needed to be used, e.g. for a HTTP request.
:param track: The current Track needing decryption. Provided for same reason as title.
:return: The License response as Bytes or a Base64 string. Don't Base64 Encode or
Decode the data, return as is to reduce unnecessary computations.
Source code in unshackle/core/service.py
get_clearkey_license
¶
Get a W3C ClearKey License (JWK Set) by sending a License Request (challenge).
Used for DASH org.w3.clearkey content. No CDM is involved: the challenge is
the W3C EME JSON license request, e.g. {"kids": ["<base64url>"], "type": "temporary"},
and the license is a JWK Set, e.g. {"keys": [{"kty": "oct", "k": "...", "kid": "..."}]}.
:param challenge: The JSON license request bytes to POST to the license server.
:param title: The current Title from get_titles that is being executed. This is provided in
case it has data needed to be used, e.g. for a HTTP request.
:param track: The current Track needing decryption. Provided for same reason as title.
:return: The JWK Set license as a dict, JSON str, or raw bytes. Return None (the default)
to let the framework POST the challenge to the manifest-provided Laurl, if any.
Services with no license server can instead pre-populate the DRM object's
content_keys in get_tracks.
Source code in unshackle/core/service.py
get_titles
abstractmethod
¶
Get Titles for the provided title ID.
Return a Movies, Series, or Album objects containing Movie, Episode, or Song title objects respectively. The returned data must be for the given title ID, or a spawn of the title ID.
At least one object is expected to be returned, or it will presume an invalid Title ID was provided.
You can use the data dictionary class instance attribute of each Title to store data you may need later on.
This can be useful to store information on each title that will be required like any sub-asset IDs, or such.
Source code in unshackle/core/service.py
get_titles_cached
¶
Cached wrapper around get_titles() to reduce redundant API calls.
This method checks the cache before calling get_titles() and handles fallback to cached data when API calls fail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title_id
|
str
|
Optional title ID for cache key generation. If not provided, will try to extract from service instance. |
None
|
Returns:
| Type | Description |
|---|---|
Titles_T
|
Titles object (Movies, Series, or Album) |
Source code in unshackle/core/service.py
apply_title_map
¶
Rewrite service-provided titles using the per-service title_map config.
title_map lives under services.<TAG> in unshackle.yaml. Applied after the
title cache so config edits take effect without a cache reset, and before any
--enrich override so enrich wins. See remap_titles for the match rules.
Source code in unshackle/core/service.py
get_tracks
abstractmethod
¶
Get Track objects of the Title.
Return a Tracks object, which itself can contain Video, Audio, Subtitle or even Chapters. Tracks.videos, Tracks.audio, Tracks.subtitles, and Track.chapters should be a List of Track objects.
Each Track in the Tracks should represent a Video/Audio Stream/Representation/Adaptation or a Subtitle file.
While one Track should only hold information for one stream/downloadable, try to get as many unique Track objects per stream type so Stream selection by the root code can give you more options in terms of Resolution, Bitrate, Codecs, Language, e.t.c.
No decision making or filtering of which Tracks get returned should happen here. It can be considered an error to filter for e.g. resolution, codec, and such. All filtering based on arguments will be done by the root code automatically when needed.
Make sure you correctly mark which Tracks are encrypted or not, and by which DRM System
via its drm property.
If you are able to obtain the Track's KID (Key ID) as a 32 char (16 bit) HEX string, provide
it to the Track's kid variable as it will speed up the decryption process later on. It may
or may not be needed, that depends on the service. Generally if you can provide it, without
downloading any of the Track's stream data, then do.
:param title: The current Title from get_titles that is being executed.
:return: Tracks object containing Video, Audio, Subtitles, and Chapters, if available.
Source code in unshackle/core/service.py
get_chapters
abstractmethod
¶
Get Chapters for the Title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
Title_T
|
The current Title from |
required |
You must return a Chapters object containing 0 or more Chapter objects.
You do not need to set a Chapter number or sort/order the chapters in any way as the Chapters class automatically handles all of that for you. If there's no descriptive name for a Chapter then do not set a name at all.
You must not set Chapter names to "Chapter {n}" or such. If you (or the user)
wants "Chapter {n}" style Chapter names (or similar) then they can use the config
option chapter_fallback_name. For example, "Chapter {i:02}" for "Chapter 01".
Source code in unshackle/core/service.py
on_segment_downloaded
¶
Called when one of a Track's Segments has finished downloading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
AnyTrack
|
The Track object that had a Segment downloaded. |
required |
segment
|
Path
|
The Path to the Segment that was downloaded. |
required |
Source code in unshackle/core/service.py
on_track_downloaded
¶
Called when a Track has finished downloading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
AnyTrack
|
The Track object that was downloaded. |
required |
on_track_decrypted
¶
Called when a Track has finished decrypting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
AnyTrack
|
The Track object that was decrypted. |
required |
drm
|
DRM_T
|
The DRM object it decrypted with. |
required |
segment
|
Optional[Segment]
|
The HLS segment information that was decrypted. |
None
|
Source code in unshackle/core/service.py
on_track_repacked
¶
Called when a Track has finished repacking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
AnyTrack
|
The Track object that was repacked. |
required |
on_track_multiplex
¶
Called when a Track is about to be Multiplexed into a Container.
Note: Right now only MKV containers are multiplexed but in the future this may also be called when multiplexing to other containers like MP4 via ffmpeg/mp4box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
AnyTrack
|
The Track object that was repacked. |
required |
Source code in unshackle/core/service.py
sanitize_proxy_for_log
¶
Sanitize a proxy URI for logs by redacting any embedded userinfo (username/password).
Examples:
- http://user:pass@host:8080 -> http://REDACTED@host:8080
- socks5h://user@host:1080 -> socks5h://REDACTED@host:1080