stremio-addon-sdk

defineStreamHandler

This method handles stream requests.

Arguments:

args - request object; parameters described below

Returns:

A promise resolving to an an object containing { streams: [] } with an array of Stream Objects. The streams should be ordered from highest to lowest quality

The resolving object can also include the following cache related properties:

Request Parameters

type - type of the item that we’re requesting streams for; e.g. movie, series, channel, tv (see Content Types)

id - a Video ID as described in the Video Object

The Video ID is the same as the Meta ID for movies.

For IMDb series (provided by Cinemeta), the video ID is formed by joining the Meta ID, season and episode with a colon (e.g. "tt0898266:9:17").

For live TV / Native EPG, id is the channel Meta ID (not the programme video id). Programmes in meta.videos are schedule only; playback identity stays on the channel. See Native EPG.

config - object with user settings, see Manifest - User Data

Basic Example

builder.defineStreamHandler(function(args) {
    if (args.type === 'movie' && args.id === 'tt1254207') {
        // serve one stream for big buck bunny
        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: [] })
    }
})

Stream Object Definition

Note: You may require additional metadata for the requested item (such as name, releaseInfo, etc), if the requested ID is a IMDB ID (Cinemeta, for example, uses only IMDB IDs), then please refer to Getting Metadata from Cinemeta for this purpose.