Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs and support for player and library events #241

Open
wants to merge 3 commits into
base: feat/library-and-player-resources
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions cli/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async function createAddon() {
{name: 'stream'},
{name: 'meta'},
{name: 'subtitles'},
{name: 'watchStatus'},
{name: 'player'},
{name: 'library'},
]
},
{
Expand Down Expand Up @@ -200,11 +201,19 @@ builder.defineSubtitlesHandler(({type, id, extra}) => {
})
`

const watchStatusTmpl = () => `
builder.defineWatchStatusHandler(({type, id, extra}) => {
console.log("request for watchStatus: "+type+" "+id+" "+extra)
// Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineWatchStatusHandler.md
return Promise.resolve({ watchStatus: 'success' })
const playerTmpl = () => `
builder.definePlayerHandler(({type, id, extra}) => {
console.log("request for player: "+type+" "+id+" "+extra)
// Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/definePlayerHandler.md
return Promise.resolve({ success: true })
})
`

const libraryTmpl = () => `
builder.defineLibraryHandler(({type, id, extra}) => {
console.log("request for library: "+type+" "+id+" "+extra)
// Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineLibraryHandler.md
return Promise.resolve({ success: true })
})
`

Expand All @@ -218,7 +227,8 @@ function genAddonJS(manifest, resources, types) {
.concat(resources.includes('meta') ? [metaTmpl()] : [])
.concat(resources.includes('stream') ? [types.includes('movie') ? streamsMovieTmpl() : streamsTmpl()] : [])
.concat(resources.includes('subtitles') ? [subtitlesTmpl()] : [])
.concat(resources.includes('watchStatus') ? [watchStatusTmpl()] : [])
.concat(resources.includes('player') ? [playerTmpl()] : [])
.concat(resources.includes('library') ? [libraryTmpl()] : [])
.concat(footerTmpl())
.join('')
}
6 changes: 3 additions & 3 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ In order for Stremio to display addon data, the addon must first supply the reso
| **streams** | [defineStreamHandler](./requests/defineStreamHandler.md) | [stream](./responses/stream.md) | Tells Stremio how to obtain the media content. It may be torrent info hash, HTTP URL, etc |
| **subtitles** | [defineSubtitlesHandler](./requests/defineSubtitlesHandler.md) | [subtitles](./responses/subtitles.md) | Subtitles resource for the chosen media. |
| **addon_catalog** | [defineResourceHandler](./requests/defineResourceHandler.md) | [addon_catalog](./responses/addon_catalog.md) | A catalog (list) of other addon manifests. |
| **watchStatus** | [defineWatchStatusHandler](./requests/defineWatchStatusHandler.md) | 'success' or 'error' | |
| **player** | [definePlayerHandler](./requests/definePlayerHandler.md) | [event_response](./responses/event_response.md) | |
| **library** | [defineLibraryHandler](./requests/defineLibraryHandler.md) | [event_response](./responses/event_response.md) | |

The structure of those resources in Stremio is as follows:

Expand All @@ -21,7 +22,6 @@ The structure of those resources in Stremio is as follows:
+-- Videos (part of Meta Item)
+---+-- Streams
+---+---+-- Subtitles
+---+---+-- watchStatus
```

When the user opens the Discover/Board section, catalogs from all installed addons are loaded. Catalog responses include [meta preview objects](./responses/meta.md#meta-preview-object), which are just stripped down versions of the full meta object.
Expand All @@ -37,6 +37,6 @@ We determine whether an addon is relevant by comparing the request against it's

For catalogs, we usually request all catalogs from all addons, that are compatible with the `extra` properties that we're looking for. For example, to load the Board, we'd load all catalogs that have no `extra` properties that are required. But, if we're loading Search, we'd load all catalogs that have `search` as a supported property in their `extra` definition.

For other requests (meta, stream, subtitles, watchStatus), we apply the `types` and the optional `idPrefixes` filters (which can also be defined per-resource). For example, for `/meta/movie/tt1254207`, we'd try to load meta from all addons that have `"movie"` in `manifest.types` (or have `{ name: "meta", types: ["movie'] }` in `manifest.resources`). If `manifest.idPrefixes` is defined, `["tt"]` will match this request, but something different (e.g. `["yt_id:"]`) won't. This helps you ensure your addon does not get irrelevant requests.
For other requests (meta, stream, subtitles, player, library), we apply the `types` and the optional `idPrefixes` filters (which can also be defined per-resource). For example, for `/meta/movie/tt1254207`, we'd try to load meta from all addons that have `"movie"` in `manifest.types` (or have `{ name: "meta", types: ["movie'] }` in `manifest.resources`). If `manifest.idPrefixes` is defined, `["tt"]` will match this request, but something different (e.g. `["yt_id:"]`) won't. This helps you ensure your addon does not get irrelevant requests.

For the full spec, see [manifest - filtering properties](./responses/manifest.md#filtering-properties).
16 changes: 10 additions & 6 deletions docs/api/requests/defineLibraryHandler.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## defineLibraryHandler

This method handles library requests.
This method handles library events.

### Arguments:

Expand All @@ -11,9 +11,13 @@ This method handles library requests.

## Request Parameters

``type`` - type of the item that we're requesting streams for; e.g. `movie`, `series`, `channel`, `tv` (see [Content Types](../responses/content.types.md))
``type`` - type of the item that we're emitting player events for; e.g. `movie`, `series`, `channel`, `tv` (see [Content Types](../responses/content.types.md))

``id`` - a **Meta ID** as described in the [Meta Object](../responses/meta.md#meta-object)
``id`` - a Video ID as described in the [Video Object](../responses/meta.md#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"`).

``extra`` - object that holds additional properties; defined below

Expand All @@ -34,11 +38,11 @@ This method handles library requests.
```javascript
builder.defineLibraryHandler(function(args) {
if (args.type === 'movie' && args.id === 'tt1254207') {
// Library event has been successfully
return Promise.resolve({ handled: true })
// handle the library event
return Promise.resolve({ success: true })
} else {
// otherwise return false
return Promise.resolve({ handled: false })
return Promise.resolve({ success: false })
}
})
```
Expand Down
14 changes: 7 additions & 7 deletions docs/api/requests/definePlayerHandler.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## definePlayerHandler

This method handles player requests.
This method handles player events.

### Arguments:

Expand All @@ -11,13 +11,13 @@ This method handles player requests.

## Request Parameters

``type`` - type of the item that we're requesting streams for; e.g. `movie`, `series`, `channel`, `tv` (see [Content Types](../responses/content.types.md))
``type`` - type of the item that we're emitting player events for; e.g. `movie`, `series`, `channel`, `tv` (see [Content Types](../responses/content.types.md))

``id`` - a **Video ID** as described in the [Video Object](../responses/meta.md#video-object)
``id`` - a Video ID as described in the [Video Object](../responses/meta.md#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 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"`).

``extra`` - object that holds additional properties; defined below

Expand All @@ -38,11 +38,11 @@ For IMDb series (provided by Cinemeta), the video ID is formed by joining the Me
```javascript
builder.definePlayerHandler(function(args) {
if (args.type === 'movie' && args.id === 'tt1254207') {
// Player event has been successfully
return Promise.resolve({ handled: true })
// handle the player event
return Promise.resolve({ success: true })
} else {
// otherwise return false
return Promise.resolve({ handled: false })
return Promise.resolve({ success: false })
}
})
```
Expand Down
2 changes: 1 addition & 1 deletion docs/api/requests/defineStreamHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The resolving object can also include the following cache related properties:

**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 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"`).

``config`` - object with user settings, see [Manifest - User Data](../responses/manifest.md#user-data)

Expand Down
5 changes: 5 additions & 0 deletions docs/api/responses/event_response.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## event response Object

Used as a response for [`definePlayerHandler`](../requests/definePlayerHandler.md) and [`defineLibraryHandler`](../requests/defineLibraryHandler.md)

``success`` - **required** - bool, either true or false, representing if the handling of the event was successful or not.
2 changes: 1 addition & 1 deletion docs/api/responses/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Valid properties are:

**NOTE:** In order to understand the next properties better, please check out the [protocol documentation](../../protocol.md) and keep in mind requests to addons are formed in the format of `/{resource}/{type}/{id}`

``resources`` - **required** - array of objects or strings, supported resources - for example ``["catalog", "meta", "stream", "subtitles", "addon_catalog", "watchStatus"]``, resources can also be added as objects instead of strings, for additional details on how they should be requested, example: `{ "name": "stream", "types": [ "movie" ], "idPrefixes": [ "tt" ] }` (see the **ADVANCED** note)
``resources`` - **required** - array of objects or strings, supported resources - for example ``["catalog", "meta", "stream", "subtitles", "addon_catalog", "player", "library"]``, resources can also be added as objects instead of strings, for additional details on how they should be requested, example: `{ "name": "stream", "types": [ "movie" ], "idPrefixes": [ "tt" ] }` (see the **ADVANCED** note)

``types`` - **required** - array of strings, supported types, from all the [``Content Types``](./content.types.md). If you wish to provide different sets of types for different resources, see the **ADVANCED** note.

Expand Down
2 changes: 1 addition & 1 deletion docs/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This allows Stremio or other similar applications to aggregate content seamlessl

To define a minimal addon, you only need an HTTP server/endpoint serving a `/manifest.json` file and responding to resource requests at `/{resource}/{type}/{id}.json`.

Currently used resources are: `catalog`, `meta`, `stream`, `subtitles`, `watchStatus`.
Currently used resources are: `catalog`, `meta`, `stream`, `subtitles`, `player`, `library`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add playback


`/catalog/{type}/{id}.json` - catalogs of media items; `type` denotes the type, such as `movie`, `series`, `channel`, `tv`, and `id` denotes the catalog ID, which is custom and specified in your manifest, `id` is required as an addon can hold multiple catalogs

Expand Down
3 changes: 2 additions & 1 deletion src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function AddonBuilder(manifest) {
this.defineMetaHandler = this.defineResourceHandler.bind(this, 'meta')
this.defineCatalogHandler = this.defineResourceHandler.bind(this, 'catalog')
this.defineSubtitlesHandler = this.defineResourceHandler.bind(this, 'subtitles')
this.defineWatchStatusHandler = this.defineResourceHandler.bind(this, 'watchStatus')
this.definePlayerHandler = this.defineResourceHandler.bind(this, 'player')
this.defineLibraryHandler = this.defineResourceHandler.bind(this, 'library')

// build into an interface
this.getInterface = function() {
Expand Down