stremio-addon-core
Reusable Rust base for Stremio addon HTTP servers.
This crate owns the protocol-level work common to provider addons:
- Stremio manifest, stream, catalog, and meta response models.
- GET and POST stream routes.
- Encoded Stremio config path decoding.
- Private addon auth from config, path, query, bearer header, or custom header.
- CORS.
- Health routes.
- Optional playback redirect routes.
- Optional HMAC-signed playback tokens.
- Router options for common route surfaces such as stream-only addons, key-prefixed private addons, and manifest aliases.
Provider crates should keep provider-specific login, search API execution, and playback resolution outside this crate. The core includes shared title lookup, search query generation, normalized result ranking, filename/media parsing, JSON cache storage, stream selection, and stream-card formatting helpers that multiple providers can reuse.
Install Shape
Add the crate to a provider app:
[]
= "0.1.4"
= "0.1"
= "0.7"
= { = "1", = ["macros", "rt-multi-thread"] }
CI/CD
The crate includes GitHub Actions workflows:
.github/workflows/ci.yml: runs on pushes, pull requests, and manual dispatch. It checks formatting,cargo check, clippy, tests, andcargo package..github/workflows/release.yml: runs onv*.*.*tags or manual dispatch. It repeats validation, runscargo publish --dry-run, then publishes to crates.io when triggered by a matching tag or manualpublish=true.
CI uses Rust 1.88.0, matching the crate rust-version. This is required because the current locked dependency graph includes crates whose declared MSRV is 1.88.
Crates.io publishing requires a repository secret:
CARGO_REGISTRY_TOKEN
Release flow:
- Update
versioninCargo.toml. - Run
cargo test --locked --all-targets. - Create and push a matching tag, for example
v0.1.4. - The release workflow verifies the tag matches
Cargo.tomland publishes the crate.
Minimal Adapter
use async_trait;
use Arc;
use ;
;
async
Routes
Core Stremio routes:
| Route | Method | Handler |
|---|---|---|
/manifest.json |
GET | AddonAdapter::manifest |
/{config}/manifest.json |
GET | AddonAdapter::manifest with decoded config |
/stream/{type}/{id} |
GET | AddonAdapter::stream |
/{config}/stream/{type}/{id} |
GET | AddonAdapter::stream with decoded config |
/stream |
POST | AddonAdapter::stream_request |
/api/streams |
POST | AddonAdapter::stream_request |
/api/streams/{type}/{id} |
GET | AddonAdapter::stream |
/catalog/{type}/{id}/{extra} |
GET | AddonAdapter::catalog |
/{config}/catalog/{type}/{id}/{extra} |
GET | AddonAdapter::catalog with decoded config |
/meta/{type}/{id} |
GET | AddonAdapter::meta |
/{config}/meta/{type}/{id} |
GET | AddonAdapter::meta with decoded config |
/play/{ident} |
GET | AddonAdapter::playback |
/{config}/play/{ident} |
GET | AddonAdapter::playback with decoded config |
Alias routes enabled by default:
| Route | Purpose |
|---|---|
/ |
manifest alias |
/stremio/manifest.json |
manifest alias |
/api/manifest |
manifest alias |
/health |
unauthenticated health |
/healthz |
unauthenticated health |
/u/{authKey}/manifest.json |
key-prefixed private manifest |
/u/{authKey}/stream/{type}/{id} |
key-prefixed private stream |
The route parser strips a trailing .json from Stremio id path segments.
Router Options
Use build_router_with_options when the provider needs a narrower route surface:
use ;
let router = build_router_with_options;
Options:
| Option | Default | Meaning |
|---|---|---|
catalog_routes |
true |
Mount catalog routes. Disable for stream-only addons. |
meta_routes |
true |
Mount meta routes. Disable for stream-only addons. |
playback_routes |
true |
Mount /play redirect routes. Disable for direct-URL providers. |
alias_routes |
true |
Mount root/index/API manifest aliases. |
path_key_routes |
true |
Mount /u/{authKey}/... routes. |
health_routes |
true |
Mount /health and /healthz. |
playback_signing_key |
None |
If set, /play/{ident} requires ?sig= signed by this key. |
Auth
AuthConfig::required(key) applies to Stremio routes. AuthConfig::disabled() skips addon auth, useful for tests or public addons.
Accepted auth locations, in precedence order:
- Encoded config JSON:
/{%7B%22authKey%22%3A%22secret%22%7D}/manifest.json - Path key:
/u/secret/manifest.json - Query string:
?authKey=secret - Query string alias:
?key=secret - Bearer header:
Authorization: Bearer secret - Header:
X-Addon-Auth: secret
Key comparisons use constant-time equality. AuthConfig redacts the configured key from Debug.
Health routes are intentionally unauthenticated.
Encoded Config
Stremio supports a configuration object encoded as a path segment:
The core decodes this into:
Unknown fields are preserved in extra, so provider adapters can read custom fields without changing the core model.
Stream Requests
GET stream routes call:
async
POST stream routes call:
async
The default stream_request implementation forwards to stream when type and id are present. Override it for provider-specific POST request bodies that use alternate fields such as name, episode, year, or custom metadata.
POST body shape:
Stream Responses
Stream supports the common Stremio transport shapes:
url: direct playable URL or addon playback URL.externalUrl: external page.infoHashplussources: torrent/P2P style.
It also has typed provider fields used by local addons:
qualitybehaviorHints.countryWhitelistbehaviorHints.bingeGroupbehaviorHints.videoSizebehaviorHints.filename
Provider-specific fields can be added through extra maps.
Metadata Lookups
metadata provides a small TMDB/Cinemeta resolver:
use ;
let metadata = new;
let info = metadata.lookup_imdb.await?;
let episode = metadata.lookup_imdb.await?;
let tmdb = metadata.lookup_tmdb_id.await?;
Resolution behavior:
- Uses TMDB first when
tmdb_api_keyis set. - Falls back to Cinemeta for IMDb IDs when TMDB returns no usable result.
- Uses Cinemeta only when no TMDB key is configured.
- Preserves
seasonandepisodefrom Stremio IDs likett123:1:2. - Returns
TitleInfowith Czech/primary title, Slovak title, English title, original title, year, type, season, and episode.
The core performs metadata HTTP requests, but it does not cache metadata. Provider apps should add caching around MetadataClient if needed.
Search Query Generation
search builds provider-friendly query variants from TitleInfo:
use ;
let input = from_title_info;
let queries = build_search_queries;
Profiles:
- Title/year profile: movie queries include each title and title-with-year variants; series queries include
S01E02and01x02variants. - Ordered fallback profile: query order starts specific and gradually broadens, useful for providers where query order is an important ranking signal.
Providers still execute provider searches and normalize raw provider rows into core SearchResult values.
Search Result Ranking
ranking scores normalized provider results against the metadata returned by TMDB/Cinemeta before cards are built:
use ;
let ranked = rank_results;
Profiles:
- Provider-tuned profiles for existing query styles.
Balanced: generic title and filename blend for new adapters.
Ranking behavior:
- Filters protected rows by default.
- Filters results with a year outside the configured tolerance.
- Requires exact season/episode matches for series when metadata has episode information.
- Filters episode-like movie false positives for profiles that enable that guard.
- Preserves
strong_matchandweak_matchflags for card formatting. - Uses optional vote ratio and quality rank as small tie-breakers.
The recommended provider pipeline is:
- Resolve
TitleInfowithMetadataClient. - Build queries with
build_search_queries. - Execute provider searches.
- Normalize raw provider rows into
SearchResult. - Rank and filter with
rank_results. - Convert ranked rows to
StreamCardInputand buildStreamcards.
Stream Card Formatting
cards converts common provider presentation data into Stream values:
use ;
let stream = stream_card;
Profiles:
- Provider-tuned profiles for richer legacy card layouts.
Compact: generic one-line card useful for simple providers.
The helpers are intentionally presentation-only. They should run after metadata lookup, query generation, provider search, and ranking. They do not resolve playback URLs.
Playback Redirects
Use playback routes when stream URLs should point back to the addon instead of exposing provider tokens or expensive direct URLs.
Typical private provider flow:
- Provider search returns stream URL
/play/{ident}?authKey=...&sig=.... - Core validates addon auth.
- If
RouterOptions.playback_signing_keyis set, core verifiessig. - Core calls
AddonAdapter::playback(ctx, ident). - Adapter resolves the real provider URL.
- Core redirects with
Cache-Control: max-age={seconds}, must-revalidate, proxy-revalidate.
Create signatures with SignedPlayback:
use SignedPlayback;
let payload = new;
let sig = payload.sign?;
If signing is enabled, the signed payload ident must match the /play/{ident} path.
For providers that already return safe direct playable URLs, disable playback routes:
RouterOptions
Manifest Compatibility
Manifest.resources accepts both official Stremio shapes:
"resources":
and:
"resources":
Manifest.extra can carry fields that are not modeled explicitly, such as stremioAddonsConfig.
Error Behavior
Errors are JSON:
Status mapping:
| Error | Status |
|---|---|
| auth failure | 401 |
| invalid config or bad request | 400 |
| provider/playback failure | 500 |
Provider adapters should return empty Stremio responses for normal no-result cases, not errors:
Ok
Ok
Ok
Provider Design Guidance
Keep these in provider crates:
- Provider HTTP clients.
- Login/session/token caching.
- Provider-specific filename parsing that does not fit the shared parser.
- Provider-specific cache policy. The shared
FileJsonCacheonly provides storage semantics. - Provider-specific ranking overrides that do not fit the built-in profiles.
- Provider-specific stream-card formatting that does not fit the built-in card profiles.
This keeps the core stable enough to reuse across provider adapters.