4. Streams
The streams in Stremio's add-ons are just shortcuts to the actual media. They do not contain any videos but instead, they just point Stremio to the right place where these videos can be found.
Update the manifest
If you've selected "streams" in addon-bootstrap, you will have streams
already listed in the resources
array.
"resources": [
"catalog",
{
"name": "meta",
"types": ["movie"],
"idPrefixes": ["hiwrld_"]
},
"streams"
]
Add streams
At this point you have two videos in your catalog. In order to serve them, you will create a function:
function getMovieStreams(id) {
const streams = {
tt1254207: [
{ "title": "HTTP location", "yt_ID": "aqz-KE-bpKQ"}
]
hiwrld_jellyfish: [
{ "title": "Web, 3 MBps, HD", "url": "http://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv" },
{ "title": "Web 15 MBps, HD", "url": "http://jell.yfish.us/media/jellyfish-15-mbps-hd-h264.mkv" },
{ "title": "Web, 120 MBps, 4K", "url": "http://jell.yfish.us/media/jellyfish-120-mbps-4k-uhd-h264.mkv" }
]
}
return Promise.resolve(streams[id] || [])
}
Let's handle this resource:
builder.defineStreamHandler(({type, id}) => {
// Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineStreamHandler.md
let results;
switch(type) {
case 'movie':
results = getMovieStreams(id)
break
default:
results = Promise.resolve( [] )
break
}
return results.then(streams => ({streams}))
})
When your add-on is unable to provide streams for particular video, you have to return an empty streams array. Otherwise and error is shown to the user.
As you can see, the stream object can point to variety of streams. The complete reference is located here.