stremiok 2.2.2 → 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/js/xtvod.js ADDED
@@ -0,0 +1,366 @@
1
+ /* Xtream films and series. Global namespace: XtVod
2
+ An Xtream account's (your IPTV playlists') films and series, as a local addon like IPTV's: a
3
+ Movies and a Series catalog per account (its categories as genres; none: the newest; search),
4
+ their pages (get_vod_info / get_series_info) and sources. On titles from your addons (IMDb or
5
+ TMDB ids), the accounts' copies of them as sources, found by StremioK's service, which keeps
6
+ each account's whole list (see service/index.js, xtvControl; YTPlay.xtvodAsk).
7
+ Ids: xvm.<account>.<id> (a film), xvs.<account>.<id> (a series; its episodes
8
+ xvs.<account>.<id>:<season>:<episode>, as other addons' tt…:1:2). */
9
+ var XtVod = (function () {
10
+ 'use strict';
11
+
12
+ var CATS_KEY = 'stremiok.xtvod.cats', CATS_FRESH_MS = 86400000, CATS_RETRY_MS = 6 * 3600000, PAGE = 100, CATS_MAX = 2000;
13
+ function enc(v) { return encodeURIComponent('' + v); }
14
+
15
+ // The Xtream accounts among your playlists (switched on): { id, label, base, user, pass }.
16
+ function accounts() {
17
+ if (typeof IPTV === 'undefined' || !IPTV.xtreamParts || !IPTV.xtreamFormat) { return []; }
18
+ return IPTV.getPlaylists().filter(function (p) { return !p.off && IPTV.xtreamFormat(p.id); }).map(function (p) {
19
+ var x = IPTV.xtreamParts(p.url);
20
+ return x && x.user && x.pass ? { id: p.id, label: IPTV.label(p.id), base: x.base, user: x.user, pass: x.pass } : null;
21
+ }).filter(Boolean);
22
+ }
23
+ function account(id) {
24
+ var l = accounts();
25
+ for (var i = 0; i < l.length; i++) { if (l[i].id === id) { return l[i]; } }
26
+ return null;
27
+ }
28
+ // An account whose server lists films or series (of that type: either, without one), or whose
29
+ // categories haven't been asked yet. A server that offers only live channels (its film and
30
+ // series answers empty, or not JSON) adds nothing: no catalogs, no copies, no source.
31
+ function hasVod(acc, type) {
32
+ var c = known(acc);
33
+ if (!c) { return true; }
34
+ return type ? catsOf(acc, type).length > 0 : (catsOf(acc, 'movie').length > 0 || catsOf(acc, 'series').length > 0);
35
+ }
36
+ // What's kept follows the account's server and username: its link edited, the old server's
37
+ // categories and titles aren't shown as its own.
38
+ function sigOf(acc) { return acc.id + '|' + acc.base + '|' + acc.user; }
39
+ function known(acc) { var c = catsAll()[acc.id]; return c && c.sig === sigOf(acc) ? c : null; }
40
+ function isEnabled() { return accounts().some(function (acc) { return hasVod(acc); }); }
41
+ // Whether an Xtream playlist's own film and episode lines (/movie/…, /series/…) stay out of the
42
+ // IPTV tab: yes, unless its server is known to list none (they're its films and series here).
43
+ // onVodChange: told when an account turns out to have some, or none (its IPTV rows made again).
44
+ function noneKnown(id) { var acc = account(id), c = acc ? known(acc) : null; return !!(c && c.none); }
45
+ function hidesVodLines(id) { return !noneKnown(id); }
46
+ var _vodFns = [];
47
+ function onVodChange(fn) { _vodFns.push(fn); }
48
+ function api(acc, action, more) {
49
+ return U.getJSON(acc.base + '/player_api.php?username=' + enc(acc.user) + '&password=' + enc(acc.pass) + '&action=' + action + (more || ''), 20000, 16 * 1048576);
50
+ }
51
+
52
+ // ---- Categories: Discover's genres, kept a day (U.store), read again in the background ----
53
+ var _cats = null, _catsAsked = {}, _changeFns = [];
54
+ function onChange(fn) { _changeFns.push(fn); } // (catalogs added or gone once its categories came)
55
+ // Reload on an account (Settings › Content › IPTV): its categories asked again now, and the
56
+ // service's list of its films and series read again (the next time it's asked: force).
57
+ var _force = {}, _reloaded = {};
58
+ function reload(id) {
59
+ var acc = account(id), all = catsAll();
60
+ if (!acc) { return; }
61
+ delete all[id];
62
+ U.store.set(CATS_KEY, all);
63
+ _catsAsked[sigOf(acc)] = false;
64
+ _catItems.clear(); _info.clear(); // (an answer still on its way isn't kept: it's the cached promise that's dropped)
65
+ _reloaded[id] = true; // (its rows drawn again once its categories come, whatever they are)
66
+ _force[id + '|movie'] = _force[id + '|series'] = true;
67
+ refreshCats();
68
+ var since = Date.now();
69
+ ['movie', 'series'].forEach(function (type) { // (the service starts reading at once; its rows drawn again when it's done)
70
+ indexAsk('list', acc, type, '').then(function () { watchIndex(acc, type, since); });
71
+ });
72
+ }
73
+ function catsAll() {
74
+ if (!_cats) { var c = U.store.get(CATS_KEY, {}); _cats = c && typeof c === 'object' && !Array.isArray(c) ? c : {}; }
75
+ return _cats;
76
+ }
77
+ function catsOf(acc, type) { var c = known(acc); return c && Array.isArray(c[type]) ? c[type] : []; }
78
+ function catList(a) {
79
+ return (Array.isArray(a) ? a : []).filter(function (x) { return x && x.category_id != null && x.category_name; }).slice(0, CATS_MAX)
80
+ .map(function (x) { return [('' + x.category_id).slice(0, 20), ('' + x.category_name).replace(/\s+/g, ' ').trim().slice(0, 80)]; });
81
+ }
82
+ function refreshCats() {
83
+ accounts().forEach(function (acc) {
84
+ var c = known(acc), sk = sigOf(acc);
85
+ if ((c && Date.now() - c.at < (c.none ? CATS_RETRY_MS : CATS_FRESH_MS)) || _catsAsked[sk]) { return; }
86
+ _catsAsked[sk] = true; // (once a launch: an answer that failed isn't asked again until the next)
87
+ function either(p) { return p.then(null, function (e) { return { failed: e }; }); }
88
+ Promise.all([either(api(acc, 'get_vod_categories')), either(api(acc, 'get_series_categories'))]).then(function (r) {
89
+ var all = catsAll(), keep = {}, o = { sig: sk, movie: catList(r[0]), series: catList(r[1]), at: Date.now() }, wasNone = noneKnown(acc.id);
90
+ if (!o.movie.length && !o.series.length) { // (none: asked again in CATS_RETRY_MS)
91
+ o.none = true;
92
+ var why = r[0] && r[0].failed ? U.problem(r[0].failed) : 'its server lists none';
93
+ U.log('iptv', 'Xtream “' + acc.label + '”: no films or series (' + why + ')');
94
+ }
95
+ accounts().forEach(function (a) { if (all[a.id]) { keep[a.id] = all[a.id]; } }); // (accounts gone: dropped)
96
+ keep[acc.id] = o;
97
+ _cats = keep;
98
+ U.store.set(CATS_KEY, keep);
99
+ var before = _addon ? _addon.manifest.catalogs.length : 0;
100
+ fillCatalogs();
101
+ if (_addon && (_addon.manifest.catalogs.length !== before || _reloaded[acc.id])) { changed(); } // (its rows: Home reads them now)
102
+ delete _reloaded[acc.id];
103
+ if (!!o.none !== wasNone) { _vodFns.forEach(function (fn) { try { fn(acc.id); } catch (e) {} }); } // (its film and episode lines: into IPTV, or out)
104
+ });
105
+ });
106
+ }
107
+
108
+ // ---- The addon ----
109
+ // Its catalogs: per account, Movies and Series (named after it), the categories as genres.
110
+ // Its sources: on titles from your addons (tt…, tmdb:…); its own titles' are asked directly
111
+ // (Stremio.getStreams).
112
+ var _addon = null;
113
+ function catalogsNow() {
114
+ var out = [];
115
+ accounts().forEach(function (acc) {
116
+ ['movie', 'series'].forEach(function (type) {
117
+ if (!hasVod(acc, type) || !known(acc)) { return; } // (its categories first: none, no catalog)
118
+ out.push({ type: type, id: 'xv.' + acc.id + '.' + type, name: acc.label,
119
+ extra: [{ name: 'genre', options: catsOf(acc, type).map(function (c) { return c[1]; }) }, { name: 'search' }, { name: 'skip' }] });
120
+ });
121
+ });
122
+ return out;
123
+ }
124
+ var RESOURCES = ['catalog', { name: 'stream', types: ['movie', 'series'], idPrefixes: ['tt', 'tmdb:'] }];
125
+ function fillCatalogs() { // (changed in place: the loaded addon holds the same list)
126
+ if (!_addon) { return; }
127
+ var l = _addon.manifest.catalogs;
128
+ l.splice.apply(l, [0, l.length].concat(catalogsNow()));
129
+ _addon.manifest.resources = isEnabled() ? RESOURCES : ['catalog']; // (no account with films or series: not a source either)
130
+ }
131
+ function synthAddon() {
132
+ if (!_addon) {
133
+ _addon = { __local: true, __impl: XtVod, __sources: true, url: 'local:xtvod', base: 'local:xtvod',
134
+ manifest: { id: 'org.stremiok.xtvod', name: 'Xtream', version: '1.0.0', types: ['movie', 'series'], resources: RESOURCES, catalogs: [] } };
135
+ }
136
+ fillCatalogs();
137
+ refreshCats();
138
+ return _addon;
139
+ }
140
+
141
+ // ---- Titles: a card's meta, from a category's list or the service's ----
142
+ function itemOf(o, type) { // a category list's title -> the service's shape
143
+ return { id: type === 'movie' ? o.stream_id : o.series_id, name: o.name, pic: o.stream_icon || o.cover, rating: o.rating, ext: o.container_extension,
144
+ year: parseInt(o.year, 10) || parseInt(('' + (o.releaseDate || o.release_date || '')).slice(0, 4), 10) || 0 };
145
+ }
146
+ function cardOf(acc, type, it) {
147
+ if (!it || !(+it.id > 0) || !it.name) { return null; }
148
+ var id = (type === 'movie' ? 'xvm.' : 'xvs.') + acc.id + '.' + (+it.id);
149
+ var m = { id: id, type: type, name: ('' + it.name).replace(/\s+/g, ' ').trim(), posterShape: 'poster' };
150
+ if (/^https?:\/\//i.test(it.pic || '')) { m.poster = it.pic; }
151
+ var r = parseFloat(it.rating);
152
+ if (r > 0 && r <= 10) { m.imdbRating = r.toFixed(1); }
153
+ if (it.year > 1880) { m.releaseInfo = '' + it.year; }
154
+ return m;
155
+ }
156
+ function cards(acc, type, items) { return items.map(function (it) { return cardOf(acc, type, it); }).filter(Boolean); }
157
+
158
+ // The service's answer for this account: /xtvod/list (the newest, or a search) or /xtvod/find.
159
+ // Nothing (no service: a desktop browser; or it failed): { items: [] }.
160
+ function indexAsk(path, acc, type, more) {
161
+ if (typeof YTPlay === 'undefined' || !YTPlay.xtvodAsk) { return Promise.resolve({ items: [] }); }
162
+ if (_force[acc.id + '|' + type]) { delete _force[acc.id + '|' + type]; more = (more || '') + '&force=1'; }
163
+ return YTPlay.xtvodAsk(path, acc, type, more).then(function (r) {
164
+ if (r && r.state === 'failed' && r.error) { U.log('iptv', 'Xtream “' + acc.label + '”: its ' + (type === 'movie' ? 'films' : 'series') + ' couldn’t be read (' + r.error + ')'); }
165
+ if (r && isReading(r)) { watchIndex(acc, type, 0); }
166
+ return r && Array.isArray(r.items) ? r : { items: [] };
167
+ }, function (e) { U.log('iptv', 'Xtream “' + acc.label + '”: StremioK’s service didn’t answer (' + U.problem(e) + ')'); return { items: [] }; });
168
+ }
169
+ // The service's list still being read: looked at again, less and less often, until it's done
170
+ // (since: read after then, for a Reload's), and those told (Home's rows, sources kept).
171
+ var _watching = {}, WATCH_FIRST_MS = 3000, WATCH_MAX_MS = 60000, WATCH_FOR_MS = 20 * 60000;
172
+ function isReading(r) { return r.state === 'queued' || r.state === 'reading' || r.state === 'new'; }
173
+ function changed() { _changeFns.forEach(function (fn) { try { fn(); } catch (e) {} }); }
174
+ function watchIndex(acc, type, since) {
175
+ var k = acc.id + '|' + type, wait = WATCH_FIRST_MS, until = Date.now() + WATCH_FOR_MS;
176
+ if (_watching[k]) { return; }
177
+ _watching[k] = true;
178
+ function again() {
179
+ setTimeout(function () {
180
+ if (!account(acc.id) || Date.now() > until) { delete _watching[k]; return; }
181
+ YTPlay.xtvodAsk('list', acc, type, '').then(function (r) {
182
+ if (r && (r.state === 'failed' || (r.state === 'ready' && (!since || r.at >= since)))) { delete _watching[k]; changed(); return; }
183
+ wait = Math.min(wait * 2, WATCH_MAX_MS);
184
+ again();
185
+ }, function () { wait = Math.min(wait * 2, WATCH_MAX_MS); again(); });
186
+ }, wait);
187
+ }
188
+ again();
189
+ }
190
+ // A category's titles, as the provider lists them (kept: the last few asked).
191
+ var _catItems = U.lru(8);
192
+ function categoryCards(acc, type, catId) {
193
+ var k = sigOf(acc) + '|' + type + '|' + catId, kept = _catItems.get(k);
194
+ if (kept) { return kept; }
195
+ var p = api(acc, type === 'movie' ? 'get_vod_streams' : 'get_series', '&category_id=' + enc(catId)).then(function (a) {
196
+ return cards(acc, type, (Array.isArray(a) ? a : []).map(function (o) { return itemOf(o, type); }));
197
+ });
198
+ _catItems.set(k, p);
199
+ p.then(null, function () { if (_catItems.get(k) === p) { _catItems.set(k, null); } });
200
+ return p;
201
+ }
202
+ function catalog(catId, extra) {
203
+ var m = /^xv\.([^.]+)\.(movie|series)$/.exec(catId || ''), acc = m && account(m[1]);
204
+ if (!acc) { return Promise.resolve([]); }
205
+ var type = m[2], skip = extra && extra.skip ? (parseInt(extra.skip, 10) || 0) : 0;
206
+ if (extra && extra.genre) {
207
+ var cat = catsOf(acc, type).filter(function (c) { return c[1] === extra.genre; })[0];
208
+ return cat ? categoryCards(acc, type, cat[0]).then(function (l) { return l.slice(skip, skip + PAGE); }) : Promise.resolve([]);
209
+ }
210
+ var more = (extra && extra.search ? '&q=' + enc(('' + extra.search).slice(0, 120)) : '') + (skip ? '&skip=' + skip : '');
211
+ return indexAsk('list', acc, type, more).then(function (r) {
212
+ var out = cards(acc, type, r.items);
213
+ if (!(extra && extra.search) && isReading(r)) { out.pending = true; } // (being read: Home's Loading…, not an empty row)
214
+ return out;
215
+ });
216
+ }
217
+
218
+ // ---- A title's page ----
219
+ var _info = U.lru(40); // account|action|id -> its answer (a promise)
220
+ function info(acc, action, num) {
221
+ var k = sigOf(acc) + '|' + action + '|' + num, kept = _info.get(k);
222
+ if (kept) { return kept; }
223
+ var p = api(acc, action, (action === 'get_vod_info' ? '&vod_id=' : '&series_id=') + enc(num));
224
+ _info.set(k, p);
225
+ p.then(null, function () { if (_info.get(k) === p) { _info.set(k, null); } });
226
+ return p;
227
+ }
228
+ function parseId(id) {
229
+ var m = /^xv([ms])\.([^.]+)\.(\d+)(?::(\d+):(\d+))?$/.exec('' + id);
230
+ return m ? { kind: m[1], acc: account(m[2]), num: m[3], season: m[4] != null ? +m[4] : null, episode: m[5] != null ? +m[5] : null } : null;
231
+ }
232
+ function list(v) { return ('' + (v || '')).split(/\s*,\s*/).map(function (x) { return x.trim(); }).filter(Boolean).slice(0, 12); }
233
+ function link(v) { return /^https?:\/\//i.test('' + (v || '')) ? '' + v : ''; }
234
+ function firstOf(v) { return Array.isArray(v) ? v[0] : v; }
235
+ function yearOf(v) { var y = parseInt(('' + (v || '')).slice(0, 4), 10); return y > 1880 && y < 2100 ? '' + y : ''; }
236
+ function common(m, i) { // what a film's and a series' info share
237
+ var bg = link(firstOf(i.backdrop_path)), rating = parseFloat(i.rating);
238
+ if (bg) { m.background = bg; }
239
+ if (i.plot || i.description) { m.description = ('' + (i.plot || i.description)).slice(0, 2000); }
240
+ if (list(i.genre).length) { m.genres = list(i.genre); }
241
+ if (list(i.cast || i.actors).length) { m.cast = list(i.cast || i.actors); }
242
+ if (list(i.director).length) { m.director = list(i.director); }
243
+ if (rating > 0 && rating <= 10) { m.imdbRating = rating.toFixed(1); }
244
+ var yt = /^[\w-]{11}$/.test('' + (i.youtube_trailer || '')) ? '' + i.youtube_trailer : '';
245
+ if (yt) { m.trailers = [{ source: yt, type: 'Trailer' }]; }
246
+ return m;
247
+ }
248
+ function meta(type, id) {
249
+ var x = parseId(id);
250
+ if (!x || !x.acc) { return Promise.resolve(null); }
251
+ if (x.kind === 'm') {
252
+ return info(x.acc, 'get_vod_info', x.num).then(function (r) {
253
+ var i = (r && r.info) || {}, d = (r && r.movie_data) || {};
254
+ if (!d.stream_id && !i.name) { return null; }
255
+ var m = common({ id: id, type: 'movie', name: ('' + (i.name || d.name)).trim(), _from: x.acc.label }, i);
256
+ var pic = link(i.cover_big || i.movie_image);
257
+ if (pic) { m.poster = pic; }
258
+ var secs = +i.duration_secs || 0;
259
+ if (secs > 0) { m.runtime = Math.round(secs / 60) + ' min'; }
260
+ var y = yearOf(i.releasedate || i.release_date);
261
+ if (y) { m.releaseInfo = y; m.year = y; }
262
+ return m;
263
+ });
264
+ }
265
+ return info(x.acc, 'get_series_info', x.num).then(function (r) {
266
+ var i = (r && r.info) || {}, showId = 'xvs.' + x.acc.id + '.' + x.num;
267
+ if (!i.name) { return null; }
268
+ var m = common({ id: showId, type: 'series', name: ('' + i.name).trim(), _from: x.acc.label }, i);
269
+ var pic = link(i.cover);
270
+ if (pic) { m.poster = pic; }
271
+ var y = yearOf(i.releaseDate || i.release_date);
272
+ if (y) { m.releaseInfo = y; m.year = y; }
273
+ m.videos = episodes(r).map(function (e) {
274
+ var ei = e.info || {}, v = { id: showId + ':' + e.season + ':' + e.episode, season: e.season, episode: e.episode, title: ('' + (e.title || '')).trim() || 'Episode ' + e.episode };
275
+ if (ei.plot) { v.overview = ('' + ei.plot).slice(0, 1000); }
276
+ if (link(ei.movie_image)) { v.thumbnail = link(ei.movie_image); }
277
+ var rel = Date.parse(ei.releasedate || ei.air_date || '');
278
+ if (rel) { v.released = new Date(rel).toISOString(); }
279
+ return v;
280
+ });
281
+ return m;
282
+ });
283
+ }
284
+ // A series' episodes, however its server lists them ({ "1": [...] } or [[...]]): [{ season,
285
+ // episode, id, ext, title, info }], in order.
286
+ function episodes(r) {
287
+ var out = [], eps = r && r.episodes;
288
+ if (!eps || typeof eps !== 'object') { return out; }
289
+ Object.keys(eps).forEach(function (k) {
290
+ (Array.isArray(eps[k]) ? eps[k] : []).forEach(function (e) {
291
+ var season = parseInt(e && (e.season != null ? e.season : k), 10), ep = parseInt(e && e.episode_num, 10);
292
+ if (!e || !(+e.id > 0) || !(season >= 0) || !(ep >= 0)) { return; }
293
+ out.push({ season: season, episode: ep, id: +e.id, ext: /^[a-z0-9]{2,5}$/i.test(e.container_extension || '') ? ('' + e.container_extension).toLowerCase() : 'mp4', title: e.title, info: e.info });
294
+ });
295
+ });
296
+ out.sort(function (a, b) { return a.season - b.season || a.episode - b.episode; });
297
+ return out;
298
+ }
299
+
300
+ // ---- Sources ----
301
+ // Its quality, from its name ("… 4K", "FHD") or the file's own (info.video.height).
302
+ function quality(name, video) {
303
+ var h = video && +video.height;
304
+ if (h >= 1600) { return '4K'; }
305
+ if (h >= 900) { return '1080p'; }
306
+ if (h >= 600) { return '720p'; }
307
+ var n = ' ' + ('' + (name || '')).toUpperCase() + ' ';
308
+ if (/[^A-Z0-9](4K|UHD|2160P)[^A-Z0-9]/.test(n)) { return '4K'; }
309
+ if (/[^A-Z0-9](FHD|1080P)[^A-Z0-9]/.test(n)) { return '1080p'; }
310
+ if (/[^A-Z0-9](HD|720P)[^A-Z0-9]/.test(n)) { return '720p'; }
311
+ return '';
312
+ }
313
+ function source(acc, url, name, ext, video) {
314
+ var q = quality(name, video);
315
+ return { url: url, name: 'Xtream' + (q ? '\n' + q : ''), title: ('' + name).trim() + '\n' + acc.label + (ext ? ' · ' + ext.toUpperCase() : ''), _xtvod: true };
316
+ }
317
+ function movieUrl(acc, num, ext) { return acc.base + '/movie/' + enc(acc.user) + '/' + enc(acc.pass) + '/' + num + '.' + ext; }
318
+ function episodeSource(acc, num, season, episode) {
319
+ return info(acc, 'get_series_info', num).then(function (r) {
320
+ var e = episodes(r).filter(function (x) { return x.season === season && x.episode === episode; })[0];
321
+ if (!e) { return null; }
322
+ var name = ((r.info && r.info.name) || '') + ' S' + (season < 10 ? '0' : '') + season + 'E' + (episode < 10 ? '0' : '') + episode;
323
+ return source(acc, acc.base + '/series/' + enc(acc.user) + '/' + enc(acc.pass) + '/' + e.id + '.' + e.ext, name, e.ext, e.info && e.info.video);
324
+ }, function () { return null; });
325
+ }
326
+ function filmSource(acc, num, name, ext) {
327
+ if (ext) { return Promise.resolve(source(acc, movieUrl(acc, num, ext), name, ext)); }
328
+ return info(acc, 'get_vod_info', num).then(function (r) {
329
+ var d = (r && r.movie_data) || {}, i = (r && r.info) || {};
330
+ var e = /^[a-z0-9]{2,5}$/i.test(d.container_extension || '') ? ('' + d.container_extension).toLowerCase() : 'mp4';
331
+ return source(acc, movieUrl(acc, num, e), name || i.name || d.name || '', e, i.video);
332
+ }, function () { return null; });
333
+ }
334
+ // A title's sources: its own (xvm / xvs ids: from its info, which its page has asked for
335
+ // already), or, for a title from your addons, each account's copies (m: its details, for its
336
+ // TMDB id, name and year).
337
+ function streams(type, id, m) {
338
+ var x = parseId(id);
339
+ if (x) {
340
+ if (!x.acc) { return Promise.resolve([]); }
341
+ var p = x.kind === 'm' ? filmSource(x.acc, x.num, '', '') : x.season != null ? episodeSource(x.acc, x.num, x.season, x.episode) : Promise.resolve(null);
342
+ return p.then(function (s) { return s ? [s] : []; });
343
+ }
344
+ return matches(type, id, m);
345
+ }
346
+ function tmdbOf(id, m) {
347
+ var t = /^tmdb:(\d+)/.exec('' + id);
348
+ return t ? t[1] : (m && +(m.moviedb_id || m.tmdb_id || m.tmdbId) > 0 ? '' + +(m.moviedb_id || m.tmdb_id || m.tmdbId) : '');
349
+ }
350
+ function matches(type, id, m) {
351
+ var parts = ('' + id).split(':'), season = type === 'series' ? parseInt(parts[parts.length - 2], 10) : null, episode = type === 'series' ? parseInt(parts[parts.length - 1], 10) : null;
352
+ if (type === 'series' && !(season >= 0 && episode >= 0)) { return Promise.resolve([]); }
353
+ var tmdb = tmdbOf(id, m), name = m && m.name ? '' + m.name : '', year = m ? yearOf(m.year || m.releaseInfo || m.released) : '';
354
+ if (!tmdb && !name) { return Promise.resolve([]); }
355
+ var more = (tmdb ? '&tmdb=' + tmdb : '') + (name ? '&name=' + enc(name.slice(0, 120)) : '') + (year ? '&year=' + year : '');
356
+ return Promise.all(accounts().filter(function (acc) { return known(acc) && hasVod(acc, type); }).map(function (acc) {
357
+ return indexAsk('find', acc, type, more).then(function (r) {
358
+ return Promise.all(r.items.slice(0, 6).map(function (it) {
359
+ return type === 'movie' ? filmSource(acc, +it.id, it.name, it.ext || '') : episodeSource(acc, +it.id, season, episode);
360
+ }));
361
+ });
362
+ })).then(function (all) { return [].concat.apply([], all).filter(Boolean); });
363
+ }
364
+
365
+ return { accounts: accounts, isEnabled: isEnabled, onChange: onChange, reload: reload, hidesVodLines: hidesVodLines, onVodChange: onVodChange, synthAddon: synthAddon, catalog: catalog, meta: meta, streams: streams, refreshCats: refreshCats };
366
+ })();
package/js/ytplay.js CHANGED
@@ -96,6 +96,29 @@ var YTPlay = (function () {
96
96
  return U.getJSON(PROXY + '/aiom/addons?base=' + encodeURIComponent(base) + a.q, 40000, 1048576, null, h);
97
97
  });
98
98
  }
99
+ // A Stalker portal, through the service (a web page can't send its MAC address cookie or a MAG
100
+ // User-Agent): stalkerList -> { m3u, count } or { refused | unreachable, why }: its channels as
101
+ // an M3U playlist; stalkerLink -> { url } or { why }: a channel's link (u, from that playlist)
102
+ // to play now. portal: its address; mac: 00:1A:79:… (see service/index.js, stalkerControl).
103
+ function stalkerAsk(path, portal, mac, more, ms, max, cancel) {
104
+ if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
105
+ return ensureService().then(entryAuth).then(function (a) {
106
+ return U.getJSON(PROXY + path + '?portal=' + encodeURIComponent(portal) + '&mac=' + encodeURIComponent(mac) + more + a.q, ms, max, cancel || null, a.h);
107
+ });
108
+ }
109
+ function stalkerList(portal, mac) { return stalkerAsk('/stalker/list', portal, mac, '', 90000, 48 * 1048576); }
110
+ function stalkerLink(portal, mac, u, cancel) { return stalkerAsk('/stalker/link', portal, mac, '&u=' + encodeURIComponent(u), 25000, 65536, cancel); }
111
+ // An Xtream account's films or series, kept by the service (see service/index.js, xtvControl;
112
+ // user= and pass=: names Diagnostics masks):
113
+ // path 'list' (the newest; more: &q= for a search, &skip=) or 'find' (a title's copies: &tmdb=
114
+ // &name= &year=) -> { state, at, error, items: [{ id, name, year, tmdb, cat, ext, pic, rating }] }.
115
+ function xtvodAsk(path, acc, type, more) {
116
+ if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
117
+ return ensureService().then(entryAuth).then(function (a) {
118
+ return U.getJSON(PROXY + '/xtvod/' + path + '?base=' + encodeURIComponent(acc.base) + '&user=' + encodeURIComponent(acc.user) + '&pass=' + encodeURIComponent(acc.pass) +
119
+ '&type=' + type + (more || '') + a.q, 30000, 4 * 1048576, null, a.h);
120
+ });
121
+ }
99
122
  // A playlist's TV guide, read and kept by the service (see service/index.js, epgControl):
100
123
  // epgLoad asks it to read it for these channels (k: their keys as a bitset, EPG.bitsFor) ->
101
124
  // { state, at, channels, programmes, partial, error }; epgGet: their programs -> { <key>:
@@ -230,6 +253,6 @@ var YTPlay = (function () {
230
253
  return MODE === 'tizenbrew' ? 'TizenBrew module' : MODE === 'wgt' ? 'Sideloaded app (.wgt)' : 'Browser (development)';
231
254
  }
232
255
 
233
- return { ensureService: ensureService, resolverUrl: resolverUrl, infoUrl: infoUrl, canPlay: canPlay, liveOpen: liveOpen, hlsMaster: hlsMaster, aiomAddons: aiomAddons, epgLoad: epgLoad, epgGet: epgGet, epgFiles: epgFiles, epgClear: epgClear, entryOpen: entryOpen, entryPoll: entryPoll, entryClose: entryClose, subsUrl: subsUrl, audioLang: audioLang, setAudioLang: setAudioLang, installMode: function () { return MODE; },
256
+ return { ensureService: ensureService, resolverUrl: resolverUrl, infoUrl: infoUrl, canPlay: canPlay, liveOpen: liveOpen, hlsMaster: hlsMaster, aiomAddons: aiomAddons, stalkerList: stalkerList, stalkerLink: stalkerLink, xtvodAsk: xtvodAsk, epgLoad: epgLoad, epgGet: epgGet, epgFiles: epgFiles, epgClear: epgClear, entryOpen: entryOpen, entryPoll: entryPoll, entryClose: entryClose, subsUrl: subsUrl, audioLang: audioLang, setAudioLang: setAudioLang, installMode: function () { return MODE; },
234
257
  installLabel: installLabel, unavailableMessage: unavailableMessage, isRunning: isRunning, port: PORT };
235
258
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stremiok",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "StremioK streaming client for Tizen 3.0+ Samsung TVs (TizenBrew app module).",
5
5
  "packageType": "app",
6
6
  "appName": "StremioK",