A NodeJS SDK for making and publishing Stremio addons
This arbitrary example creates an addon that provides a stream for Big Buck Bunny and outputs a HTTP address where you can access it
#!/usr/bin/env node
const { addonBuilder, serveHTTP, publishToCentral } = require('stremio-addon-sdk')
const builder = new addonBuilder({
id: 'org.myexampleaddon',
version: '1.0.0',
name: 'simple example',
// Properties that determine when Stremio picks this addon
// this means your addon will be used for streams of the type movie
resources: ['stream'],
types: ['movie'],
idPrefixes: ['tt']
})
// takes function(args), returns Promise
builder.defineStreamHandler(function(args) {
if (args.type === 'movie' && args.id === 'tt1254207') {
// serve one stream to big buck bunny
// return addonSDK.Stream({ url: '...' })
const stream = { url: 'http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_30fps_normal.mp4' }
return Promise.resolve({ streams: [stream] })
} else {
// otherwise return no streams
return Promise.resolve({ streams: [] })
}
})
serveHTTP(builder.getInterface(), { port: 7000 })
// If you want this addon to appear in the addon catalogs, call .publishToCentral() with the publically available URL to your manifest
//publishToCentral('https://my-addon.com/manifest.json')
Save this as addon.js
and run:
npm install stremio-addon-sdk
node ./addon.js
It will output a URL that you can use to install the addon in Stremio
To get familiar with the resources and their roles, read this.
Imports everything the SDK provides:
addonBuilder
, which you'll need to define the addonserveHTTP
, which you will need to serve a HTTP server for this addongetRouter
, converts anaddonInterface
to an express routerpublishToCentral
: publishes an addon URL to the public addon catalog
Creates an addon builder object with a given manifest. This will throw if the manifest is not valid.
The manifest will determine the basic information of your addon (name, description, images), but most importantly, it will determine when and how your addon will be invoked by Stremio.
Handles catalog requests, including search.
Catalog Request Parameters and Example
Handles metadata requests. (title, releaseInfo, poster, background, etc.)
Meta Request Parameters and Example
Handles stream requests.
Stream Request Parameters and Example
Handles subtitle requests.
Subtitle Request Parameters and Example
Handles addon catalog requests, this can be used by an addon to just send a list of other addon manifests.
Addon Catalog Request Parameters and Example
The JSON format of the response to these resources is described here.
Turns the addon
into an addonInterface
, which is an immutable (frozen) object that has {manifest, get}
; manifest is a regular manifest object, while get
is a function that takes one argument of the form { resource, type, id, extra }
, and returns a Promise
Turns the addonInterface
into an express router, that serves the addon according to the protocol, and a landing page on the root (/
)
This method expects a string with the url to your manifest.json
file.
Publish your addon to the central server. After using this method your addon will be available in the Community Addons list in Stremio for users to install and use. Your addon needs to be publicly available with a URL in order for this to happen, as local addons that are not publicly available cannot be used by other Stremio users.
Starts the addon server. options
is an object that contains:
port
cacheMaxAge
(in seconds);cacheMaxAge
means theCache-Control
header being set tomax-age=$cacheMaxAge
static
: path to a directory of static files to be served; e.g./public
This method is also special in that it will react to certain process arguments, such as:
--launch
: launches Stremio in the web browser, and automatically installs/upgrades the addon--install
: installs the addon in the desktop version of Stremio
The addonInterface
, as returned from builder.getInterface()
, has two properties:
get({ resource, type, id, extra })
- returns a Promisemanifest
: manifest object