stremiok 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +15 -12
- package/config.xml +1 -1
- package/css/style.css +14 -9
- package/index.html +34 -33
- package/js/app.js +18 -19
- package/js/focus.js +30 -10
- package/js/iptv.js +107 -9
- package/js/player-core.js +80 -18
- package/js/player-store.js +3 -3
- package/js/player-subs.js +47 -7
- package/js/stremio.js +196 -28
- package/js/util.js +137 -16
- package/js/view-core.js +53 -13
- package/js/view-detail.js +35 -7
- package/js/view-discover.js +1 -1
- package/js/view-home.js +110 -20
- package/js/view-settings.js +114 -4
- package/js/views.js +1 -1
- package/js/xtvod.js +366 -0
- package/js/ytplay.js +28 -4
- package/package.json +2 -1
- package/service/index.js +553 -18
package/js/stremio.js
CHANGED
|
@@ -162,6 +162,8 @@ var Stremio = (function () {
|
|
|
162
162
|
function getPrefs() {
|
|
163
163
|
var p = U.store.get(PREFS_KEY, {}) || {};
|
|
164
164
|
return { posterShape: p.posterShape || 'portrait', accent: p.accent || 'indigo', bg: p.bg || 'dark',
|
|
165
|
+
zoom: [110, 120, 130, 140].indexOf(p.zoom) !== -1 ? p.zoom : 100, // Settings > Appearance: everything bigger (percent)
|
|
166
|
+
rowCards: [50, 100, 200].indexOf(p.rowCards) !== -1 ? p.rowCards : 30, // Settings > Appearance: titles in a Home row
|
|
165
167
|
formatsAuto: p.formatsAuto !== false, // Settings > Formats: mark "Not working" on its own
|
|
166
168
|
allowLocal: p.allowLocal === true, // Settings > Addons: home-network links from internet addons
|
|
167
169
|
addonWait: ADDON_WAITS.indexOf(p.addonWait) !== -1 ? p.addonWait : 0, // Settings > Addons: seconds to wait for an addon (0: Normal)
|
|
@@ -289,7 +291,7 @@ var Stremio = (function () {
|
|
|
289
291
|
var APP_FIELDS = {};
|
|
290
292
|
['_addon', '_addonPos', '_addonRank', '_also', '_cardImage', '_posterAlt', '_from', '_headers', '_keepStream', '_playlistId', '_reported', '_yt', '_file',
|
|
291
293
|
'_group', '_local', '_localSubs', '_tmdbWhere', '_trakt', '_dupes', '_restoreKey', '_current', '_autoFocus', '_epFocus', '_focusNp', '_focusPill',
|
|
292
|
-
'_focusSeason', '_focusTrailer', '_earlier', '_localFile', 'stale', 'ytPage'].forEach(function (k) { APP_FIELDS[k] = 1; });
|
|
294
|
+
'_focusSeason', '_focusTrailer', '_earlier', '_localFile', '_torrent', '_pickFile', 'stale', 'ytPage'].forEach(function (k) { APP_FIELDS[k] = 1; });
|
|
293
295
|
function fieldSet(list) { var o = {}; list.forEach(function (k) { o[k] = 1; }); return o; }
|
|
294
296
|
var STR_FIELDS = fieldSet(['id', 'type', 'name', 'title', 'description', 'poster', 'background', 'logo', 'thumbnail', 'banner', 'url', 'externalUrl', 'ytId',
|
|
295
297
|
'infoHash', 'releaseInfo', 'released', 'imdb_id', 'lang', 'filename', 'bingeGroup', 'posterShape', 'runtime']);
|
|
@@ -433,6 +435,7 @@ var Stremio = (function () {
|
|
|
433
435
|
// Appearance > Home feeds; there's no cap on how many rows or feeds).
|
|
434
436
|
if (iptvNow) { addons.unshift(IPTV.synthAddon()); }
|
|
435
437
|
else if (iptvOn) { iptvJoin(addons, rev); }
|
|
438
|
+
if (typeof XtVod !== 'undefined' && XtVod.isEnabled()) { addons.push(XtVod.synthAddon()); } // (your Xtream accounts' films and series: after your addons)
|
|
436
439
|
if (hasYouTube()) { addons.push(YouTube.synthAddon()); } // (after your addons: its rows last on Home)
|
|
437
440
|
if (typeof Trakt !== 'undefined' && Trakt.isConnected()) { addons.push(Trakt.synthAddon()); } // (your Watchlist and Up next)
|
|
438
441
|
_loaded = addons;
|
|
@@ -487,6 +490,11 @@ var Stremio = (function () {
|
|
|
487
490
|
configChanged();
|
|
488
491
|
return id;
|
|
489
492
|
}
|
|
493
|
+
function iptvAddStalker(portal, mac) { // (as an Xtream account)
|
|
494
|
+
var id = _hasIptv ? IPTV.addStalker(portal, mac) : false;
|
|
495
|
+
configChanged();
|
|
496
|
+
return id;
|
|
497
|
+
}
|
|
490
498
|
function iptvSetXtreamFormat(id, fmt) {
|
|
491
499
|
var changed = _hasIptv ? IPTV.setXtreamFormat(id, fmt) : false;
|
|
492
500
|
configChanged();
|
|
@@ -498,8 +506,21 @@ var Stremio = (function () {
|
|
|
498
506
|
function iptvMovePlaylist(id, dir) { var ok = _hasIptv ? IPTV.movePlaylist(id, dir) : false; configChanged(); return ok; }
|
|
499
507
|
function iptvLabel(id) { return _hasIptv ? IPTV.label(id) : ''; }
|
|
500
508
|
function iptvLoad() { return _hasIptv ? IPTV.load() : Promise.resolve(null); }
|
|
509
|
+
function iptvRefreshEvery() { return _hasIptv && IPTV.refreshEvery ? IPTV.refreshEvery() : 0; }
|
|
510
|
+
function iptvSetRefreshEvery(h) { if (_hasIptv && IPTV.setRefreshEvery) { IPTV.setRefreshEvery(h); } }
|
|
511
|
+
function iptvReadAt() { return _hasIptv && IPTV.readAt ? IPTV.readAt() : Infinity; }
|
|
501
512
|
function iptvStatus(id) { return _hasIptv ? IPTV.status(id) : { error: 'IPTV unavailable' }; }
|
|
502
513
|
// Force a re-fetch of one playlist (Settings → Reload) and rebuild the addon list.
|
|
514
|
+
// An Xtream account turned out to have films and series, or none (XtVod.onVodChange): the IPTV
|
|
515
|
+
// rows made again from the saved copies (its film and episode lines in or out), not downloaded.
|
|
516
|
+
function iptvRebuild() {
|
|
517
|
+
if (!_hasIptv) { return; }
|
|
518
|
+
IPTV.reset();
|
|
519
|
+
configChanged();
|
|
520
|
+
loadAddons().then(null, function () {});
|
|
521
|
+
}
|
|
522
|
+
if (typeof XtVod !== 'undefined' && XtVod.onVodChange) { XtVod.onVodChange(iptvRebuild); }
|
|
523
|
+
if (typeof XtVod !== 'undefined' && XtVod.onChange) { XtVod.onChange(function () { sourcesChanged(); }); } // (its list read: its copies, on titles asked before)
|
|
503
524
|
function iptvReload(id) {
|
|
504
525
|
configChanged();
|
|
505
526
|
return _hasIptv ? IPTV.reload(id) : Promise.resolve(null);
|
|
@@ -757,14 +778,14 @@ var Stremio = (function () {
|
|
|
757
778
|
function addonKey(a) { return (a.manifest && a.manifest.id) || a.url; }
|
|
758
779
|
function streamAddons() {
|
|
759
780
|
return loadAddons().then(function (addons) {
|
|
760
|
-
return addons.filter(function (a) { return !a.__local && supports(a, 'stream'); }).map(function (a) {
|
|
781
|
+
return addons.filter(function (a) { return (!a.__local || a.__sources) && supports(a, 'stream'); }).map(function (a) {
|
|
761
782
|
return { key: addonKey(a), name: (a.manifest && a.manifest.name) || a.url, addon: a };
|
|
762
783
|
});
|
|
763
784
|
});
|
|
764
785
|
}
|
|
765
786
|
var sourceFeeds = feedList(SOURCE_FEEDS_KEY, streamAddons, function (x) { return x.key; });
|
|
766
787
|
// Whether any addon you have provides sources (true while the addons aren't loaded yet)
|
|
767
|
-
function hasStreamAddons() { return !_loaded || _loaded.some(function (a) { return !a.__local && supports(a, 'stream'); }); }
|
|
788
|
+
function hasStreamAddons() { return !_loaded || _loaded.some(function (a) { return (!a.__local || a.__sources) && supports(a, 'stream'); }); }
|
|
768
789
|
function sourcesChanged() { _streamCache = {}; _streamOrder = []; } // (cached lists came from the old set)
|
|
769
790
|
|
|
770
791
|
// ---- Source ranking (Settings > Source ranking) ----
|
|
@@ -777,17 +798,24 @@ var Stremio = (function () {
|
|
|
777
798
|
['uncached', 'Not yet cached last', 'sources an addon marks as not cached on your debrid service yet (they can’t start right away)'],
|
|
778
799
|
['kind', 'Release type', 'remux > Blu-ray > web > unknown > TV rip, CAM rips far below'],
|
|
779
800
|
['hdr', 'HDR before SDR', 'HDR10 / HDR10+ / Dolby Vision first'],
|
|
801
|
+
['seeds', 'Seeders (high to low)', 'torrent sources with more people sharing them first, by the count they state (👤 123, or Seeders: 123); the others keep their order'],
|
|
780
802
|
['addon', 'Feed sources order', 'your order of the addons (at the bottom of this page)'],
|
|
781
803
|
['within', 'Each addon\'s own order', 'the order an addon lists its sources in (its first, then its second…); right after Feed sources order: each addon\'s list as it gives it'],
|
|
782
804
|
['cached', 'Cached before unknown', 'sources an addon marks as cached ahead of ones with no mark']
|
|
783
805
|
];
|
|
784
806
|
var RANK_OFF_DEFAULT = ['cached'];
|
|
807
|
+
var RANK_AFTER = { seeds: 'hdr' }; // (added in 2.2.1.13)
|
|
785
808
|
function getRanking() {
|
|
786
809
|
var r = U.store.get(RANKING_KEY, null) || {}, known = {}, order = [];
|
|
787
810
|
RANK_CRITERIA.forEach(function (c) { known[c[0]] = c; });
|
|
788
811
|
(r.order || []).forEach(function (k) { if (known[k] && order.indexOf(k) === -1) { order.push(k); } });
|
|
789
|
-
// one missing from a saved order goes where it is by default (Resolution: first)
|
|
790
|
-
|
|
812
|
+
// one missing from a saved order goes where it is by default (Resolution: first), or right
|
|
813
|
+
// after the one it follows (RANK_AFTER: Seeders after HDR, wherever you moved that)
|
|
814
|
+
RANK_CRITERIA.forEach(function (c, i) {
|
|
815
|
+
if (order.indexOf(c[0]) !== -1) { return; }
|
|
816
|
+
var after = RANK_AFTER[c[0]] ? order.indexOf(RANK_AFTER[c[0]]) : -1;
|
|
817
|
+
order.splice(after !== -1 ? after + 1 : Math.min(i, order.length), 0, c[0]);
|
|
818
|
+
});
|
|
791
819
|
var off = r.off || RANK_OFF_DEFAULT;
|
|
792
820
|
return { played: r.played !== false, criteria: order.map(function (k) {
|
|
793
821
|
return { key: k, name: known[k][1], sub: known[k][2], on: off.indexOf(k) === -1 };
|
|
@@ -861,6 +889,9 @@ var Stremio = (function () {
|
|
|
861
889
|
if (/^ytk:/.test(id) && typeof YouTube !== 'undefined') {
|
|
862
890
|
return YouTube.meta(id).then(function (m) { if (!m) { throw new Error('Not found on YouTube'); } return m; });
|
|
863
891
|
}
|
|
892
|
+
if (/^xv[ms]\./.test(id) && typeof XtVod !== 'undefined') {
|
|
893
|
+
return XtVod.meta(type, id).then(function (m) { if (!m) { throw new Error('Not found on the Xtream server'); } return m; });
|
|
894
|
+
}
|
|
864
895
|
if (/^iptv:/.test(id)) {
|
|
865
896
|
return IPTV.meta(id).then(function (m) {
|
|
866
897
|
if (!m) { throw new Error('IPTV channel not found'); }
|
|
@@ -928,6 +959,9 @@ var Stremio = (function () {
|
|
|
928
959
|
if (/^iptv:/.test(id)) {
|
|
929
960
|
return IPTV.streams(id).then(function (l) { if (onUpdate) { onUpdate(l, 0); } return l; });
|
|
930
961
|
}
|
|
962
|
+
if (/^xv[ms]\./.test(id) && typeof XtVod !== 'undefined') { // (an Xtream account's own film or episode)
|
|
963
|
+
return XtVod.streams(type, id).then(function (l) { l.forEach(function (s) { s._addon = 'Xtream'; }); if (onUpdate) { onUpdate(l, 0); } return l; });
|
|
964
|
+
}
|
|
931
965
|
var key = type + ':' + id, e = _streamCache[key];
|
|
932
966
|
if (e && !force && (e.pending > 0 || Date.now() - e.at < STREAM_TTL)) {
|
|
933
967
|
syncLocal(e, type, id); // (the addons' answers kept; the USB drive's matches as they are now)
|
|
@@ -961,8 +995,10 @@ var Stremio = (function () {
|
|
|
961
995
|
return U.settleAll(providers.map(function (a, i) {
|
|
962
996
|
return function () {
|
|
963
997
|
var url = a.base + '/stream/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '.json';
|
|
964
|
-
|
|
965
|
-
|
|
998
|
+
// (StremioK's own source, your Xtream accounts' copies: asked here, with the title's details)
|
|
999
|
+
var asked = a.__impl ? metaFirst(type, id).then(function (m) { return a.__impl.streams(type, id, m); }).then(function (l) { return { streams: l }; }) : U.getJSON(url, addonMs(15000));
|
|
1000
|
+
return asked.then(function (res) {
|
|
1001
|
+
var arr = U.listOf(a.__impl ? res.streams : fromAddon(a, res, 'sources').streams, MAX_STREAMS).map(youTubeSource).map(torrentSource), said = notes.length;
|
|
966
1002
|
arr = arr.filter(function (s) { // (an addon's notices: what it removed and why, its errors; not sources)
|
|
967
1003
|
if (!isNotice(s)) { return true; }
|
|
968
1004
|
notes.push({ addon: a.manifest.name || 'Addon', title: ('' + (s.name || '')).replace(/\s+/g, ' ').trim().slice(0, 120),
|
|
@@ -1019,14 +1055,23 @@ var Stremio = (function () {
|
|
|
1019
1055
|
return e.promise;
|
|
1020
1056
|
}
|
|
1021
1057
|
|
|
1022
|
-
|
|
1058
|
+
// A title's details, if its page has them (a series': its show's): for StremioK's own sources.
|
|
1059
|
+
function metaKept(type, id) { return _metaCache[type + ':' + (type === 'series' ? ('' + id).split(':')[0] : id)] || null; }
|
|
1060
|
+
// ...asked for when it doesn't yet (a film's sources are asked for alongside its details): the
|
|
1061
|
+
// others' sources don't wait for this one's.
|
|
1062
|
+
function metaFirst(type, id) {
|
|
1063
|
+
var m = metaKept(type, id);
|
|
1064
|
+
if (m) { return Promise.resolve(m); }
|
|
1065
|
+
return getMeta(type, type === 'series' ? ('' + id).split(':')[0] : id).then(null, function () { return null; });
|
|
1066
|
+
}
|
|
1067
|
+
function isTimeout(err) { return /^(Timeout|Timed out)/.test((err && err.message) || ''); }
|
|
1023
1068
|
// Why an addon's sources didn't come, in a few words (its link, and any token in it, left out):
|
|
1024
1069
|
// "refused (HTTP 429 · rate_limited)", "didn't answer in time", "couldn't be reached"…
|
|
1025
1070
|
function whyNone(err) {
|
|
1026
1071
|
var m = String((err && err.message) || ''), h = /^HTTP (\d{3}) for \S+(?::\s+(.+))?$/.exec(m); // (its message after ": ", not the link's "://")
|
|
1027
1072
|
if (h) { return 'refused (HTTP ' + h[1] + (h[2] ? ' · ' + h[2].replace(/https?:\/\/\S+/g, '…').slice(0, 80) : '') + ')'; }
|
|
1028
1073
|
if (isTimeout(err)) { return 'didn’t answer in time'; }
|
|
1029
|
-
if (/^Network error/.test(m)) { return 'couldn’t be reached'; }
|
|
1074
|
+
if (/^(No answer|Network error)/.test(m)) { return 'couldn’t be reached'; }
|
|
1030
1075
|
if (/^Too large/.test(m)) { return 'sent too much (' + (/\(([^)]+)\)/.exec(m) || ['', 'too large'])[1] + ')'; }
|
|
1031
1076
|
return 'failed (' + m.replace(/https?:\/\/\S+/g, '…').slice(0, 80) + ')';
|
|
1032
1077
|
}
|
|
@@ -1066,6 +1111,7 @@ var Stremio = (function () {
|
|
|
1066
1111
|
if (!st || typeof st.url !== 'string' || !/^https?:\/\//i.test(st.url) || st._localFile || !st._addon) { return; }
|
|
1067
1112
|
var copy = {};
|
|
1068
1113
|
Object.keys(st).forEach(function (k) { if (KEPT_SKIP.indexOf(k) === -1) { copy[k] = st[k]; } });
|
|
1114
|
+
if (st._torrent) { delete copy.url; delete copy._pickFile; } // (its link: made again from the streaming server set then)
|
|
1069
1115
|
var all = keptAll(), key = type + ':' + id, sid = sourceId(st);
|
|
1070
1116
|
var list = (Array.isArray(all[key]) ? all[key] : []).filter(function (x) { return x && x.st && sourceId(x.st) !== sid; });
|
|
1071
1117
|
list.unshift({ at: Date.now(), st: copy });
|
|
@@ -1091,6 +1137,7 @@ var Stremio = (function () {
|
|
|
1091
1137
|
var s = {};
|
|
1092
1138
|
Object.keys(x.st).forEach(function (k) { s[k] = x.st[k]; });
|
|
1093
1139
|
s._earlier = x.at || 1; s._addonRank = rank; s._addonPos = n;
|
|
1140
|
+
if (s._torrent) { torrentSource(s); } // (none with no server set: not playable)
|
|
1094
1141
|
return s;
|
|
1095
1142
|
});
|
|
1096
1143
|
}
|
|
@@ -1144,7 +1191,7 @@ var Stremio = (function () {
|
|
|
1144
1191
|
var tasks = providers.map(function (a) {
|
|
1145
1192
|
return function () {
|
|
1146
1193
|
var url = a.base + '/subtitles/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + (args.length ? '/' + args.join('&') : '') + '.json';
|
|
1147
|
-
return U.getJSON(url, addonMs(
|
|
1194
|
+
return U.getJSON(url, addonMs(15000)).then(function (res) { // (15 s: a subtitle addon may fetch them from elsewhere first)
|
|
1148
1195
|
var arr = U.listOf(fromAddon(a, res, 'subtitles').subtitles, MAX_SUBTITLES);
|
|
1149
1196
|
arr.forEach(function (s) { s._addon = a.manifest.name || 'Addon'; });
|
|
1150
1197
|
return arr;
|
|
@@ -1158,10 +1205,13 @@ var Stremio = (function () {
|
|
|
1158
1205
|
r.value.forEach(function (s) {
|
|
1159
1206
|
if (!s || !s.url || seen[s.url]) { return; }
|
|
1160
1207
|
seen[s.url] = 1;
|
|
1208
|
+
s._at = out.length; // (your addon order, then each addon's own: the order within a language)
|
|
1161
1209
|
out.push(s);
|
|
1162
1210
|
});
|
|
1163
1211
|
});
|
|
1164
|
-
|
|
1212
|
+
// By language, and within one as they came (the TV's sort doesn't keep the order of
|
|
1213
|
+
// equal items: an addon's best match could end up anywhere among its language's).
|
|
1214
|
+
out.sort(function (a, b) { return ('' + (a.lang || '')).localeCompare('' + (b.lang || '')) || a._at - b._at; });
|
|
1165
1215
|
return out;
|
|
1166
1216
|
});
|
|
1167
1217
|
});
|
|
@@ -1618,14 +1668,23 @@ var Stremio = (function () {
|
|
|
1618
1668
|
// GET https://api.theintrodb.org/v4/media?imdb_id=tt..[&season=&episode=][&duration_ms=]
|
|
1619
1669
|
// (v4: answers keyed by the show's TheTVDB id, episodes in TheTVDB's default order; the
|
|
1620
1670
|
// segments as v3 gave them. v2 and v3 stop on 18 Jan 2027.)
|
|
1671
|
+
// A skip-times lookup that gave nothing: why, for its line in Diagnostics (the lookups aren't
|
|
1672
|
+
// noted on their own). A 404 is the source having nothing for it (TheIntroDB: "no
|
|
1673
|
+
// submissions for this media"); anything else, why it didn't answer.
|
|
1674
|
+
function segMiss(err) {
|
|
1675
|
+
if (/^HTTP 404\b/.test((err && err.message) || '')) { return { _why: 'nothing' }; }
|
|
1676
|
+
var p = U.problem(err);
|
|
1677
|
+
return { _why: /^no answer/.test(p) ? p : 'no answer (' + p + ')' }; // ("no answer (connection refused…)" once, not twice)
|
|
1678
|
+
}
|
|
1679
|
+
function segWhy(r, has) { return r && r._why ? r._why : !r ? 'no answer' : has.length ? has.join(', ') : 'nothing'; }
|
|
1621
1680
|
function theIntroDb(q, durationMs) {
|
|
1622
1681
|
var url = 'https://api.theintrodb.org/v4/media?imdb_id=' + encodeURIComponent(q.imdb);
|
|
1623
1682
|
if (q.ep) { url += '&season=' + encodeURIComponent(q.ep.season) + '&episode=' + encodeURIComponent(q.ep.episode); }
|
|
1624
1683
|
if (durationMs && durationMs > 0) { url += '&duration_ms=' + Math.floor(durationMs); }
|
|
1625
|
-
return U.getJSON(url, 10000).then(function (r) {
|
|
1684
|
+
return U.getJSON(url, 10000, 0, null, null, null, true).then(function (r) {
|
|
1626
1685
|
if (!r) { return null; }
|
|
1627
1686
|
return { intro: segsOf(r.intro), recap: segsOf(r.recap), credits: segsOf(r.credits), preview: segsOf(r.preview) };
|
|
1628
|
-
},
|
|
1687
|
+
}, segMiss);
|
|
1629
1688
|
}
|
|
1630
1689
|
// GET https://api.skipdb.tv/api/segments?imdb_id=tt..[&season=&episode=][&duration=<sec>]
|
|
1631
1690
|
// -> { segments: { intro, recap, outro, preview } }, each the best match or null.
|
|
@@ -1633,12 +1692,12 @@ var Stremio = (function () {
|
|
|
1633
1692
|
var url = 'https://api.skipdb.tv/api/segments?imdb_id=' + encodeURIComponent(q.imdb);
|
|
1634
1693
|
if (q.ep) { url += '&season=' + encodeURIComponent(q.ep.season) + '&episode=' + encodeURIComponent(q.ep.episode); }
|
|
1635
1694
|
if (durationMs && durationMs > 0) { url += '&duration=' + Math.round(durationMs / 1000); }
|
|
1636
|
-
return U.getJSON(url, 10000).then(function (r) {
|
|
1695
|
+
return U.getJSON(url, 10000, 0, null, null, null, true).then(function (r) {
|
|
1637
1696
|
var sg = r && r.segments;
|
|
1638
1697
|
if (!sg || typeof sg !== 'object') { return null; }
|
|
1639
1698
|
function one(x) { return segsOf(x ? [x] : []); }
|
|
1640
1699
|
return { intro: one(sg.intro), recap: one(sg.recap), credits: one(sg.outro), preview: one(sg.preview) };
|
|
1641
|
-
},
|
|
1700
|
+
}, segMiss);
|
|
1642
1701
|
}
|
|
1643
1702
|
// GET https://api.introdb.app/segments?imdb_id=tt..(&season=&episode= | &is_movie=true)
|
|
1644
1703
|
// -> { intro, recap, outro, post_credits }, each one segment or null (a scene after the
|
|
@@ -1646,11 +1705,11 @@ var Stremio = (function () {
|
|
|
1646
1705
|
function introDb(q) {
|
|
1647
1706
|
var url = 'https://api.introdb.app/segments?imdb_id=' + encodeURIComponent(q.imdb) +
|
|
1648
1707
|
(q.ep ? '&season=' + encodeURIComponent(q.ep.season) + '&episode=' + encodeURIComponent(q.ep.episode) : '&is_movie=true');
|
|
1649
|
-
return U.getJSON(url, 10000).then(function (r) {
|
|
1708
|
+
return U.getJSON(url, 10000, 0, null, null, null, true).then(function (r) {
|
|
1650
1709
|
if (!r || typeof r !== 'object') { return null; }
|
|
1651
1710
|
function one(x) { return segsOf(x ? [x] : []); }
|
|
1652
1711
|
return { intro: one(r.intro), recap: one(r.recap), credits: one(r.outro), preview: [] };
|
|
1653
|
-
},
|
|
1712
|
+
}, segMiss);
|
|
1654
1713
|
}
|
|
1655
1714
|
// GET https://api.aniskip.com/v2/skip-times/<MyAnimeList id>/<episode>?types[]=…&episodeLength=<s>
|
|
1656
1715
|
// -> { found, results: [{ interval: { startTime, endTime }, skipType, episodeLength }] }: the
|
|
@@ -1684,7 +1743,7 @@ var Stremio = (function () {
|
|
|
1684
1743
|
if (!mal) { return null; }
|
|
1685
1744
|
var len = durationMs > 0 ? Math.round(durationMs / 1000) : 0;
|
|
1686
1745
|
var url = 'https://api.aniskip.com/v2/skip-times/' + mal + '/' + ep + '?types[]=op&types[]=ed&types[]=recap&types[]=mixed-op&types[]=mixed-ed&episodeLength=' + len;
|
|
1687
|
-
return U.getJSON(url, 10000).then(function (r) {
|
|
1746
|
+
return U.getJSON(url, 10000, 0, null, null, null, true).then(function (r) {
|
|
1688
1747
|
if (!r || typeof r !== 'object') { return null; }
|
|
1689
1748
|
var list = U.listOf(r.results, 50, function (v) { return v.interval && typeof v.interval.startTime === 'number' && typeof v.interval.endTime === 'number' && v.interval.endTime > v.interval.startTime; });
|
|
1690
1749
|
function best(types) {
|
|
@@ -1694,7 +1753,7 @@ var Stremio = (function () {
|
|
|
1694
1753
|
return [{ start: Math.max(0, c[0].interval.startTime), end: c[0].interval.endTime }];
|
|
1695
1754
|
}
|
|
1696
1755
|
return { intro: best(['op', 'mixed-op']), recap: best(['recap']), credits: best(['ed', 'mixed-ed']), preview: [], from: { intro: 'AniSkip', recap: 'AniSkip', credits: 'AniSkip' } };
|
|
1697
|
-
},
|
|
1756
|
+
}, segMiss);
|
|
1698
1757
|
});
|
|
1699
1758
|
}
|
|
1700
1759
|
var SEG_SOURCES = [['TheIntroDB', theIntroDb], ['SkipDB', skipDb], ['IntroDB', introDb]];
|
|
@@ -1711,9 +1770,10 @@ var Stremio = (function () {
|
|
|
1711
1770
|
// reached), from the IMDb-based sources by the show's IMDb id, season and episode.
|
|
1712
1771
|
function animeSegments(type, a, durationMs, asked, hints) {
|
|
1713
1772
|
return animeIds(a, hints).then(function (ids) {
|
|
1714
|
-
return aniSkip(ids.mal, a.ep, durationMs).then(function (
|
|
1773
|
+
return aniSkip(ids.mal, a.ep, durationMs).then(function (got) {
|
|
1774
|
+
var r = got && got._why ? null : got; // (it gave nothing: why, in its line)
|
|
1715
1775
|
var has = r ? SEG_KINDS.filter(function (k) { return r[k].length; }) : [];
|
|
1716
|
-
if (asked) { asked.push('AniSkip: ' + (
|
|
1776
|
+
if (asked) { asked.push('AniSkip: ' + segWhy(got, has)); }
|
|
1717
1777
|
var out = has.length ? r : null;
|
|
1718
1778
|
if (!ids.imdb || has.length === SEG_KINDS.length - 1) { return out; } // (all AniSkip has: intro, recap, credits)
|
|
1719
1779
|
var q = { imdb: ids.imdb, ep: (type === 'movie' || ids.movie) ? null : { season: ids.season, episode: a.ep } };
|
|
@@ -1729,9 +1789,10 @@ var Stremio = (function () {
|
|
|
1729
1789
|
var missing = SEG_KINDS.filter(function (k) { return !(out && out[k] && out[k].length); });
|
|
1730
1790
|
if (!missing.length || i >= SEG_SOURCES.length) { return Promise.resolve(out); }
|
|
1731
1791
|
var name = SEG_SOURCES[i][0];
|
|
1732
|
-
return SEG_SOURCES[i][1](q, durationMs).then(function (
|
|
1792
|
+
return SEG_SOURCES[i][1](q, durationMs).then(function (got) {
|
|
1793
|
+
var more = got && got._why ? null : got; // (it gave nothing: why, in its line)
|
|
1733
1794
|
var has = more ? SEG_KINDS.filter(function (k) { return more[k].length; }) : [];
|
|
1734
|
-
if (asked) { asked.push((i === 0 && note ? note : '') + name + ': ' + (
|
|
1795
|
+
if (asked) { asked.push((i === 0 && note ? note : '') + name + ': ' + segWhy(got, has)); }
|
|
1735
1796
|
// (TheIntroDB knowing the title, even with nothing for it: an answer; from the
|
|
1736
1797
|
// others, only the segments they have)
|
|
1737
1798
|
if (more && (i === 0 || has.length)) {
|
|
@@ -1798,7 +1859,7 @@ var Stremio = (function () {
|
|
|
1798
1859
|
return getSearchCatalogs().then(function (cats) {
|
|
1799
1860
|
var out = [], local = {};
|
|
1800
1861
|
cats.forEach(function (c) {
|
|
1801
|
-
if (c.addon && c.addon.__impl) { // StremioK's own YouTube: "YouTube · Videos"
|
|
1862
|
+
if (c.addon && c.addon.__impl) { // StremioK's own YouTube and Xtream: "YouTube · Videos"
|
|
1802
1863
|
var nm = prettyType(c.type) + ' · ' + ((c.def && c.def.name) || c.id);
|
|
1803
1864
|
out.push({ key: catalogKey(c), cats: [c], title: nm, name: nm.replace(/ · /g, ' · '), pages: true });
|
|
1804
1865
|
return;
|
|
@@ -1836,8 +1897,105 @@ var Stremio = (function () {
|
|
|
1836
1897
|
return s;
|
|
1837
1898
|
}
|
|
1838
1899
|
|
|
1900
|
+
// ---- Streaming server (Settings › Content › Streaming server) ----
|
|
1901
|
+
// Stremio's streaming server or a TorrServer on your network. A torrent-only source (infoHash,
|
|
1902
|
+
// fileIdx) becomes a link on it (torrentSource), as Stremio's own apps make it; with Stremio's,
|
|
1903
|
+
// a source the TV refused can be converted by it (convertUrl: the player asks once).
|
|
1904
|
+
// { kind: '' (off) | 'stremio' | 'torrserver', url, convert }
|
|
1905
|
+
var SERVER_KEY = 'stremiok.server', SERVER_KINDS = { stremio: 1, torrserver: 1 }, TORRENT_WAITS = [45, 60, 120, 180, 300];
|
|
1906
|
+
function server() {
|
|
1907
|
+
var x = U.store.get(SERVER_KEY, {}) || {};
|
|
1908
|
+
return { kind: SERVER_KINDS[x.kind] ? x.kind : '', url: typeof x.url === 'string' ? x.url : '', convert: x.convert === true, // (convert: off unless chosen, see convertUrl)
|
|
1909
|
+
wait: TORRENT_WAITS.indexOf(x.wait) !== -1 ? x.wait : 120 }; // (seconds a torrent has to start, see the player's startCheck)
|
|
1910
|
+
}
|
|
1911
|
+
// An address as typed ("192.168.0.10:11470/"): http:// unless given, no trailing slash.
|
|
1912
|
+
function serverAddress(v) {
|
|
1913
|
+
v = ('' + (v || '')).trim().replace(/\/+$/, '');
|
|
1914
|
+
if (v && !/^[a-z][a-z0-9+.-]*:\/\//i.test(v)) { v = 'http://' + v; }
|
|
1915
|
+
return v;
|
|
1916
|
+
}
|
|
1917
|
+
function serverAddressProblem(v) { return U.urlProblem(serverAddress(v)) || null; }
|
|
1918
|
+
// Returns null, or what's wrong with the address (nothing changed then). The sources found
|
|
1919
|
+
// so far are asked for again (their links change).
|
|
1920
|
+
function setServer(cfg) {
|
|
1921
|
+
var cur = server(), kind = SERVER_KINDS[cfg.kind] ? cfg.kind : '';
|
|
1922
|
+
var url = cfg.url !== undefined ? serverAddress(cfg.url) : cur.url;
|
|
1923
|
+
if (kind && U.urlProblem(url)) { return U.urlProblem(url); }
|
|
1924
|
+
U.store.set(SERVER_KEY, { kind: kind, url: url, convert: cfg.convert !== undefined ? cfg.convert === true : cur.convert,
|
|
1925
|
+
wait: TORRENT_WAITS.indexOf(cfg.wait) !== -1 ? cfg.wait : cur.wait });
|
|
1926
|
+
var kept = _loaded; configChanged(); _loaded = kept;
|
|
1927
|
+
return null;
|
|
1928
|
+
}
|
|
1929
|
+
// Does it answer? { ok, text } — Stremio's /settings (its version in it), TorrServer's /echo.
|
|
1930
|
+
function testServer() {
|
|
1931
|
+
var sv = server();
|
|
1932
|
+
if (!sv.kind || !sv.url) { return Promise.resolve({ ok: false, text: 'No server set' }); }
|
|
1933
|
+
var p = sv.kind === 'stremio'
|
|
1934
|
+
? U.getJSON(sv.url + '/settings', 8000).then(function (r) {
|
|
1935
|
+
if (!r || typeof r !== 'object') { throw new Error('Not a Stremio streaming server'); }
|
|
1936
|
+
var v = r.values && r.values.serverVersion;
|
|
1937
|
+
return 'Stremio server answers' + (v ? ' (' + ('' + v).slice(0, 20) + ')' : '');
|
|
1938
|
+
})
|
|
1939
|
+
: U.getText(sv.url + '/echo', 8000).then(function (t) { return 'TorrServer answers (' + ('' + t).trim().slice(0, 30) + ')'; });
|
|
1940
|
+
return p.then(function (text) { return { ok: true, text: text }; },
|
|
1941
|
+
function (e) { return { ok: false, text: 'The server didn’t answer: ' + U.problem(e) }; });
|
|
1942
|
+
}
|
|
1943
|
+
// Made again each time it's asked (a page kept from before, just before playing): from the
|
|
1944
|
+
// server set now, or no link when there's none.
|
|
1945
|
+
var HASH = /^[0-9a-f]{40}$/i;
|
|
1946
|
+
function torrentSource(s) {
|
|
1947
|
+
var sv = server();
|
|
1948
|
+
if (s && s._torrent) { delete s.url; delete s._torrent; delete s._pickFile; }
|
|
1949
|
+
if (!s || s.url || !sv.kind || !sv.url || typeof s.infoHash !== 'string' || !HASH.test(s.infoHash)) { return s; }
|
|
1950
|
+
var h = s.infoHash.toLowerCase(), idx = /^\d{1,6}$/.test('' + s.fileIdx) ? +s.fileIdx : -1;
|
|
1951
|
+
var src = (Array.isArray(s.sources) ? s.sources : []).filter(function (x) { return typeof x === 'string' && /^(tracker|dht):/.test(x); }).slice(0, 20);
|
|
1952
|
+
if (sv.kind === 'stremio') { // (-1: the server takes the torrent's largest file)
|
|
1953
|
+
s.url = sv.url + '/' + h + '/' + idx + (src.length ? '?' + src.map(function (x) { return 'tr=' + encodeURIComponent(x); }).join('&') : '');
|
|
1954
|
+
} else { // (TorrServer: files counted from 1, its trackers in a magnet; without a file, torrentFile)
|
|
1955
|
+
var tr = src.filter(function (x) { return x.indexOf('tracker:') === 0; }).map(function (x) { return '&tr=' + encodeURIComponent(x.slice(8)); });
|
|
1956
|
+
s.url = sv.url + '/stream/play?link=' + encodeURIComponent(tr.length ? 'magnet:?xt=urn:btih:' + h + tr.join('') : h) + (idx >= 0 ? '&index=' + (idx + 1) : '') + '&play';
|
|
1957
|
+
if (idx < 0) { s._pickFile = true; }
|
|
1958
|
+
}
|
|
1959
|
+
s._torrent = true;
|
|
1960
|
+
return s;
|
|
1961
|
+
}
|
|
1962
|
+
// TorrServer, a torrent that doesn't say which of its files (_pickFile): its file list (&stat,
|
|
1963
|
+
// once it has the torrent's details), then the episode's file (S01E02, 1x02), a film's largest
|
|
1964
|
+
// video. Its link with that file; as it was when the list doesn't come (one file plays anyway);
|
|
1965
|
+
// null when the episode isn't in it (another episode isn't played in its place).
|
|
1966
|
+
var VIDEO_FILE = /\.(mkv|mp4|m4v|avi|mov|wmv|ts|m2ts|webm|mpe?g|flv)$/i;
|
|
1967
|
+
function torrentFile(st, season, episode, cancel) {
|
|
1968
|
+
var sv = server(), m = /[?&]link=([^&]+)/.exec(st.url || '');
|
|
1969
|
+
if (sv.kind !== 'torrserver' || !m) { return Promise.resolve(st.url); }
|
|
1970
|
+
return U.getJSON(sv.url + '/stream/?link=' + m[1] + '&stat', 60000, undefined, cancel).then(function (r) {
|
|
1971
|
+
var files = U.listOf(r && r.file_stats, 5000).filter(function (f) { return f && typeof f.id === 'number' && VIDEO_FILE.test('' + f.path); });
|
|
1972
|
+
var pick = null, ep = (season && episode) ? new RegExp('(^|[^0-9a-z])(s0*' + season + '[ ._-]*e0*' + episode + '|0*' + season + 'x0*' + episode + ')([^0-9]|$)', 'i') : null;
|
|
1973
|
+
if (ep) {
|
|
1974
|
+
pick = files.filter(function (f) { return ep.test(f.path); })[0] || null;
|
|
1975
|
+
if (!pick && files.length) { return null; }
|
|
1976
|
+
}
|
|
1977
|
+
if (!pick) { files.forEach(function (f) { if (!pick || (+f.length || 0) > (+pick.length || 0)) { pick = f; } }); }
|
|
1978
|
+
return pick ? st.url.replace(/&play$/, '&index=' + pick.id + '&play') : st.url;
|
|
1979
|
+
}, function (e) { U.log('sources', 'The streaming server didn’t list the torrent’s files: ' + U.problem(e)); return st.url; });
|
|
1980
|
+
}
|
|
1981
|
+
// The server's HLS of a link, for what the TV plays (H.264 / HEVC video; AAC, AC-3, E-AC-3,
|
|
1982
|
+
// MP3 audio, 6 channels): the rest it converts. Null when there's no converting to ask for.
|
|
1983
|
+
// Off unless chosen: what it sends (fragmented-MP4 HLS, version 7) the 2017 TV's player
|
|
1984
|
+
// doesn't open (Stremio's own Tizen app doesn't convert either).
|
|
1985
|
+
var CONVERT_VIDEO = ['h264', 'hevc'], CONVERT_AUDIO = ['aac', 'ac3', 'eac3', 'mp3'];
|
|
1986
|
+
function convertUrl(url) {
|
|
1987
|
+
var sv = server();
|
|
1988
|
+
if (sv.kind !== 'stremio' || !sv.convert || !sv.url || !/^https?:\/\//i.test(url || '') || url.indexOf(sv.url + '/hlsv2/') === 0) { return null; }
|
|
1989
|
+
var id = '';
|
|
1990
|
+
while (id.length < 16) { id += Math.floor(Math.random() * 16).toString(16); }
|
|
1991
|
+
return sv.url + '/hlsv2/' + id + '/master.m3u8?mediaURL=' + encodeURIComponent(url) +
|
|
1992
|
+
CONVERT_VIDEO.map(function (c) { return '&videoCodecs=' + c; }).join('') +
|
|
1993
|
+
CONVERT_AUDIO.map(function (c) { return '&audioCodecs=' + c; }).join('') + '&maxAudioChannels=6';
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1839
1996
|
// A stream is directly playable on the TV only if it exposes an http(s) URL.
|
|
1840
|
-
// Torrent (infoHash) / external-only streams need an engine this app doesn't embed
|
|
1997
|
+
// Torrent (infoHash) / external-only streams need an engine this app doesn't embed (or a
|
|
1998
|
+
// streaming server: torrentSource gives them one).
|
|
1841
1999
|
function isPlayable(stream) {
|
|
1842
2000
|
if (typeof LocalMedia !== 'undefined' && LocalMedia.isLocalStream(stream)) { return true; } // (a file on a USB drive: only one StremioK made)
|
|
1843
2001
|
return !!(stream && typeof stream.url === 'string' && /^https?:\/\//i.test(stream.url));
|
|
@@ -1904,12 +2062,21 @@ var Stremio = (function () {
|
|
|
1904
2062
|
if (!m) { return 0; }
|
|
1905
2063
|
return parseFloat(m[1].replace(',', '.')) * ({ TB: 1099511627776, GB: 1073741824, MB: 1048576 })[m[2].toUpperCase()];
|
|
1906
2064
|
}
|
|
2065
|
+
// The seeders a torrent source states: Torrentio's and MediaFusion's 👤 123, or "Seeders: 123".
|
|
2066
|
+
// -1: none stated.
|
|
2067
|
+
var SEEDS = /(?:\uD83D\uDC64|\uD83D\uDC65)\s*(\d[\d,.]*)|\bseed(?:er)?s?\s*[:=]\s*(\d[\d,.]*)/i;
|
|
2068
|
+
function seedersOf(t) {
|
|
2069
|
+
var m = SEEDS.exec(t);
|
|
2070
|
+
if (!m) { return -1; }
|
|
2071
|
+
var n = parseInt((m[1] || m[2]).replace(/[,.]/g, ''), 10);
|
|
2072
|
+
return isFinite(n) ? n : -1;
|
|
2073
|
+
}
|
|
1907
2074
|
function streamInfo(stream) {
|
|
1908
2075
|
var bh = stream.behaviorHints || {};
|
|
1909
2076
|
var path = '';
|
|
1910
2077
|
try { path = decodeURIComponent(('' + (stream.url || '')).split('?')[0]); } catch (e) { path = '' + (stream.url || ''); }
|
|
1911
2078
|
var t = [stream.name, stream.title, stream.description, bh.filename, path.split('/').pop()].join(' \n ');
|
|
1912
|
-
var i = { res: 0, codec: '', bits10: RX.bits10.test(t), hdr: '', audio: [], kind: '', cache: 0, container: '', size: sizeBytes(stream) };
|
|
2079
|
+
var i = { res: 0, codec: '', bits10: RX.bits10.test(t), hdr: '', audio: [], kind: '', cache: 0, container: '', size: sizeBytes(stream), seeds: seedersOf(t) };
|
|
1913
2080
|
i.res = RX.r2160.test(t) ? 2160 : RX.r1440.test(t) ? 1440 : RX.r1080.test(t) ? 1080 : RX.r720.test(t) ? 720 : RX.r480.test(t) ? 480 : 0;
|
|
1914
2081
|
var dv = RX.dv.test(t), hdr = RX.hdr.test(t), hdr10p = RX.hdr10p.test(t);
|
|
1915
2082
|
i.hdr = dv ? ((hdr || hdr10p) ? 'dv' : 'dv-only') : hdr10p ? 'hdr10p' : hdr ? 'hdr' : '';
|
|
@@ -2098,7 +2265,8 @@ var Stremio = (function () {
|
|
|
2098
2265
|
moveSearchFeed: function (key, dir) { return searchFeeds.move(key, dir); },
|
|
2099
2266
|
toggleSearchFeed: function (key) { searchFeeds.toggle(key); },
|
|
2100
2267
|
isSearchFeedHidden: function (key) { return searchFeeds.isHidden(key); },
|
|
2101
|
-
isPlayable: isPlayable, youTubeSource: youTubeSource,
|
|
2268
|
+
isPlayable: isPlayable, youTubeSource: youTubeSource, torrentSource: torrentSource,
|
|
2269
|
+
keptSources: keptSources, torrentFile: torrentFile, server: server, setServer: setServer, testServer: testServer, convertUrl: convertUrl, serverAddressProblem: serverAddressProblem, streamLabel: streamLabel, streamName: streamName,
|
|
2102
2270
|
streamSize: streamSize, streamDescription: streamDescription,
|
|
2103
2271
|
streamInfo: streamInfo, formatTags: formatTags, formatKeys: formatKeys, recordFormats: recordFormats, setFormat: setFormat,
|
|
2104
2272
|
resetFormats: resetFormats, badFormats: badFormats, formatList: formatList,
|
|
@@ -2106,7 +2274,7 @@ var Stremio = (function () {
|
|
|
2106
2274
|
importSetupList: importSetupList, savedManifest: savedManifest, isAddonOff: isAddonOff, setAddonOff: setAddonOff, onIptvReady: onIptvReady, streamListenerCount: function (type, id) { var e = _streamCache[type + ':' + id]; return e ? e.listeners.length : 0; },
|
|
2107
2275
|
iptvGetPlaylists: iptvGetPlaylists, iptvAddPlaylist: iptvAddPlaylist,
|
|
2108
2276
|
iptvUpdatePlaylist: iptvUpdatePlaylist, iptvRemovePlaylist: iptvRemovePlaylist,
|
|
2109
|
-
iptvRenamePlaylist: iptvRenamePlaylist, iptvSetPlaylistGuide: iptvSetPlaylistGuide, iptvAddXtream: iptvAddXtream, iptvSetXtreamFormat: iptvSetXtreamFormat, iptvSetPlaylistOff: iptvSetPlaylistOff, iptvMovePlaylist: iptvMovePlaylist, iptvLabel: iptvLabel,
|
|
2277
|
+
iptvRenamePlaylist: iptvRenamePlaylist, iptvSetPlaylistGuide: iptvSetPlaylistGuide, iptvAddXtream: iptvAddXtream, iptvAddStalker: iptvAddStalker, iptvSetXtreamFormat: iptvSetXtreamFormat, iptvRefreshEvery: iptvRefreshEvery, iptvSetRefreshEvery: iptvSetRefreshEvery, iptvReadAt: iptvReadAt, iptvSetPlaylistOff: iptvSetPlaylistOff, iptvMovePlaylist: iptvMovePlaylist, iptvLabel: iptvLabel,
|
|
2110
2278
|
iptvLoad: iptvLoad, iptvStatus: iptvStatus, iptvReload: iptvReload
|
|
2111
2279
|
};
|
|
2112
2280
|
})();
|