From 60b81f4fd311259176035cbc4e7becdade5eb7fb Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Tue, 28 Nov 2023 11:55:08 +0200 Subject: [PATCH 1/5] Document Stream Behavior Hints For Subtitles --- docs/api/responses/stream.md | 5 ++++- src/getRouter.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/api/responses/stream.md b/docs/api/responses/stream.md index c41c0db..610df39 100644 --- a/docs/api/responses/stream.md +++ b/docs/api/responses/stream.md @@ -24,4 +24,7 @@ Used as a response for [`defineStreamHandler`](../requests/defineStreamHandler.m - `countryWhitelist`: which hints it's restricted to particular countries - array of ISO 3166-1 alpha-3 country codes **in lowercase** in which the stream is accessible - `notWebReady`: applies if the protocol of the url is http(s); needs to be set to `true` if the URL does not support https or is not an MP4 file - `bingeGroup`: if defined, addons with the same `behaviorHints.bingeGroup` will be chosen automatically for binge watching; this should be something that identifies the stream's nature within your addon: for example, if your addon is called "gobsAddon", and the stream is 720p, the bingeGroup should be "gobsAddon-720p"; if the next episode has a stream with the same `bingeGroup`, stremio should select that stream implicitly - - `proxyHeaders`: Only applies to `url`s; **When using this property, you must also set `stream.behaviorHints.notWebReady: true`**; This is an object containing `request` and `response` which include the headers that should be used for the stream (example value: `{ "request": { "User-Agent": "Stremio" } }`) + - `proxyHeaders`: only applies to `url`s; **When using this property, you must also set `stream.behaviorHints.notWebReady: true`**; This is an object containing `request` and `response` which include the headers that should be used for the stream (example value: `{ "request": { "User-Agent": "Stremio" } }`) + - `videoHash`: the calculated [OpenSubtitles hash](http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes) of the video, this will be used when the streaming server is not connected (so the hash cannot be calculated locally), this value is passed to subtitle addons to identify correct subtitles + - `videoSize`: size of the video file in bytes, this value is passed to the subtitle addons to identify correct subtitles + - `filename`: filename of the video file, although optional, it is highly recommended to set it when using `stream.url` (when possible) in order to identify correct subtitles (addon sdk will show a warning if it is not set in this case), this value is passed to the subtitle addons to identify correct subtitles diff --git a/src/getRouter.js b/src/getRouter.js index 4c6269d..d6a9ae4 100644 --- a/src/getRouter.js +++ b/src/getRouter.js @@ -89,6 +89,10 @@ function getRouter({ manifest , get }) { res.setHeader('Content-Type', 'application/json; charset=utf-8') + if (resource === 'stream' && ((resp || {}).streams || []).length) + if (resp.streams.find(stream => stream && stream.url && !(stream.behaviorHints || {}).filename)) + console.warn('streams include stream.url but do not include stream.behaviorHints.filename, this is not recommended, subtitles may not be retrieved for these streams') + res.end(JSON.stringify(resp)) }) .catch(err => { From 4a36f682652d43e4a52bb1c4192e7a615445471e Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Tue, 28 Nov 2023 12:02:08 +0200 Subject: [PATCH 2/5] Warn Only Once For Missing Filename --- src/getRouter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/getRouter.js b/src/getRouter.js index d6a9ae4..bde8f1e 100644 --- a/src/getRouter.js +++ b/src/getRouter.js @@ -2,6 +2,8 @@ const Router = require('router') const qs = require('querystring') const cors = require('cors') +const warned = {} + function getRouter({ manifest , get }) { const router = new Router() @@ -89,9 +91,11 @@ function getRouter({ manifest , get }) { res.setHeader('Content-Type', 'application/json; charset=utf-8') - if (resource === 'stream' && ((resp || {}).streams || []).length) - if (resp.streams.find(stream => stream && stream.url && !(stream.behaviorHints || {}).filename)) + if (!warned.filename && resource === 'stream' && ((resp || {}).streams || []).length) + if (resp.streams.find(stream => stream && stream.url && !(stream.behaviorHints || {}).filename)) { + warned.filename = true console.warn('streams include stream.url but do not include stream.behaviorHints.filename, this is not recommended, subtitles may not be retrieved for these streams') + } res.end(JSON.stringify(resp)) }) From 9f3e3e23399c9b821aea3f52b571a10f7fe908f8 Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Tue, 26 Mar 2024 22:07:38 +0700 Subject: [PATCH 3/5] Update docs/api/responses/stream.md Co-authored-by: Tim --- docs/api/responses/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/responses/stream.md b/docs/api/responses/stream.md index 610df39..b88c64c 100644 --- a/docs/api/responses/stream.md +++ b/docs/api/responses/stream.md @@ -25,6 +25,6 @@ Used as a response for [`defineStreamHandler`](../requests/defineStreamHandler.m - `notWebReady`: applies if the protocol of the url is http(s); needs to be set to `true` if the URL does not support https or is not an MP4 file - `bingeGroup`: if defined, addons with the same `behaviorHints.bingeGroup` will be chosen automatically for binge watching; this should be something that identifies the stream's nature within your addon: for example, if your addon is called "gobsAddon", and the stream is 720p, the bingeGroup should be "gobsAddon-720p"; if the next episode has a stream with the same `bingeGroup`, stremio should select that stream implicitly - `proxyHeaders`: only applies to `url`s; **When using this property, you must also set `stream.behaviorHints.notWebReady: true`**; This is an object containing `request` and `response` which include the headers that should be used for the stream (example value: `{ "request": { "User-Agent": "Stremio" } }`) - - `videoHash`: the calculated [OpenSubtitles hash](http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes) of the video, this will be used when the streaming server is not connected (so the hash cannot be calculated locally), this value is passed to subtitle addons to identify correct subtitles + - `videoHash`: - string, the calculated [OpenSubtitles hash](http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes) of the video, this will be used when the streaming server is not connected (so the hash cannot be calculated locally), this value is passed to subtitle addons to identify correct subtitles - `videoSize`: size of the video file in bytes, this value is passed to the subtitle addons to identify correct subtitles - `filename`: filename of the video file, although optional, it is highly recommended to set it when using `stream.url` (when possible) in order to identify correct subtitles (addon sdk will show a warning if it is not set in this case), this value is passed to the subtitle addons to identify correct subtitles From caf3fb3eb64187fd33388bd0b79f3706602b6470 Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Tue, 26 Mar 2024 22:08:00 +0700 Subject: [PATCH 4/5] Update docs/api/responses/stream.md Co-authored-by: Tim --- docs/api/responses/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/responses/stream.md b/docs/api/responses/stream.md index b88c64c..cb5c4a8 100644 --- a/docs/api/responses/stream.md +++ b/docs/api/responses/stream.md @@ -27,4 +27,4 @@ Used as a response for [`defineStreamHandler`](../requests/defineStreamHandler.m - `proxyHeaders`: only applies to `url`s; **When using this property, you must also set `stream.behaviorHints.notWebReady: true`**; This is an object containing `request` and `response` which include the headers that should be used for the stream (example value: `{ "request": { "User-Agent": "Stremio" } }`) - `videoHash`: - string, the calculated [OpenSubtitles hash](http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes) of the video, this will be used when the streaming server is not connected (so the hash cannot be calculated locally), this value is passed to subtitle addons to identify correct subtitles - `videoSize`: size of the video file in bytes, this value is passed to the subtitle addons to identify correct subtitles - - `filename`: filename of the video file, although optional, it is highly recommended to set it when using `stream.url` (when possible) in order to identify correct subtitles (addon sdk will show a warning if it is not set in this case), this value is passed to the subtitle addons to identify correct subtitles + - `filename`: - string, filename of the video file, although optional, it is highly recommended to set it when using `stream.url` (when possible) in order to identify correct subtitles (addon sdk will show a warning if it is not set in this case), this value is passed to the subtitle addons to identify correct subtitles From 5fd18b8cb03894b997d8e18737876d73b03789b3 Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Tue, 26 Mar 2024 22:11:25 +0700 Subject: [PATCH 5/5] Update docs/api/responses/stream.md Co-authored-by: Tim --- docs/api/responses/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/responses/stream.md b/docs/api/responses/stream.md index cb5c4a8..f05d940 100644 --- a/docs/api/responses/stream.md +++ b/docs/api/responses/stream.md @@ -26,5 +26,5 @@ Used as a response for [`defineStreamHandler`](../requests/defineStreamHandler.m - `bingeGroup`: if defined, addons with the same `behaviorHints.bingeGroup` will be chosen automatically for binge watching; this should be something that identifies the stream's nature within your addon: for example, if your addon is called "gobsAddon", and the stream is 720p, the bingeGroup should be "gobsAddon-720p"; if the next episode has a stream with the same `bingeGroup`, stremio should select that stream implicitly - `proxyHeaders`: only applies to `url`s; **When using this property, you must also set `stream.behaviorHints.notWebReady: true`**; This is an object containing `request` and `response` which include the headers that should be used for the stream (example value: `{ "request": { "User-Agent": "Stremio" } }`) - `videoHash`: - string, the calculated [OpenSubtitles hash](http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes) of the video, this will be used when the streaming server is not connected (so the hash cannot be calculated locally), this value is passed to subtitle addons to identify correct subtitles - - `videoSize`: size of the video file in bytes, this value is passed to the subtitle addons to identify correct subtitles + - `videoSize`: - number, size of the video file in bytes, this value is passed to the subtitle addons to identify correct subtitles - `filename`: - string, filename of the video file, although optional, it is highly recommended to set it when using `stream.url` (when possible) in order to identify correct subtitles (addon sdk will show a warning if it is not set in this case), this value is passed to the subtitle addons to identify correct subtitles