(function () { 'use strict'; var PLUGIN = { name: 'mymovies', title: 'mymovies_title', menu_action: 'mymovies' }; var DEFAULT_BASE = 'https://movies-lmp-18.dynv6.net/'; // ---------- Remote logger (always on) ---------- // Forwards console.* from the device to the server so logs are visible centrally. // Device is identified by userAgent + Lampa device/platform + server-seen IP. (function () { try { var LOG_URL = 'http://movies-lmp-18.dynv6.net:8899/mymovies-log'; function deviceInfo() { var ua = navigator.userAgent || 'unknown'; var dev = ''; try { dev = (Lampa.Device && (Lampa.Device.name || Lampa.Device.platform)) || ''; } catch (e) {} if (!dev) { try { dev = (window.Platform && window.Platform.name && window.Platform.name()) || ''; } catch (e) {} } return ua + (dev ? ' [' + dev + ']' : ''); } function send(level, args) { var msg = [].map.call(args, function (a) { try { return (typeof a === 'object') ? JSON.stringify(a) : String(a); } catch (e) { return String(a); } }).join(' '); var payload = 'level=' + encodeURIComponent(level) + '&dev=' + encodeURIComponent(deviceInfo()) + '&msg=' + encodeURIComponent(msg); // fire-and-forget; ignore failures (e.g. offline) var img = new Image(); img.src = LOG_URL + '?' + payload + '&_=' + Date.now(); } var orig = { log: console.log.bind(console), warn: console.warn.bind(console), error: console.error.bind(console), info: console.info.bind(console) }; console.log = function () { send('log', arguments); orig.log.apply(console, arguments); }; console.warn = function () { send('warn', arguments); orig.warn.apply(console, arguments); }; console.error = function () { send('error', arguments); orig.error.apply(console, arguments); }; console.info = function () { send('info', arguments); orig.info.apply(console, arguments); }; window.onerror = function (m, s, l, c, e) { send('error', ['[onerror]', m, s + ':' + l]); }; } catch (e) {} })(); console.log('[mymovies] plugin loaded', PLUGIN.name, 'base', DEFAULT_BASE); // Forward torrent download progress to the remote log. // PlayerInfo emits 'stat' while Torserver preloads the torrent; we mirror it // into console.log so the central logger captures % / peers / speed. // Registered once globally (not per play) to avoid duplicate listeners. try { if (Lampa.PlayerInfo && Lampa.PlayerInfo.listener) { Lampa.PlayerInfo.listener.follow('stat', function (e) { if (!e || !e.data) return; var d = e.data; if (d.preloaded_bytes == null && d.active_peers == null) return; var pb = d.preloaded_bytes || 0, ps = d.preload_size || 0, prog = ps ? Math.min(100, Math.round(pb * 100 / ps)) : 0; console.log('[mymovies] torrent', prog + '%', 'peers:', d.active_peers || 0, 'speed:', d.download_speed || 0); }); } } catch (err) {} // Localized strings. Register once, then use Lampa.Lang.translate(KEY). var STRINGS = { mymovies_title: { ru: 'Мои фильмы', en: 'My Movies' } }; function t(key) { try { return Lampa.Lang.translate(key); } catch (e) { return key; } } function base() { var b = Lampa.Storage.get(PLUGIN.name + '_base', DEFAULT_BASE); return b.replace(/\/+$/, '') + '/'; } function resolve(p) { if (!p) return ''; if (/^https?:\/\//.test(p)) return p; if (/^magnet:/.test(p)) return p; return base() + p.replace(/^\/+/, ''); } // Append a cache-busting param so Lampa.Reguest does not serve a stale copy. function bust(url) { var sep = url.indexOf('?') >= 0 ? '&' : '?'; return url + sep + '_=' + Date.now(); } function esc(s) { return String(s == null ? '' : s) .replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } // Load catalog via Lampa native network layer (TV-safe, fetch fails on some devices) function loadCatalog(cb) { var url = bust(base() + 'movies/catalog.json'); if (Lampa.Reguest && Lampa.Reguest.get) { Lampa.Reguest.get(url, function (html) { try { cb(null, JSON.parse(html)); } catch (e) { cb(e, null); } }, function (err) { cb(err || new Error('request failed'), null); }); } else { fetch(url).then(function (r) { return r.json(); }) .then(function (d) { cb(null, d); }) .catch(function (e) { cb(e, null); }); } } // Plugin styles. // NOTE: Lampa.Template.add() only stores the string in memory — it does NOT // inject