From 5f6af23f2c6c3ff0d7a63e35bd3716a1ede8eb67 Mon Sep 17 00:00:00 2001 From: lemax10 Date: Sat, 25 Oct 2025 04:10:28 -0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20plugins/tmdb-proxy.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/tmdb-proxy.js | 177 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 plugins/tmdb-proxy.js diff --git a/plugins/tmdb-proxy.js b/plugins/tmdb-proxy.js new file mode 100644 index 0000000..e5bbe26 --- /dev/null +++ b/plugins/tmdb-proxy.js @@ -0,0 +1,177 @@ +/** + * Оптимизированный скрипт прокси для tmdb на основе скрипта https://skaztv.online/t.js + */ +(function () { + 'use strict'; + + const DOMAIN = 'cubnotrip.top'; + const API_ENDPOINTS = [ + { url: `https://${DOMAIN}/api/checker`, name: DOMAIN } + ]; + + const tmdbProxy = { + name: 'TMDB Proxy by Skaz (Mod. LeMaX)', + version: '1.0.5', + description: 'Проксирование постеров и API сайта TMDB (Optimized )', + pathImage: `imagetmdb.${DOMAIN}/`, + pathApi: `apitmdb.${DOMAIN}/3/` + }; + + // Кэширование результатов проверки API + let apiCheckComplete = false; + + /** + * Проверка доступности API + */ + function checkApiAvailability() { + if (apiCheckComplete) return; + + let currentIndex = 0; + + function tryNextEndpoint() { + if (currentIndex >= API_ENDPOINTS.length) return; + + const endpoint = API_ENDPOINTS[currentIndex]; + const xhr = new XMLHttpRequest(); + + xhr.open('GET', endpoint.url, true); + xhr.timeout = 5000; + + xhr.onload = function() { + if (xhr.status === 200) { + try { + const response = xhr.responseText; + if (response === 'ok') { + localStorage.setItem('cub_domain', endpoint.name); + apiCheckComplete = true; + return; + } + } catch (error) { + console.warn('API check error:', error); + } + } + currentIndex++; + tryNextEndpoint(); + }; + + xhr.onerror = xhr.ontimeout = function() { + currentIndex++; + tryNextEndpoint(); + }; + + xhr.send(); + } + + tryNextEndpoint(); + } + + /** + * Фильтрация URL (замена обратных слешей) + */ + function filterUrl(url) { + const prefix = url.slice(0, 8); + const suffix = url.slice(8).replace(/\/\+/g, '/'); + return prefix + suffix; + } + + /** + * Получение email пользователя + */ + function getUserEmail() { + try { + const account = Lampa.Storage.get('account', '{}'); + return (typeof account === 'string' ? JSON.parse(account) : account).email || ''; + } catch (e) { + return ''; + } + } + + /** + * Добавление email параметра к URL + */ + function addEmailParam(url) { + const email = getUserEmail(); + return email ? Lampa.Utils.addUrlComponent(url, `email=${encodeURIComponent(email)}`) : url; + } + + /** + * Инициализация проверки API + */ + if (Lampa.Storage.get('cub_domain_skaz') === 1) { + checkApiAvailability(); + } + + // Отключение кэширования изображений + Lampa.Storage.set('cache_images', false); + + /** + * Переопределение метода получения изображений TMDB + */ + Lampa.TMDB.image = function (url) { + const protocol = Lampa.Utils.protocol(); + const isProxyEnabled = Lampa.Storage.field('proxy_tmdb'); + + const baseUrl = isProxyEnabled + ? `${protocol}${tmdbProxy.pathImage}${url}` + : `${protocol}image.tmdb.org/${url}`; + + return addEmailParam(filterUrl(baseUrl)); + }; + + /** + * Переопределение метода API TMDB + */ + Lampa.TMDB.api = function (url) { + const protocol = Lampa.Utils.protocol(); + const isProxyEnabled = Lampa.Storage.field('proxy_tmdb'); + + const baseUrl = isProxyEnabled + ? `${protocol}${tmdbProxy.pathApi}${url}` + : `${protocol}api.themoviedb.org/3/${url}`; + + return addEmailParam(filterUrl(baseUrl)); + }; + + /** + * Удаление стандартного прокси из настроек + */ + Lampa.Settings.listener.follow('open', function (event) { + if (event.name === 'tmdb') { + event.body.find('[data-parent="proxy"]').remove(); + } + }); + + console.log( + 'TMDB-Proxy', + `v${tmdbProxy.version} started, enabled:`, + Lampa.Storage.field('proxy_tmdb') + ); + + /** + * Добавление компонента настроек + */ + Lampa.SettingsApi.addComponent({ + component: 'iptvskaz', + icon: '', + name: 'by Skaz (Optimized)' + }); + + /** + * Добавление параметра настроек + */ + Lampa.SettingsApi.addParam({ + component: 'iptvskaz', + param: { + name: 'b_skaz', + type: 'trigger', + default: false + }, + field: { + name: 'Убрать с главной трансляции', + description: 'Убирает с главной трансляцию события' + }, + onChange: function (value) { + Lampa.Noty.show('Необходимо перезайти в лампу'); + } + }); +})();