docs(service): make the Service docstring the one table of class variables and attributes

This commit is contained in:
imSp4rky
2026-12-04 18:01:08 -07:00
parent 8d3ae1151e
commit ec6a48f8c0
6 changed files with 108 additions and 243 deletions
+11 -63
View File
@@ -98,29 +98,10 @@ Click `cli` entry point plus three abstract methods.
### Class variables
Declared at class level to configure framework behaviour:
| Variable | Type | Purpose |
|---|---|---|
| `ALIASES` | `tuple[str, ...]` | Extra tags that resolve to this service (e.g. `("EX", "DOMAIN")`). Case does not matter. Default `()`. |
| `GEOFENCE` | `tuple[str, ...]` | IP region codes the service requires. Empty = no geofence. unshackle treats the **first** entry as the main region for auto-proxy. |
| `GEOBLOCK` | `tuple[str, ...]` | IP region codes where the service refuses to work. Every other region is allowed. Default `()`. |
| `VAULT_TAG` | `Optional[str]` | Overrides the key-vault namespace so sibling services can share one vault. Default `None` (use the service's own tag). |
| `AUTH_METHODS` | `Optional[tuple[str, ...]]` | Auth methods accepted (`"cookies"` / `"credentials"`). When `None`, the REST `/services` endpoint infers them from `authenticate()`. |
| `ANONYMOUS_SEARCH` | `bool` | Set `True` when `search()` needs no login and no state from `authenticate()`. A search then skips the cookie load, `authenticate()` and the cookie save. Default `False`. |
| `NO_SUBTITLES` | `bool` | Set `True` on a service with no subtitle tracks to skip subtitle handling entirely. Default `False`. |
| `ANIME` | `bool` | Set `True` when the catalogue is anime, so metadata lookups prefer AniList. A title's own `anime` flag overrides it. |
| `METADATA_PROVIDER` | `Optional[str]` | Set it, such as to `"tmdb"`, when an index keeps your catalogue's titles only in a form your service does not use (romanized, for one), and another provider finds them by the name your service gives. Lookups try that provider first. It only reorders `metadata_providers` and never adds a provider the user left out. A title's own `metadata_provider` overrides it. |
| `DAILY` | `bool` | Set `True` when the catalogue is daily/date-based (talk shows, news, sports), so unshackle names episodes by air date. A title's own `daily` flag overrides it. |
`GEOFENCE` drives an automatic proxy: on startup, if you did not pass an
explicit `--proxy`, the base class does a live IP check and, if your region is
blocked, fetches a proxy to `GEOFENCE[0]` from your configured proxy providers. A
proxy exit outside `GEOFENCE` logs a warning and the run continues.
`GEOBLOCK` is the negative form: the service works everywhere except the listed
regions. With no `GEOFENCE` to name a main region, a `GEOBLOCK` hit stops the run
with a "not available in your region" error; pass `--proxy` yourself.
Class variables at the top of your class configure framework behaviour. The attributes table of
[`Service`][unshackle.core.service.Service] lists each one.
[Service Architecture](service-architecture.md#what-__init__-wires-up-for-you) explains the region check
that `GEOFENCE` and `GEOBLOCK` drive.
```python
class EXAMPLE(Service):
@@ -136,37 +117,12 @@ class WORLDWIDE(Service):
### What `Service.__init__` wires up
When you call `super().__init__(ctx)`, the base class sets up the attributes you
will use throughout the service:
will use throughout the service, such as `self.config`, `self.session`, `self.cache` and
`self.track_request`. The attributes table of [`Service`][unshackle.core.service.Service] lists each one.
| Attribute | What it is |
|---|---|
| `self.config` | A dict: this service's `config.yaml`, with the user's `services.<TAG>` block from `unshackle.yaml` merged over it. Without a `config.yaml`, it holds only the user's block. See [Services & authentication](../reference/configuration/services.md) for the override keys. |
| `self.log` | A `logging.Logger` named after your class. |
| `self.session` | A prepared `requests.Session` with config headers and a retry adapter (5 retries, backoff 0.2, retries on 429/500/502/503/504). Send every request through it: with a proxy active, a request from service code that does not go through the proxy logs a warning. A separate HTTP session that goes direct on purpose sets `proxy_exempt = True`. |
| `self.cache` | A `Cacher` for arbitrary key/value data, for example authentication tokens. |
| `self.title_cache` | A region/account-aware `TitleCacher` used by `get_titles_cached`. |
| `self.cache_dir` | `config.directories.cache / <ClassName>`. |
| `self.track_request` | A `TrackRequest` built from the CLI `--vcodec` / `--range` / `--best-available` flags. |
| `self.credential` | `None` until `authenticate()` runs. |
| `self.current_region` | The two-letter region resolved from proxy/IP. |
`self.track_request` is a small dataclass you can read *and rewrite* before
fetching tracks:
```python
@dataclass
class TrackRequest:
codecs: list[Video.Codec] = [] # empty == accept any codec
ranges: list[Video.Range] = [Video.Range.SDR]
best_available: bool = False
generate_dv: bool = False # --generate-dv: make Dolby Vision when a title has no DV track
```
!!! note "`generate_dv` and a hand-made HYBRID"
A service that fetches the HYBRID variants itself (HDR10 or HDR Vivid, and DV) must also fetch
HDR10P when `track_request.generate_dv` is set and the title has no DV track.
unshackle prefers an HEVC HDR10+ track as the base, and measures an HDR10 base from the decoded video.
`get_tracks_for_variants` does this for you.
`self.track_request` is a [`TrackRequest`][unshackle.core.service.TrackRequest] built from the CLI.
You can read it *and rewrite* it before you fetch tracks. A service that fetches the HYBRID variants itself reads the
[`TrackRequest` note](service-architecture.md#what-__init__-wires-up-for-you) first.
!!! note "Read the request, don't second-guess the user"
Services may narrow `track_request` for hard technical constraints (e.g.
@@ -639,16 +595,8 @@ The core drives licensing. Your job is to answer the license challenges the CDM
produces. Mark encrypted tracks with the right DRM in `get_tracks` (the manifest
parsers do this automatically for PSSH/`EXT-X-KEY` found in the manifest), then
write the license callbacks you need. Each receives the challenge plus the
current `title` and `track`:
| Method | For | Returns |
|---|---|---|
| `get_widevine_service_certificate` | Widevine privacy mode | The service certificate (bytes or base64 str), or `None`. |
| `get_widevine_license` | Widevine | The raw license response (bytes or base64 str), **unmodified**. |
| `get_playready_license` | PlayReady | The license response. Defaults to delegating to `get_widevine_license`. |
| `get_clearkey_license` | DASH `org.w3.clearkey` | The JWK Set (dict/JSON/bytes), or `None` to let the framework POST the challenge to the manifest's Laurl. |
A license callback can also declare optional keyword arguments. `get_widevine_license` can ask for `pssh` and `session_id`. `get_playready_license` can ask for `pssh_b64` and `session_id`. `session_id` is the open CDM session. A callback gets only the arguments that its signature declares. When a `--remote` client licenses with its own CDM, the callback on the server gets `pssh` or `pssh_b64` for the header the client licenses, but no `session_id`.
current `title` and `track`. [The service-side hooks](service-architecture.md#the-service-side-hooks)
names each callback, the optional arguments that it can declare, and what it returns:
```python
def get_widevine_license(self, *, challenge: bytes, title, track):