stremiok 2.3.3 → 2.3.4
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 +10 -0
- package/README.md +5 -5
- package/config.xml +1 -1
- package/index.html +40 -39
- package/js/app.js +4 -0
- package/js/jellyfin.js +43 -10
- package/js/player-core.js +1 -0
- package/js/player-store.js +12 -5
- package/js/plex.js +58 -10
- package/js/stremio-account.js +11 -6
- package/js/stremio-sync.js +641 -0
- package/js/stremio.js +1 -0
- package/js/util.js +1 -1
- package/js/view-core.js +19 -2
- package/js/view-detail.js +11 -0
- package/js/view-home.js +24 -2
- package/js/view-settings.js +101 -25
- package/package.json +1 -1
- package/tizenbrew.html +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
What changed in each version of StremioK, newest first. How everything works is in the
|
|
4
4
|
[user guide](docs/USER-GUIDE.md).
|
|
5
5
|
|
|
6
|
+
## 2.3.4 — 2026-11-09
|
|
7
|
+
- **Your Stremio account, kept in step** (Settings › Content › Integrations › *Stremio account*):
|
|
8
|
+
Continue Watching, watched marks and your Library sync with it, both ways; the latest change to
|
|
9
|
+
a title wins. Your Library is a *Stremio Library* row; *+ Stremio Library* on a title page adds
|
|
10
|
+
to it.
|
|
11
|
+
- **Importing addons** uses the connected account, without signing in again.
|
|
12
|
+
- **Large media server libraries:** Jellyfin, Emby and Plex lists of titles are read 2,000 at a
|
|
13
|
+
time, so a big library's copies show on title pages; one too big or slow is searched by name
|
|
14
|
+
(the same IMDb or TMDB id), now on Plex too.
|
|
15
|
+
|
|
6
16
|
## 2.3.3 — 2026-11-08
|
|
7
17
|
- **After a lot of debugging & troubleshooting: TizenBrew has no TV player** (#17): the TV gives
|
|
8
18
|
its own player only to installed apps, so under TizenBrew a file with several audio tracks only
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ video through Samsung's AVPlay API.
|
|
|
22
22
|
|
|
23
23
|
- **Your addons:** catalogs, details, sources and subtitles from the Stremio addons you add
|
|
24
24
|
(Cinemeta and OpenSubtitles to start with), in the order you choose.
|
|
25
|
-
- **Home** with Watching (Continue Watching, synced with **Trakt** if you connect
|
|
25
|
+
- **Home** with Watching (Continue Watching, synced with **Trakt** or **Stremio** if you connect them), Movies,
|
|
26
26
|
Series, IPTV, Guide, Radio, Sports, YouTube and Local tabs; **Discover** to browse any catalog in full;
|
|
27
27
|
**Search** across every addon that can search, and people by name.
|
|
28
28
|
- **Title pages:** ranked sources with **▶ Play best**, trailers, ratings (IMDb, Rotten
|
|
@@ -61,7 +61,7 @@ Three ways, all covered step by step in the **[installation guide](docs/INSTALL.
|
|
|
61
61
|
titles playable.
|
|
62
62
|
2. **API keys**, optional: your own TMDB, OMDb and MDBList keys add ratings, *Cast & more*,
|
|
63
63
|
*where to watch* and episode trailers.
|
|
64
|
-
3. **Trakt**, optional: connect
|
|
64
|
+
3. **Trakt** or **Stremio**, optional: connect to share watched marks and Continue Watching.
|
|
65
65
|
4. **IPTV**, optional: your M3U playlist links, an Xtream account (its server, username and
|
|
66
66
|
password) or a Stalker portal (its address and MAC address).
|
|
67
67
|
5. **A USB drive or network folder**, optional: plug a drive in, or add a WebDAV folder; the
|
|
@@ -99,7 +99,7 @@ responsibility.
|
|
|
99
99
|
- Under TizenBrew there's no TV player (only the `.wgt` has it): one audio track per file, no
|
|
100
100
|
built-in subtitle tracks, no PlayReady or Widevine channels; opening apps depends on TizenBrew.
|
|
101
101
|
- No StremioK account and no profiles: settings, addons and progress stay on the TV. The
|
|
102
|
-
only
|
|
102
|
+
only syncs are optional: Trakt and your Stremio account.
|
|
103
103
|
- Subtitles use an HTML overlay; gzipped (`.gz`) subtitle files aren't decoded.
|
|
104
104
|
- No playback speed control (the TV's player mutes audio at other speeds), and no
|
|
105
105
|
HDR / frame-rate mode switching (not available to web apps on Tizen 3).
|
|
@@ -125,5 +125,5 @@ the [ODbL 1.0](https://opendatacommons.org/licenses/odbl/1-0/) (see its
|
|
|
125
125
|
reads it through SkipDB's public API and keeps none of it.
|
|
126
126
|
|
|
127
127
|
`js/qrcode.js` is [qrcode-generator](https://github.com/kazuhikoarase/qrcode-generator) by
|
|
128
|
-
Kazuhiko Arase (MIT), unchanged; it draws the TV's QR codes (
|
|
129
|
-
|
|
128
|
+
Kazuhiko Arase (MIT), unchanged; it draws the TV's QR codes (sign-ins, entering text from your
|
|
129
|
+
phone, Continue on phone, an addon's Share and Configure).
|
package/config.xml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets"
|
|
3
|
-
id="http://stremiok.tizen/StremioKTizen" version="2.3.
|
|
3
|
+
id="http://stremiok.tizen/StremioKTizen" version="2.3.4" viewmodes="maximized">
|
|
4
4
|
<tizen:application id="StremioK01.StremioK" package="StremioK01" required_version="3.0"/>
|
|
5
5
|
<content src="index.html"/>
|
|
6
6
|
<feature name="http://tizen.org/feature/screen.size.all"/>
|
package/index.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=1920, height=1080, user-scalable=no">
|
|
6
6
|
<title>StremioK</title>
|
|
7
|
-
<link rel="stylesheet" href="css/style.css?v=2.3.
|
|
8
|
-
<link rel="stylesheet" href="css/modern.css?v=2.3.
|
|
7
|
+
<link rel="stylesheet" href="css/style.css?v=2.3.4">
|
|
8
|
+
<link rel="stylesheet" href="css/modern.css?v=2.3.4">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<!-- CSS-applied sentinel (kept off-screen); app.js waits for its width before rendering -->
|
|
@@ -54,42 +54,43 @@
|
|
|
54
54
|
|
|
55
55
|
<!-- Load order matters: polyfills -> util -> iptv -> data -> input -> tvapps -> player parts -> player -> ytplay -> view parts -> views -> app -->
|
|
56
56
|
<!-- ?v= busts the TV webview cache on every release (keep in sync with package.json) -->
|
|
57
|
-
<script src="js/polyfills.js?v=2.3.
|
|
58
|
-
<script src="js/util.js?v=2.3.
|
|
59
|
-
<script src="js/iptv.js?v=2.3.
|
|
60
|
-
<script src="js/xtvod.js?v=2.3.
|
|
61
|
-
<script src="js/stvod.js?v=2.3.
|
|
62
|
-
<script src="js/jellyfin.js?v=2.3.
|
|
63
|
-
<script src="js/plex.js?v=2.3.
|
|
64
|
-
<script src="js/epg.js?v=2.3.
|
|
65
|
-
<script src="js/youtube.js?v=2.3.
|
|
66
|
-
<script src="js/stremio.js?v=2.3.
|
|
67
|
-
<script src="js/trakt.js?v=2.3.
|
|
68
|
-
<script src="js/keys.js?v=2.3.
|
|
69
|
-
<script src="js/focus.js?v=2.3.
|
|
70
|
-
<script src="js/tvapps.js?v=2.3.
|
|
71
|
-
<script src="js/player-core.js?v=2.3.
|
|
72
|
-
<script src="js/player-store.js?v=2.3.
|
|
73
|
-
<script src="js/player-lang.js?v=2.3.
|
|
74
|
-
<script src="js/player-quality.js?v=2.3.
|
|
75
|
-
<script src="js/player-subs.js?v=2.3.
|
|
76
|
-
<script src="js/player-audio.js?v=2.3.
|
|
77
|
-
<script src="js/player-controls.js?v=2.3.
|
|
78
|
-
<script src="js/player.js?v=2.3.
|
|
79
|
-
<script src="js/ytplay.js?v=2.3.
|
|
80
|
-
<script src="js/netfolders.js?v=2.3.
|
|
81
|
-
<script src="js/local.js?v=2.3.
|
|
82
|
-
<script src="js/downloads.js?v=2.3.
|
|
83
|
-
<script src="js/stremio-account.js?v=2.3.
|
|
84
|
-
<script src="js/
|
|
85
|
-
<script src="js/view-
|
|
86
|
-
<script src="js/view-
|
|
87
|
-
<script src="js/view-
|
|
88
|
-
<script src="js/view-
|
|
89
|
-
<script src="js/view-
|
|
90
|
-
<script src="js/view-
|
|
91
|
-
<script src="js/
|
|
92
|
-
<script src="js/
|
|
93
|
-
<script src="js/
|
|
57
|
+
<script src="js/polyfills.js?v=2.3.4"></script>
|
|
58
|
+
<script src="js/util.js?v=2.3.4"></script>
|
|
59
|
+
<script src="js/iptv.js?v=2.3.4"></script>
|
|
60
|
+
<script src="js/xtvod.js?v=2.3.4"></script>
|
|
61
|
+
<script src="js/stvod.js?v=2.3.4"></script>
|
|
62
|
+
<script src="js/jellyfin.js?v=2.3.4"></script>
|
|
63
|
+
<script src="js/plex.js?v=2.3.4"></script>
|
|
64
|
+
<script src="js/epg.js?v=2.3.4"></script>
|
|
65
|
+
<script src="js/youtube.js?v=2.3.4"></script>
|
|
66
|
+
<script src="js/stremio.js?v=2.3.4"></script>
|
|
67
|
+
<script src="js/trakt.js?v=2.3.4"></script>
|
|
68
|
+
<script src="js/keys.js?v=2.3.4"></script>
|
|
69
|
+
<script src="js/focus.js?v=2.3.4"></script>
|
|
70
|
+
<script src="js/tvapps.js?v=2.3.4"></script>
|
|
71
|
+
<script src="js/player-core.js?v=2.3.4"></script>
|
|
72
|
+
<script src="js/player-store.js?v=2.3.4"></script>
|
|
73
|
+
<script src="js/player-lang.js?v=2.3.4"></script>
|
|
74
|
+
<script src="js/player-quality.js?v=2.3.4"></script>
|
|
75
|
+
<script src="js/player-subs.js?v=2.3.4"></script>
|
|
76
|
+
<script src="js/player-audio.js?v=2.3.4"></script>
|
|
77
|
+
<script src="js/player-controls.js?v=2.3.4"></script>
|
|
78
|
+
<script src="js/player.js?v=2.3.4"></script>
|
|
79
|
+
<script src="js/ytplay.js?v=2.3.4"></script>
|
|
80
|
+
<script src="js/netfolders.js?v=2.3.4"></script>
|
|
81
|
+
<script src="js/local.js?v=2.3.4"></script>
|
|
82
|
+
<script src="js/downloads.js?v=2.3.4"></script>
|
|
83
|
+
<script src="js/stremio-account.js?v=2.3.4"></script>
|
|
84
|
+
<script src="js/stremio-sync.js?v=2.3.4"></script>
|
|
85
|
+
<script src="js/view-core.js?v=2.3.4"></script>
|
|
86
|
+
<script src="js/view-home.js?v=2.3.4"></script>
|
|
87
|
+
<script src="js/view-guide.js?v=2.3.4"></script>
|
|
88
|
+
<script src="js/view-detail.js?v=2.3.4"></script>
|
|
89
|
+
<script src="js/view-search.js?v=2.3.4"></script>
|
|
90
|
+
<script src="js/view-settings.js?v=2.3.4"></script>
|
|
91
|
+
<script src="js/view-discover.js?v=2.3.4"></script>
|
|
92
|
+
<script src="js/views.js?v=2.3.4"></script>
|
|
93
|
+
<script src="js/app.js?v=2.3.4"></script>
|
|
94
|
+
<script src="js/hubpreview.js?v=2.3.4"></script>
|
|
94
95
|
</body>
|
|
95
96
|
</html>
|
package/js/app.js
CHANGED
|
@@ -270,6 +270,10 @@ var App = (function () {
|
|
|
270
270
|
if (typeof Trakt !== 'undefined' && Trakt.isConnected()) {
|
|
271
271
|
Trakt.refreshCaches().then(function () { if (_current === 'home') { Views.renderHome(); } });
|
|
272
272
|
}
|
|
273
|
+
// ...and your Stremio account, both ways (js/stremio-sync.js).
|
|
274
|
+
if (typeof StremioSync !== 'undefined' && StremioSync.isConnected()) {
|
|
275
|
+
StremioSync.sync().then(function () { if (_current === 'home' && !Player.isActive()) { Views.renderHome(); } });
|
|
276
|
+
}
|
|
273
277
|
serverMarks();
|
|
274
278
|
}
|
|
275
279
|
// Your media servers' watched marks: read at launch, when a server is added, reloaded or
|
package/js/jellyfin.js
CHANGED
|
@@ -24,6 +24,7 @@ var Jellyfin = (function () {
|
|
|
24
24
|
|
|
25
25
|
var KEY = 'stremiok.jellyfin.servers', DEV_KEY = 'stremiok.jellyfin.device', LIBS_KEY = 'stremiok.jellyfin.libs';
|
|
26
26
|
var PAGE = 100, INDEX_FRESH_MS = 30 * 60000, INDEX_RETRY_MS = 60000, INDEX_SLOW_MS = 30 * 60000, LIBS_FRESH_MS = 86400000;
|
|
27
|
+
var INDEX_PAGE = 2000, INDEX_PAGES = 25; // (a server's list read 2,000 titles at a time, 50,000 at most: see pages)
|
|
27
28
|
var QC_EVERY = 3000, QC_FOR = 10 * 60000, REPORT_EVERY = 60000, TICKS = 10000000;
|
|
28
29
|
var _changeFns = [];
|
|
29
30
|
function onChange(fn) { _changeFns.push(fn); }
|
|
@@ -406,22 +407,54 @@ var Jellyfin = (function () {
|
|
|
406
407
|
// ---- Which titles each server has (for titles from your addons) ----
|
|
407
408
|
// type|tt… and type|tmdb:… -> its item ids; read when first asked, kept INDEX_FRESH_MS (the
|
|
408
409
|
// old list answers while a new one is read).
|
|
410
|
+
// A list is read a page at a time (page(start) -> a Promise of that page's items), INDEX_PAGE
|
|
411
|
+
// titles a page, each with the server's own wait, until a page comes short, INDEX_PAGES at
|
|
412
|
+
// most: { items, part } (part: not all of it: more than that, or a page after the first that
|
|
413
|
+
// didn't come, its error in part.e). The first page not coming: the whole read fails.
|
|
414
|
+
function pages(page) {
|
|
415
|
+
var items = [];
|
|
416
|
+
function next(n) {
|
|
417
|
+
return page(n * INDEX_PAGE).then(function (l) {
|
|
418
|
+
items = items.concat(l);
|
|
419
|
+
if (l.length < INDEX_PAGE) { return { items: items, part: null }; }
|
|
420
|
+
if (n + 1 >= INDEX_PAGES) { return { items: items, part: { more: true } }; }
|
|
421
|
+
return next(n + 1);
|
|
422
|
+
}, function (e) {
|
|
423
|
+
if (!n) { throw e; }
|
|
424
|
+
return { items: items, part: { e: e } };
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
return next(0);
|
|
428
|
+
}
|
|
409
429
|
var _index = {};
|
|
410
430
|
function index(srv) {
|
|
411
431
|
var x = _index[srv.id];
|
|
412
432
|
if (x && x.map && (x.p || Date.now() - x.at < INDEX_FRESH_MS)) { return Promise.resolve(x.map); }
|
|
413
433
|
if (x && x.p) { return x.p; }
|
|
414
|
-
var p =
|
|
434
|
+
var p = pages(function (start) {
|
|
435
|
+
return get(srv, K(srv).items(uid(srv)) + 'recursive=true&includeItemTypes=Movie,Series&fields=ProviderIds&enableImages=false&enableUserData=true&enableTotalRecordCount=false' +
|
|
436
|
+
'&sortBy=SortName&sortOrder=Ascending&startIndex=' + start + '&limit=' + INDEX_PAGE, 8 * 1048576).then(function (r) { return U.listOf(r && r.Items, INDEX_PAGE); });
|
|
437
|
+
}).then(function (got) {
|
|
415
438
|
var map = { __ids: {}, __tm: {}, __played: [] }; // (__ids, __tm: an item's IMDb, TMDB id, for Next up's cards and watched marks; __played: its played films and shows)
|
|
416
439
|
function add(k, v) { (map[k] = map[k] || []).push(v); }
|
|
417
|
-
|
|
440
|
+
got.items.forEach(function (it) {
|
|
418
441
|
var t = it.Type === 'Movie' ? 'movie' : it.Type === 'Series' ? 'series' : '', tt = imdbOf(it), tm = tmdbOf(it);
|
|
419
442
|
if (!t || !it.Id) { return; }
|
|
420
443
|
if (tt) { add(t + '|' + tt, '' + it.Id); map.__ids['' + it.Id] = tt; }
|
|
421
444
|
if (tm) { add(t + '|tmdb:' + tm, '' + it.Id); map.__tm['' + it.Id] = tm; }
|
|
422
445
|
if (it.UserData && it.UserData.Played) { map.__played.push({ t: t, ids: titleIds(map, (t === 'movie' ? 'jfm.' : 'jfs.') + srv.id + '.', '' + it.Id), at: Date.parse(it.UserData.LastPlayedDate || '') || 1 }); }
|
|
423
446
|
});
|
|
424
|
-
|
|
447
|
+
// Not all of it (__part): titles looked up by name too (idsFor). A page that didn't come:
|
|
448
|
+
// the list read again as a failed one would be (in a minute; timed out: in 30).
|
|
449
|
+
var at = Date.now();
|
|
450
|
+
if (got.part) {
|
|
451
|
+
map.__part = true;
|
|
452
|
+
if (got.part.e) {
|
|
453
|
+
U.log('jellyfin', '“' + srv.name + '” (' + kindName(srv) + '): only ' + got.items.length + ' of its titles read (' + U.problem(got.part.e) + ')');
|
|
454
|
+
at -= INDEX_FRESH_MS - (/Timed out/i.test(got.part.e.message || '') ? INDEX_SLOW_MS : INDEX_RETRY_MS);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (_index[srv.id] && _index[srv.id].p === p) { _index[srv.id] = { at: at, map: map }; }
|
|
425
458
|
return map;
|
|
426
459
|
}, function (e) {
|
|
427
460
|
U.log('jellyfin', '“' + srv.name + '” (' + kindName(srv) + '): its titles couldn’t be read (' + U.problem(e) + ')');
|
|
@@ -444,9 +477,9 @@ var Jellyfin = (function () {
|
|
|
444
477
|
if (map.__tm && map.__tm[id]) { l.push('tmdb:' + map.__tm[id]); }
|
|
445
478
|
return l;
|
|
446
479
|
}
|
|
447
|
-
// A title the server's list can't give (never read: too big or slow
|
|
448
|
-
// presenting a whole catalog is): searched for by its name, taken only when its IMDb or
|
|
449
|
-
// is the one asked for. Kept FOUND_MS (a failed search: asked again next time).
|
|
480
|
+
// A title the server's list can't give (never read, or not all of it: too big or slow, as a
|
|
481
|
+
// server presenting a whole catalog is): searched for by its name, taken only when its IMDb or
|
|
482
|
+
// TMDB id is the one asked for. Kept FOUND_MS (a failed search: asked again next time).
|
|
450
483
|
var FOUND_MS = 30 * 60000, _found = U.lru(300);
|
|
451
484
|
function lookup(srv, type, key, name) {
|
|
452
485
|
name = ('' + (name || '')).replace(/\s+/g, ' ').trim().slice(0, 100);
|
|
@@ -464,12 +497,12 @@ var Jellyfin = (function () {
|
|
|
464
497
|
_found.set(k, { at: Date.now(), p: p });
|
|
465
498
|
return p;
|
|
466
499
|
}
|
|
467
|
-
// The server's items for a title: from its list, as before; with no list yet,
|
|
468
|
-
//
|
|
500
|
+
// The server's items for a title: from its list, as before; with no list yet, none to be had or
|
|
501
|
+
// not all of it, looked up by name meanwhile (lookup), the list's answer used when that finds none.
|
|
469
502
|
function idsFor(srv, type, key, name) {
|
|
470
503
|
var x = _index[srv.id];
|
|
471
504
|
var fromList = index(srv).then(function (map) { return map[type + '|' + key] || []; });
|
|
472
|
-
if (x && x.map && !x.map.__err) { return fromList; }
|
|
505
|
+
if (x && x.map && !x.map.__err && !x.map.__part) { return fromList; }
|
|
473
506
|
return lookup(srv, type, key, name).then(function (ids) { return ids.length ? ids : fromList; });
|
|
474
507
|
}
|
|
475
508
|
// A film or episode listed without its files (a server presenting remote ones gives them only
|
|
@@ -873,6 +906,6 @@ var Jellyfin = (function () {
|
|
|
873
906
|
signIn: signIn, quickConnect: quickConnect, remove: remove, reload: reload, libraries: libsOf, synthAddon: synthAddon, synthAddons: synthAddons, kindsOn: kindsOn,
|
|
874
907
|
kindName: kindName, nameOfId: nameOfId, catalog: catalog, meta: meta, streams: streams, isJellyfinId: isJellyfinId, onPlayer: onPlayer, resumeFor: resumeFor,
|
|
875
908
|
segments: segments, trickplayAt: trickplayAt, waitMs: waitMs, sourceKind: sourceKind, refreshMarks: refreshMarks, watchedAt: watchedAt,
|
|
876
|
-
shared: { chapterSegments: chapterSegments, namedChapters: namedChapters, marksFrom: marksFrom } // (Plex's chapters
|
|
909
|
+
shared: { chapterSegments: chapterSegments, namedChapters: namedChapters, marksFrom: marksFrom, pages: pages, INDEX_PAGE: INDEX_PAGE } // (Plex's chapters, watched marks and lists read the same way)
|
|
877
910
|
};
|
|
878
911
|
})();
|
package/js/player-core.js
CHANGED
|
@@ -186,6 +186,7 @@ var PlayerParts = {};
|
|
|
186
186
|
added: added || undefined };
|
|
187
187
|
}
|
|
188
188
|
writeProgress(all);
|
|
189
|
+
if (typeof StremioSync !== 'undefined' && StremioSync.onProgress) { StremioSync.onProgress(S.ctx, S.cur, S.dur, !fromTicker); } // (your Stremio account's place)
|
|
189
190
|
}
|
|
190
191
|
// What's saved to resume: a converted playback's own link (not the server's conversion), and a
|
|
191
192
|
// torrent's infoHash, file and trackers (its link depends on the server set when it resumes).
|
package/js/player-store.js
CHANGED
|
@@ -11,14 +11,16 @@
|
|
|
11
11
|
var WATCHED_KEY = 'stremiok.watched';
|
|
12
12
|
function watchedAll() { return U.store.get(WATCHED_KEY, {}) || {}; }
|
|
13
13
|
// A mark made here: watched at (ms, > 0), or not watched at (−ms; false: an older "not
|
|
14
|
-
// watched", at 0). Trakt's history (when connected)
|
|
15
|
-
// against it by time: marked watched here: watched; marked not
|
|
16
|
-
//
|
|
14
|
+
// watched", at 0). Trakt's history (when connected), your Stremio account's and your media
|
|
15
|
+
// servers' marks are weighed against it by time: marked watched here: watched; marked not
|
|
16
|
+
// watched here: watched only if one of them has it watched since (on another device); no mark
|
|
17
|
+
// here: as they have it.
|
|
17
18
|
// null: none knows it.
|
|
18
19
|
function traktAt(type, id) {
|
|
19
20
|
var t = (typeof Trakt !== 'undefined' && Trakt.isConnected && Trakt.isConnected() && Trakt.watchedAt) ? Trakt.watchedAt(type, id) : 0;
|
|
20
21
|
var s = (typeof Jellyfin !== 'undefined' && Jellyfin.watchedAt) ? Jellyfin.watchedAt(type, id) : 0; // (Jellyfin, Emby and Plex: js/jellyfin.js)
|
|
21
|
-
|
|
22
|
+
var a = (typeof StremioSync !== 'undefined' && StremioSync.watchedAt) ? StremioSync.watchedAt(type, id) : 0; // (your Stremio account)
|
|
23
|
+
return Math.max(t || 0, s || 0, a || 0);
|
|
22
24
|
}
|
|
23
25
|
function watchedState(type, id) {
|
|
24
26
|
var v = watchedAll()[type + ':' + id], t = traktAt(type, id);
|
|
@@ -43,12 +45,14 @@
|
|
|
43
45
|
});
|
|
44
46
|
return out;
|
|
45
47
|
}
|
|
46
|
-
// quiet: Trakt not told (it's been told another way: a finished scrobble)
|
|
48
|
+
// quiet: Trakt not told (it's been told another way: a finished scrobble); your Stremio
|
|
49
|
+
// account always is
|
|
47
50
|
function setWatched(type, id, on, quiet) {
|
|
48
51
|
var a = watchedAll();
|
|
49
52
|
a[type + ':' + id] = on ? Date.now() : -Date.now();
|
|
50
53
|
U.store.set(WATCHED_KEY, a);
|
|
51
54
|
if (!quiet) { tellTrakt(type, [id], on); }
|
|
55
|
+
tellStremio(type, [id], on);
|
|
52
56
|
}
|
|
53
57
|
function setWatchedMany(type, ids, on) {
|
|
54
58
|
var a = watchedAll();
|
|
@@ -56,7 +60,9 @@
|
|
|
56
60
|
ids.forEach(function (id) { a[type + ':' + id] = value; });
|
|
57
61
|
U.store.set(WATCHED_KEY, a);
|
|
58
62
|
tellTrakt(type, ids, on);
|
|
63
|
+
tellStremio(type, ids, on);
|
|
59
64
|
}
|
|
65
|
+
function tellStremio(type, ids, on) { if (typeof StremioSync !== 'undefined' && StremioSync.onMarked) { StremioSync.onMarked(type, ids, !!on); } }
|
|
60
66
|
// A "not watched" Trakt has confirmed (and its copy shows): dropped here, so Trakt decides.
|
|
61
67
|
function clearUnwatched(type, id) {
|
|
62
68
|
var a = watchedAll(), k = type + ':' + id, v = a[k];
|
|
@@ -158,6 +164,7 @@
|
|
|
158
164
|
if (all[k]) { all[k].added = true; }
|
|
159
165
|
else { all[k] = { id: e.id, type: e.type, name: e.name, poster: e.poster, background: e.background, parent: e.parent, position: 0, duration: 0, updated: Date.now(), added: true }; }
|
|
160
166
|
U.store.set(PROGRESS_KEY, all);
|
|
167
|
+
if (typeof StremioSync !== 'undefined' && StremioSync.onAdded) { StremioSync.onAdded(e); } // (your Stremio account's too, at its start)
|
|
161
168
|
}
|
|
162
169
|
|
|
163
170
|
function progressFor(type, id) { return progressAll()[type + ':' + id] || null; }
|
package/js/plex.js
CHANGED
|
@@ -21,7 +21,7 @@ var Plex = (function () {
|
|
|
21
21
|
|
|
22
22
|
var KEY = 'stremiok.plex.servers', DEV_KEY = 'stremiok.plex.device', LIBS_KEY = 'stremiok.plex.libs';
|
|
23
23
|
var TV = 'https://clients.plex.tv', LINK = 'https://plex.tv/link';
|
|
24
|
-
var PAGE = 100, INDEX_FRESH_MS = 30 * 60000, INDEX_RETRY_MS = 60000, LIBS_FRESH_MS = 86400000;
|
|
24
|
+
var PAGE = 100, INDEX_FRESH_MS = 30 * 60000, INDEX_RETRY_MS = 60000, INDEX_SLOW_MS = 30 * 60000, LIBS_FRESH_MS = 86400000;
|
|
25
25
|
var PIN_EVERY = 3000, PIN_FOR = 10 * 60000, REPORT_EVERY = 60000, PIC_EVERY = 5000;
|
|
26
26
|
var _changeFns = [];
|
|
27
27
|
function onChange(fn) { _changeFns.push(fn); }
|
|
@@ -384,9 +384,16 @@ var Plex = (function () {
|
|
|
384
384
|
var x = _index[srv.id];
|
|
385
385
|
if (x && x.map && (x.p || Date.now() - x.at < INDEX_FRESH_MS)) { return Promise.resolve(x.map); }
|
|
386
386
|
if (x && x.p) { return x.p; }
|
|
387
|
+
// (each library a page at a time, as Jellyfin's list: Jellyfin.shared.pages; one not all
|
|
388
|
+
// read, or not at all after its first page: __part, its titles looked up by name too)
|
|
389
|
+
var part = null;
|
|
387
390
|
var p = Promise.all(libsOf(srv).map(function (lib) {
|
|
388
|
-
return
|
|
389
|
-
return
|
|
391
|
+
return share().pages(function (start) {
|
|
392
|
+
return get(srv, '/library/sections/' + enc(lib.id) + '/all?type=' + (lib.type === 'movie' ? 1 : 2) + '&includeGuids=1&sort=titleSort' +
|
|
393
|
+
'&X-Plex-Container-Start=' + start + '&X-Plex-Container-Size=' + share().INDEX_PAGE, 8 * 1048576).then(function (r) { return U.listOf(mc(r).Metadata, share().INDEX_PAGE); });
|
|
394
|
+
}).then(function (got) {
|
|
395
|
+
if (got.part) { part = part && part.e ? part : got.part; }
|
|
396
|
+
return got.items.map(function (it) { return { t: lib.type, it: it }; });
|
|
390
397
|
});
|
|
391
398
|
})).then(function (lists) {
|
|
392
399
|
var map = { __ids: {}, __tm: {}, __played: [] }; // (__played: its watched films and shows)
|
|
@@ -399,12 +406,22 @@ var Plex = (function () {
|
|
|
399
406
|
var played = e.t === 'movie' ? +it.viewCount > 0 : +it.leafCount > 0 && +it.viewedLeafCount >= +it.leafCount;
|
|
400
407
|
if (played) { map.__played.push({ t: e.t, ids: titleIds(map, (e.t === 'movie' ? 'pxm.' : 'pxs.') + srv.id + '.', rk), at: (+it.lastViewedAt || 0) * 1000 }); }
|
|
401
408
|
});
|
|
402
|
-
|
|
409
|
+
var at = Date.now();
|
|
410
|
+
if (part) {
|
|
411
|
+
map.__part = true;
|
|
412
|
+
if (part.e) {
|
|
413
|
+
U.log('plex', '“' + srv.name + '”: only some of its titles read (' + U.problem(part.e) + ')');
|
|
414
|
+
at -= INDEX_FRESH_MS - (/Timed out/i.test(part.e.message || '') ? INDEX_SLOW_MS : INDEX_RETRY_MS);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (_index[srv.id] && _index[srv.id].p === p) { _index[srv.id] = { at: at, map: map }; }
|
|
403
418
|
return map;
|
|
404
419
|
}, function (e) {
|
|
405
420
|
U.log('plex', '“' + srv.name + '”: its titles couldn’t be read (' + U.problem(e) + ')');
|
|
406
421
|
var old = _index[srv.id], map = (old && old.map) || { __ids: {}, __tm: {}, __played: [], __err: true };
|
|
407
|
-
|
|
422
|
+
// (asked again in a minute; one that timed out, after 30: titles looked up by name meanwhile, idsFor)
|
|
423
|
+
var slow = /Timed out/i.test((e && e.message) || '');
|
|
424
|
+
if (old && old.p === p) { _index[srv.id] = { at: Date.now() - INDEX_FRESH_MS + (slow ? INDEX_SLOW_MS : INDEX_RETRY_MS), map: map }; }
|
|
408
425
|
return map;
|
|
409
426
|
});
|
|
410
427
|
_index[srv.id] = { at: x ? x.at : 0, map: x ? x.map : null, p: p };
|
|
@@ -438,7 +455,37 @@ var Plex = (function () {
|
|
|
438
455
|
return sh.marksFrom(list);
|
|
439
456
|
});
|
|
440
457
|
}
|
|
441
|
-
|
|
458
|
+
// A title the server's list can't give (never read, or not all of it: a library too big or slow):
|
|
459
|
+
// searched for by its name in each library of its kind, taken only when its IMDb or TMDB id is
|
|
460
|
+
// the one asked for (Jellyfin's way). Kept FOUND_MS (a failed search: asked again next time).
|
|
461
|
+
var FOUND_MS = 30 * 60000, _found = U.lru(300);
|
|
462
|
+
function lookup(srv, type, key, name) {
|
|
463
|
+
name = ('' + (name || '')).replace(/\s+/g, ' ').trim().slice(0, 100);
|
|
464
|
+
if (!name) { return Promise.resolve([]); }
|
|
465
|
+
var k = srv.id + '|' + type + '|' + key, had = _found.get(k);
|
|
466
|
+
if (had && had.p && Date.now() - had.at < FOUND_MS) { return had.p; }
|
|
467
|
+
var p = Promise.all(libsOf(srv).filter(function (l) { return l.type === type; }).map(function (lib) {
|
|
468
|
+
return get(srv, '/library/sections/' + enc(lib.id) + '/all?type=' + (type === 'movie' ? 1 : 2) + '&includeGuids=1&title=' + enc(name) +
|
|
469
|
+
'&X-Plex-Container-Start=0&X-Plex-Container-Size=40').then(function (r) {
|
|
470
|
+
return U.listOf(mc(r).Metadata, 40, function (it) { return it && it.ratingKey != null && (imdbOf(it) === key || (!!tmdbOf(it) && 'tmdb:' + tmdbOf(it) === key)); }).map(function (it) { return '' + it.ratingKey; });
|
|
471
|
+
});
|
|
472
|
+
})).then(flat, function (e) {
|
|
473
|
+
_found.set(k, null);
|
|
474
|
+
U.log('plex', '“' + srv.name + '”: “' + name + '” couldn’t be looked up (' + U.problem(e) + ')');
|
|
475
|
+
return [];
|
|
476
|
+
});
|
|
477
|
+
_found.set(k, { at: Date.now(), p: p });
|
|
478
|
+
return p;
|
|
479
|
+
}
|
|
480
|
+
// The server's items for a title: from its list; with no list yet, none to be had or not all of
|
|
481
|
+
// it, looked up by name meanwhile, the list's answer used when that finds none.
|
|
482
|
+
function idsFor(srv, type, key, name) {
|
|
483
|
+
var x = _index[srv.id];
|
|
484
|
+
var fromList = index(srv).then(function (map) { return map[type + '|' + key] || []; });
|
|
485
|
+
if (x && x.map && !x.map.__err && !x.map.__part) { return fromList; }
|
|
486
|
+
return lookup(srv, type, key, name).then(function (ids) { return ids.length ? ids : fromList; });
|
|
487
|
+
}
|
|
488
|
+
function copies(type, id, meta) {
|
|
442
489
|
var key = '', season = null, episode = null;
|
|
443
490
|
if (type === 'movie') { key = /^(tt\d+|tmdb:\d+)$/.test('' + id) ? '' + id : ''; }
|
|
444
491
|
else if (type === 'series') {
|
|
@@ -446,9 +493,10 @@ var Plex = (function () {
|
|
|
446
493
|
if (mm) { key = mm[1]; season = +mm[2]; episode = +mm[3]; }
|
|
447
494
|
}
|
|
448
495
|
if (!key) { return Promise.resolve([]); }
|
|
496
|
+
var name = meta && typeof meta.name === 'string' ? meta.name : '';
|
|
449
497
|
return Promise.all(servers().map(function (srv) {
|
|
450
|
-
return
|
|
451
|
-
return Promise.all(
|
|
498
|
+
return idsFor(srv, type, key, name).then(function (rks) {
|
|
499
|
+
return Promise.all(rks.slice(0, 3).map(function (rk) {
|
|
452
500
|
return type === 'movie' ? item(srv, rk).then(function (it) { return sourcesOf(srv, it); }, none) : episodeSources(srv, rk, season, episode);
|
|
453
501
|
}));
|
|
454
502
|
}).then(flat, none);
|
|
@@ -527,14 +575,14 @@ var Plex = (function () {
|
|
|
527
575
|
return e ? item(srv, e.it.ratingKey).then(function (it) { return sourcesOf(srv, it); }, none) : [];
|
|
528
576
|
}, none);
|
|
529
577
|
}
|
|
530
|
-
function streams(type, id) {
|
|
578
|
+
function streams(type, id, meta) { // (meta: the title's details, for its name: lookup)
|
|
531
579
|
var x = parseId(id);
|
|
532
580
|
if (x) {
|
|
533
581
|
if (!x.srv) { return Promise.resolve([]); }
|
|
534
582
|
if (x.kind === 'm') { return item(x.srv, x.item).then(function (it) { return sourcesOf(x.srv, it); }, none); }
|
|
535
583
|
return x.season != null ? episodeSources(x.srv, x.item, x.season, x.episode) : Promise.resolve([]);
|
|
536
584
|
}
|
|
537
|
-
return copies(type, id);
|
|
585
|
+
return copies(type, id, meta);
|
|
538
586
|
}
|
|
539
587
|
function isPlexId(id) { return /^px[ms]\./.test('' + id); }
|
|
540
588
|
|
package/js/stremio-account.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
seconds, it then gives a sign-in key (start, wait). With it the account's addons are read
|
|
5
5
|
(addons) and the key is given up at once (signOut): no password on the TV, nothing of the
|
|
6
6
|
account kept, the account itself unchanged. StremioK has no key of Stremio's: none is needed.
|
|
7
|
+
Keeping your account in step (js/stremio-sync.js) signs in the same way and keeps the key.
|
|
7
8
|
Global namespace: StremioAccount */
|
|
8
9
|
var StremioAccount = (function () {
|
|
9
10
|
'use strict';
|
|
@@ -35,24 +36,28 @@ var StremioAccount = (function () {
|
|
|
35
36
|
setTimeout(ask, POLL_MS);
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
|
-
// POST a request to Stremio's API: its result
|
|
39
|
-
|
|
39
|
+
// POST a request to Stremio's API: its result (an answer over max, MAX_BYTES unless given,
|
|
40
|
+
// refused). A refusal's Error carries Stremio's code (1: the sign-in no longer works).
|
|
41
|
+
function call(method, body, max) {
|
|
42
|
+
max = max || MAX_BYTES;
|
|
40
43
|
return new Promise(function (resolve, reject) {
|
|
41
44
|
var xhr = new XMLHttpRequest(), done = false;
|
|
42
45
|
try { xhr.open('POST', API + method, true); } catch (e) { reject(new Error('couldn’t reach Stremio')); return; }
|
|
43
46
|
xhr.timeout = 20000;
|
|
44
47
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
45
48
|
xhr.onprogress = function (ev) { // (an answer over MAX_BYTES: stopped as it arrives, as every other request is)
|
|
46
|
-
if (!done && ev && ev.loaded >
|
|
49
|
+
if (!done && ev && ev.loaded > max) { done = true; try { xhr.abort(); } catch (e) {} reject(new Error('too large an answer')); }
|
|
47
50
|
};
|
|
48
51
|
xhr.onreadystatechange = function () {
|
|
49
52
|
if (xhr.readyState !== 4 || done) { return; }
|
|
50
53
|
done = true;
|
|
51
54
|
var text = '' + (xhr.responseText || ''), data = null;
|
|
52
|
-
if (text.length >
|
|
55
|
+
if (text.length > max) { reject(new Error('too large an answer')); return; }
|
|
53
56
|
try { data = JSON.parse(text); } catch (e2) { data = null; }
|
|
54
57
|
if (xhr.status >= 200 && xhr.status < 300 && data && data.result) { resolve(data.result); return; }
|
|
55
|
-
|
|
58
|
+
var err = new Error((data && data.error && data.error.message) || ('HTTP ' + xhr.status));
|
|
59
|
+
err.code = (data && data.error && typeof data.error.code === 'number') ? data.error.code : 0;
|
|
60
|
+
reject(err);
|
|
56
61
|
};
|
|
57
62
|
xhr.ontimeout = function () { if (!done) { done = true; reject(new Error('Stremio didn’t answer')); } };
|
|
58
63
|
xhr.onerror = function () { if (!done) { done = true; reject(new Error('couldn’t reach Stremio')); } };
|
|
@@ -75,5 +80,5 @@ var StremioAccount = (function () {
|
|
|
75
80
|
// The key given up (Stremio's own sign-out): whatever happens, nothing is kept here.
|
|
76
81
|
function signOut(key) { return call('logout', { type: 'Logout', authKey: key }).then(function () {}, function () {}); }
|
|
77
82
|
|
|
78
|
-
return { start: start, wait: wait, addons: addons, signOut: signOut };
|
|
83
|
+
return { start: start, wait: wait, addons: addons, signOut: signOut, call: call };
|
|
79
84
|
})();
|