Spaces:
Paused
Paused
Delete index.js
#4
by jumannendange - opened
index.js
DELETED
|
@@ -1,633 +0,0 @@
|
|
| 1 |
-
/**
|
| 2 |
-
* JAYNES MAX TV — Node.js/Puppeteer backend
|
| 3 |
-
* Port ya kraudius_core.php (v3.2-split, PHP) kwenda Node.js.
|
| 4 |
-
*
|
| 5 |
-
* Tofauti kuu kutoka PHP:
|
| 6 |
-
* - fetchPage() inatumia Puppeteer (Chromium halisi) badala ya curl,
|
| 7 |
-
* ili kupita anti-bot ya InfinityFree (imethibitishwa kufanya kazi).
|
| 8 |
-
* - Browser instance MOJA inabaki wazi (reuse) badala ya kufunguliwa
|
| 9 |
-
* upya kila request — hii ni muhimu kwa ufanisi.
|
| 10 |
-
* - kraudius: channels 1-36 | liveblog: channels 1-52
|
| 11 |
-
* - Kwa channel 1-36: jaribu kraudius kwanza, liveblog ni fallback.
|
| 12 |
-
* - Kwa channel 37-52: liveblog pekee (kraudius haina hizo).
|
| 13 |
-
*/
|
| 14 |
-
|
| 15 |
-
const express = require('express');
|
| 16 |
-
const puppeteer = require('puppeteer');
|
| 17 |
-
|
| 18 |
-
const app = express();
|
| 19 |
-
const PORT = process.env.PORT || 7860;
|
| 20 |
-
|
| 21 |
-
// ═══════════════════════════════════════════════════════════
|
| 22 |
-
// DATA — sawa kabisa na kraudius_core.php
|
| 23 |
-
// ═══════════════════════════════════════════════════════════
|
| 24 |
-
|
| 25 |
-
const CHANNEL_NAMES = {
|
| 26 |
-
1: 'Azam Sports 1', 2: 'Azam Sports 2', 3: 'Azam Sports 3', 4: 'Azam Sports 4',
|
| 27 |
-
5: 'ZBC', 6: 'ZBC 2', 7: 'Azam One', 8: 'Azam Two', 9: 'Sinema Zetu',
|
| 28 |
-
10: 'Kix Movies', 11: 'UTV', 12: 'Cheka Plus', 13: 'Wasafi TV', 14: 'Crown TV',
|
| 29 |
-
15: 'Fubo Sports', 16: 'Premier Sports 1', 17: 'Premier Sports 2',
|
| 30 |
-
18: 'TNT Sports 1', 19: 'TNT Sports 2', 20: 'TNT Sports 3', 21: 'TNT Sports 4',
|
| 31 |
-
22: 'LaLiga TV',
|
| 32 |
-
// 23-52: zitatoka HTML (hazina jina tuli bado)
|
| 33 |
-
};
|
| 34 |
-
|
| 35 |
-
const CLEARKEY_OVERRIDE = {
|
| 36 |
-
'azam sports 1': 'c31df1600afc33799ecac543331803f2:dd2101530e222f545997d4c553787f85',
|
| 37 |
-
'azam sports 2': '739e7499125b31cc9948da8057b84cf9:1b7d44d798c351acc02f33ddfbb7682a',
|
| 38 |
-
'azam sports 3': '2f12d7b889de381a9fb5326ca3aa166d:51c2d733a54306fdf89acd4c9d4f6005',
|
| 39 |
-
'azam sports 4': 'fbcac74e355b3b5d9b6cbc56c7597dbf:5f980e872b378d88b46f656a806205c3',
|
| 40 |
-
'zbc': 'e91fec140bc5316f919b4dc9c16287d7:79884fad0dbfcdc43d3e33c82a1f1cfa',
|
| 41 |
-
'zbc 2': 'f38b03549d023f3a883997328537bf4d:90f9d2d9cc26009c437905692ad70730',
|
| 42 |
-
'azam one': 'b5cbe1bb5acf3c7f9995be428245cfcd:89f1188a11e5e000d4443eb27ca378e1',
|
| 43 |
-
'azam two': '18f515fd536b3e728e9844e77d9f0fa8:c96dfd9b65560f87a1a95b8aeda0432d',
|
| 44 |
-
'sinema zetu': 'd628ae37a8f0336b970f250d9699461e:1194c3d60bb494aabe9114ca46c2738e',
|
| 45 |
-
'kix movies': 'a7e155b282f33335ae8d553f169f443c:c3fdcfd5d509f1ed8550d76a525e34e5',
|
| 46 |
-
'utv': '31b8fc6289fe3ca698588a59d845160c:f8c4e73f419cb80db3bdf4a974e31894',
|
| 47 |
-
'cheka plus': '4dce7643f03c3327832b657d74056b6b:8b8675b9d2ff24dd7c7619d86a698231',
|
| 48 |
-
'wasafi tv': '8714fe102679348e9c76cfd315dacaa0:a8b86ceda831061c13c7c4c67bd77f8e',
|
| 49 |
-
'crown tv': 'e3eb6e0656ec3c22aa308aaa3f82c565:a7634d6defd2c255135095c45bc442fb',
|
| 50 |
-
'fubo sports': 'dc69b6159a0f9f0a4e03b3ff91cbacd5:d0dcbcd7723bc40df0bf34c9c092d51f',
|
| 51 |
-
'premier sports 1': '1444f4235529f183f0a5a486befe9cdb:e5e3fec67a1bb3472a2089c8a0a2557f',
|
| 52 |
-
'premier sports 2': '1a5df53609ebc9857898c490f4724918:77f62980d582ec541280796acf8b2d19',
|
| 53 |
-
'tnt sports 1': '294b5761cefc22d0c6312939e13d8278:52148f1042d238849f0a7813f1da8a7b',
|
| 54 |
-
'tnt sports 2': 'f288380ca4cef9ad3f27a92a08e9bb8b:9f18d26291d9230833501f7f822f6875',
|
| 55 |
-
'tnt sports 3': '1d96ab366bbe6451edf7407b58e2fa16:0116201f4a63ac5bf5787d2c610c41a7',
|
| 56 |
-
'tnt sports 4': '192b1115da041585c77200128549efa1:634e10efe4abbb14be400a3ccbac0258',
|
| 57 |
-
'laliga tv': '620e51b82596475517a27aa425c52280:2b9ba811e9c5aeafc8ae1b71cdca4d6a',
|
| 58 |
-
};
|
| 59 |
-
|
| 60 |
-
const LOGOS = {
|
| 61 |
-
'azam sports 1': 'https://i.postimg.cc/BZFnGMrq/azam-sports-1.png',
|
| 62 |
-
'azam sports 2': 'https://i.postimg.cc/BZFnGMrq/azam-sports-2.png',
|
| 63 |
-
'azam sports 3': 'https://i.postimg.cc/BZFnGMrq/azam-sports-3.png',
|
| 64 |
-
'azam sports 4': 'https://i.postimg.cc/BZFnGMrq/azam-sports-4.png',
|
| 65 |
-
'zbc': 'https://i.postimg.cc/BZFnGMrq/zbc.png',
|
| 66 |
-
'zbc 2': 'https://i.postimg.cc/BZFnGMrq/zbc2.png',
|
| 67 |
-
'azam one': 'https://i.postimg.cc/BZFnGMrq/azam-one.png',
|
| 68 |
-
'azam two': 'https://i.postimg.cc/BZFnGMrq/azam-two.png',
|
| 69 |
-
'sinema zetu': 'https://i.postimg.cc/BZFnGMrq/sinema-zetu.png',
|
| 70 |
-
'wasafi tv': 'https://i.postimg.cc/x199GSXJ/Wasafi-319ee69a217e4c351694412919fca27d.png',
|
| 71 |
-
'tnt sports 1': 'https://upload.wikimedia.org/wikipedia/en/thumb/4/49/TNT_Sports_1.svg/120px-TNT_Sports_1.svg.png',
|
| 72 |
-
'tnt sports 2': 'https://upload.wikimedia.org/wikipedia/en/thumb/4/49/TNT_Sports_1.svg/120px-TNT_Sports_1.svg.png',
|
| 73 |
-
'tnt sports 3': 'https://upload.wikimedia.org/wikipedia/en/thumb/4/49/TNT_Sports_1.svg/120px-TNT_Sports_1.svg.png',
|
| 74 |
-
'tnt sports 4': 'https://upload.wikimedia.org/wikipedia/en/thumb/4/49/TNT_Sports_1.svg/120px-TNT_Sports_1.svg.png',
|
| 75 |
-
'laliga tv': 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/LaLiga_TV_logo.svg/120px-LaLiga_TV_logo.svg.png',
|
| 76 |
-
'premier sports 1': 'https://upload.wikimedia.org/wikipedia/en/thumb/d/d0/Premier_Sports_logo.svg/120px-Premier_Sports_logo.svg.png',
|
| 77 |
-
'premier sports 2': 'https://upload.wikimedia.org/wikipedia/en/thumb/d/d0/Premier_Sports_logo.svg/120px-Premier_Sports_logo.svg.png',
|
| 78 |
-
'fubo sports': 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/FuboTV_logo.svg/120px-FuboTV_logo.svg.png',
|
| 79 |
-
};
|
| 80 |
-
|
| 81 |
-
const CATEGORIES = {
|
| 82 |
-
'azam sports 1': 'Sports', 'azam sports 2': 'Sports', 'azam sports 3': 'Sports', 'azam sports 4': 'Sports',
|
| 83 |
-
'zbc': 'News', 'zbc 2': 'News',
|
| 84 |
-
'azam one': 'Movie Channels', 'azam two': 'Movie Channels', 'sinema zetu': 'Movie Channels', 'kix movies': 'Movie Channels',
|
| 85 |
-
'utv': 'News', 'cheka plus': 'Entertainment', 'wasafi tv': 'Entertainment', 'crown tv': 'Entertainment',
|
| 86 |
-
'fubo sports': 'Sports', 'premier sports 1': 'Sports', 'premier sports 2': 'Sports',
|
| 87 |
-
'tnt sports 1': 'Sports', 'tnt sports 2': 'Sports', 'tnt sports 3': 'Sports', 'tnt sports 4': 'Sports',
|
| 88 |
-
'laliga tv': 'Sports',
|
| 89 |
-
};
|
| 90 |
-
|
| 91 |
-
const DISPLAY_NAMES = {
|
| 92 |
-
'tnt sports 1': 'TNT Sports 1', 'tnt sports 2': 'TNT Sports 2', 'tnt sports 3': 'TNT Sports 3', 'tnt sports 4': 'TNT Sports 4',
|
| 93 |
-
'laliga tv': 'LaLiga TV', 'cheka plus': 'Cheka Plus', 'utv': 'UTV', 'zbc': 'ZBC', 'zbc 2': 'ZBC 2',
|
| 94 |
-
'kix movies': 'Kix Movies', 'wasafi tv': 'Wasafi TV', 'crown tv': 'Crown TV',
|
| 95 |
-
'azam sports 1': 'Azam Sports 1', 'azam sports 2': 'Azam Sports 2', 'azam sports 3': 'Azam Sports 3', 'azam sports 4': 'Azam Sports 4',
|
| 96 |
-
'azam one': 'Azam One', 'azam two': 'Azam Two', 'sinema zetu': 'Sinema Zetu', 'fubo sports': 'Fubo Sports',
|
| 97 |
-
'premier sports 1': 'Premier Sports 1', 'premier sports 2': 'Premier Sports 2',
|
| 98 |
-
};
|
| 99 |
-
|
| 100 |
-
// ═══════════════════════════════════════════════════════════
|
| 101 |
-
// KIKOMO CHA CHANNELS KWA KILA CHANZO
|
| 102 |
-
// ═══════════════════════════════════════════════════════════
|
| 103 |
-
const KRAUDIUS_MAX_CHANNEL = 36;
|
| 104 |
-
const LIVEBLOG_MAX_CHANNEL = 52;
|
| 105 |
-
const TOTAL_CHANNELS = 52; // jumla ya app (kraudius 1-36 + liveblog 37-52)
|
| 106 |
-
|
| 107 |
-
function channelExistsForSource(source, channel) {
|
| 108 |
-
if (source === 'kraudius') return channel >= 1 && channel <= KRAUDIUS_MAX_CHANNEL;
|
| 109 |
-
if (source === 'liveblog') return channel >= 1 && channel <= LIVEBLOG_MAX_CHANNEL;
|
| 110 |
-
return false;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
function sourceUrl(source, channel) {
|
| 114 |
-
if (source === 'kraudius') return `https://kraudiustv.iceiy.com/index.php?channel=${channel}&i=1`;
|
| 115 |
-
if (source === 'liveblog') return `https://mfumo.liveblog365.com/player.php?channel=${channel}`;
|
| 116 |
-
return '';
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
function sourceLabel(source) {
|
| 120 |
-
if (source === 'kraudius') return 'KraudiusTV';
|
| 121 |
-
if (source === 'liveblog') return 'LiveBlog365';
|
| 122 |
-
return source;
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
// ═══════════════════════════════════════════════════════════
|
| 126 |
-
// HELPERS
|
| 127 |
-
// ═══════════════════════════════════════════════════════════
|
| 128 |
-
|
| 129 |
-
function normName(name) {
|
| 130 |
-
let n = name.toLowerCase().trim();
|
| 131 |
-
n = n.replace(/\s*(hd)\s*$/i, '');
|
| 132 |
-
n = n.replace(/\s+/g, ' ');
|
| 133 |
-
return n.trim();
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
function guessCategory(norm) {
|
| 137 |
-
if (/sport|bein|tnt|laliga|premier sport|fubo|sky sport|espn|fox sport|nbc sport|dazn|eleven|eurosport|supersport|canal.*sport|arena sport|setanta|gtv|osn sport|racing|horse|freesport/.test(norm)) return 'Sports';
|
| 138 |
-
if (/sinema|movie|film|hbo|azam one|azam two|mbc|kix|rock action/.test(norm)) return 'Movie Channels';
|
| 139 |
-
if (/zbc|tbc|bbc|aljazeera|utv|news/.test(norm)) return 'News';
|
| 140 |
-
if (/wasafi|crown|cheka|zamaradi|trace|entertain/.test(norm)) return 'Entertainment';
|
| 141 |
-
if (/cartoon|kid|family/.test(norm)) return 'Kids';
|
| 142 |
-
if (/nature|safari|food|history|document/.test(norm)) return 'Documentary';
|
| 143 |
-
if (/mahaasin|hope|imaan|religion/.test(norm)) return 'Religion';
|
| 144 |
-
return 'General';
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
// ═══════════════════════════════════════════════════════════
|
| 148 |
-
// PUPPETEER — browser instance MOJA, inabaki wazi (reuse)
|
| 149 |
-
// ═══════════════════════════════════════════════════════════
|
| 150 |
-
|
| 151 |
-
let browserPromise = null;
|
| 152 |
-
|
| 153 |
-
async function getBrowser() {
|
| 154 |
-
if (!browserPromise) {
|
| 155 |
-
browserPromise = puppeteer.launch({
|
| 156 |
-
headless: 'new',
|
| 157 |
-
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
|
| 158 |
-
});
|
| 159 |
-
}
|
| 160 |
-
return browserPromise;
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
// Kikomo cha pages zinazoendeshwa kwa wakati mmoja (usizidishe CPU
|
| 164 |
-
// ndogo ya free tier). Queue rahisi.
|
| 165 |
-
const MAX_CONCURRENT_PAGES = 3;
|
| 166 |
-
let activePages = 0;
|
| 167 |
-
const waitQueue = [];
|
| 168 |
-
|
| 169 |
-
function acquireSlot() {
|
| 170 |
-
return new Promise((resolve) => {
|
| 171 |
-
const tryAcquire = () => {
|
| 172 |
-
if (activePages < MAX_CONCURRENT_PAGES) {
|
| 173 |
-
activePages++;
|
| 174 |
-
resolve();
|
| 175 |
-
} else {
|
| 176 |
-
waitQueue.push(tryAcquire);
|
| 177 |
-
}
|
| 178 |
-
};
|
| 179 |
-
tryAcquire();
|
| 180 |
-
});
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
function releaseSlot() {
|
| 184 |
-
activePages--;
|
| 185 |
-
const next = waitQueue.shift();
|
| 186 |
-
if (next) next();
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
async function fetchPage(url) {
|
| 190 |
-
await acquireSlot();
|
| 191 |
-
let page;
|
| 192 |
-
try {
|
| 193 |
-
const browser = await getBrowser();
|
| 194 |
-
page = await browser.newPage();
|
| 195 |
-
await page.setUserAgent(
|
| 196 |
-
'Mozilla/5.0 (Linux; Android 13; SM-G991B) AppleWebKit/537.36 ' +
|
| 197 |
-
'(KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36'
|
| 198 |
-
);
|
| 199 |
-
const response = await page.goto(url, { waitUntil: 'networkidle2', timeout: 20000 });
|
| 200 |
-
const html = await page.content();
|
| 201 |
-
const code = response ? response.status() : 0;
|
| 202 |
-
return { html: html || '', code, error: '' };
|
| 203 |
-
} catch (err) {
|
| 204 |
-
return { html: '', code: 0, error: err.message };
|
| 205 |
-
} finally {
|
| 206 |
-
if (page) await page.close().catch(() => {});
|
| 207 |
-
releaseSlot();
|
| 208 |
-
}
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
// ═══════════════════════════════════════════════════════════
|
| 212 |
-
// STREAM EXTRACTOR — port ya extractStream() ya PHP
|
| 213 |
-
// ═══════════════════════════════════════════════════════════
|
| 214 |
-
|
| 215 |
-
function firstMatch(html, patterns) {
|
| 216 |
-
for (const p of patterns) {
|
| 217 |
-
const m = html.match(p);
|
| 218 |
-
if (m) return m[1].trim();
|
| 219 |
-
}
|
| 220 |
-
return '';
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
function extractStream(html) {
|
| 224 |
-
const mpdUrl = firstMatch(html, [
|
| 225 |
-
/const\s+mpdUrl\s*=\s*["']([^"']+)["']/,
|
| 226 |
-
/var\s+mpdUrl\s*=\s*["']([^"']+)["']/,
|
| 227 |
-
/let\s+mpdUrl\s*=\s*["']([^"']+)["']/,
|
| 228 |
-
/mpdUrl\s*[:=]\s*["']([^"']+\.mpd[^"']*)["']/,
|
| 229 |
-
/source\s*[:=]\s*["']([^"']+\.mpd[^"']*)["']/,
|
| 230 |
-
/["'](https?:\/\/[^"']{10,}\.mpd(?:\?[^"']*)?)["']/,
|
| 231 |
-
]);
|
| 232 |
-
|
| 233 |
-
const hlsUrl = firstMatch(html, [
|
| 234 |
-
/const\s+hlsUrl\s*=\s*["']([^"']+)["']/,
|
| 235 |
-
/var\s+hlsUrl\s*=\s*["']([^"']+)["']/,
|
| 236 |
-
/let\s+hlsUrl\s*=\s*["']([^"']+)["']/,
|
| 237 |
-
/hlsUrl\s*[:=]\s*["']([^"']+\.m3u8[^"']*)["']/,
|
| 238 |
-
/["'](https?:\/\/[^"']{10,}\.m3u8(?:\?[^"']*)?)["']/,
|
| 239 |
-
]);
|
| 240 |
-
|
| 241 |
-
let mp4Url = '';
|
| 242 |
-
if (!mpdUrl && !hlsUrl) {
|
| 243 |
-
mp4Url = firstMatch(html, [
|
| 244 |
-
/["'](https?:\/\/[^"']{10,}\.mp4(?:\?[^"']*)?)["']/,
|
| 245 |
-
/<source[^>]+src=["']([^"']+\.mp4[^"']*)["']/,
|
| 246 |
-
]);
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
let clearKey = firstMatch(html, [
|
| 250 |
-
/const\s+clearKey\s*=\s*["']([a-f0-9]{32}:[a-f0-9]{32})["']/,
|
| 251 |
-
/var\s+clearKey\s*=\s*["']([a-f0-9]{32}:[a-f0-9]{32})["']/,
|
| 252 |
-
/clearKey\s*[:=]\s*["']([a-f0-9]{32}:[a-f0-9]{32})["']/,
|
| 253 |
-
/["']([a-f0-9]{32}:[a-f0-9]{32})["']/,
|
| 254 |
-
]);
|
| 255 |
-
|
| 256 |
-
if (!clearKey) {
|
| 257 |
-
const kidMatch = html.match(/["']?(?:kid|KID)["']?\s*[:=]\s*["']([a-f0-9]{32})["']/);
|
| 258 |
-
const keyMatch = html.match(/["']?(?:key|KEY)["']?\s*[:=]\s*["']([a-f0-9]{32})["']/);
|
| 259 |
-
if (kidMatch && keyMatch) clearKey = `${kidMatch[1]}:${keyMatch[1]}`;
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
let licenseUrl = '';
|
| 263 |
-
if (!clearKey) {
|
| 264 |
-
licenseUrl = firstMatch(html, [
|
| 265 |
-
/licenseUrl\s*[:=]\s*["']([^"']+)["']/,
|
| 266 |
-
/license_url\s*[:=]\s*["']([^"']+)["']/,
|
| 267 |
-
]);
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
let name = '';
|
| 271 |
-
const titleMatch = html.match(/<title[^>]*>([^<]+)<\/title>/i);
|
| 272 |
-
if (titleMatch) {
|
| 273 |
-
const raw = titleMatch[1].trim();
|
| 274 |
-
let n = raw.replace(/\s*[-–|:]\s*(player|live|stream|tv|channel|watch).*$/i, '').trim();
|
| 275 |
-
n = n.replace(/\s*[-–|]\s*.*$/, '').trim();
|
| 276 |
-
name = n.length > 60 ? raw : n;
|
| 277 |
-
}
|
| 278 |
-
if (!name) {
|
| 279 |
-
const hMatch = html.match(/<h[1-3][^>]*>([^<]+)<\/h[1-3]>/i);
|
| 280 |
-
if (hMatch) name = hMatch[1].replace(/<[^>]*>/g, '').trim();
|
| 281 |
-
}
|
| 282 |
-
|
| 283 |
-
const streamUrl = mpdUrl || hlsUrl || mp4Url;
|
| 284 |
-
|
| 285 |
-
// Amua "type" kutoka extension HALISI ya streamUrl iliyochaguliwa
|
| 286 |
-
// mwishoni (siyo kutoka variable tofauti) — hii inaepuka hitilafu
|
| 287 |
-
// ya kusema "DASH" wakati URL ni .m3u8 (au kinyume chake) endapo
|
| 288 |
-
// mpdUrl/hlsUrl zilipata match isiyo sahihi kwenye HTML.
|
| 289 |
-
let type = '';
|
| 290 |
-
if (/\.mpd(\?|$)/i.test(streamUrl)) type = 'DASH';
|
| 291 |
-
else if (/\.m3u8(\?|$)/i.test(streamUrl)) type = 'HLS';
|
| 292 |
-
else if (/\.mp4(\?|$)/i.test(streamUrl)) type = 'MP4';
|
| 293 |
-
else type = mpdUrl ? 'DASH' : (hlsUrl ? 'HLS' : (mp4Url ? 'MP4' : ''));
|
| 294 |
-
|
| 295 |
-
const drm = clearKey ? 'CLEARKEY' : (licenseUrl ? 'WIDEVINE' : 'NONE');
|
| 296 |
-
|
| 297 |
-
return { name, stream_url: streamUrl, type, drm, clearkey: clearKey, license_url: licenseUrl };
|
| 298 |
-
}
|
| 299 |
-
|
| 300 |
-
// ═══════════════════════════════════════════════════════════
|
| 301 |
-
// PROCESS CHANNEL — port ya processChannel() ya PHP
|
| 302 |
-
// ═══════════════════════════════════════════════════════════
|
| 303 |
-
|
| 304 |
-
async function processChannel(src, chNo) {
|
| 305 |
-
const url = sourceUrl(src, chNo);
|
| 306 |
-
const t0 = Date.now();
|
| 307 |
-
const result = await fetchPage(url);
|
| 308 |
-
const ms = Date.now() - t0;
|
| 309 |
-
|
| 310 |
-
if (!result.html) {
|
| 311 |
-
return {
|
| 312 |
-
ok: false, channel: chNo, source: sourceLabel(src),
|
| 313 |
-
error: result.error || 'Empty response', code: result.code, ms,
|
| 314 |
-
};
|
| 315 |
-
}
|
| 316 |
-
|
| 317 |
-
const ext = extractStream(result.html);
|
| 318 |
-
|
| 319 |
-
const rawName = CHANNEL_NAMES[chNo] || ext.name || `Channel ${chNo}`;
|
| 320 |
-
const norm = normName(rawName);
|
| 321 |
-
const finalName = DISPLAY_NAMES[norm] || rawName;
|
| 322 |
-
|
| 323 |
-
let ck = ext.clearkey;
|
| 324 |
-
let drm = ext.drm;
|
| 325 |
-
if (!ck && CLEARKEY_OVERRIDE[norm]) {
|
| 326 |
-
ck = CLEARKEY_OVERRIDE[norm];
|
| 327 |
-
drm = 'CLEARKEY';
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
let clearkeyObj = null;
|
| 331 |
-
if (ck && ck.includes(':')) {
|
| 332 |
-
const [kid, key] = ck.split(':');
|
| 333 |
-
clearkeyObj = { kid, key };
|
| 334 |
-
}
|
| 335 |
-
|
| 336 |
-
return {
|
| 337 |
-
ok: !!ext.stream_url,
|
| 338 |
-
channel: chNo,
|
| 339 |
-
source: sourceLabel(src),
|
| 340 |
-
name: finalName,
|
| 341 |
-
norm,
|
| 342 |
-
stream_url: ext.stream_url,
|
| 343 |
-
type: ext.type,
|
| 344 |
-
drm,
|
| 345 |
-
clearkey: clearkeyObj,
|
| 346 |
-
license_url: ext.license_url || undefined,
|
| 347 |
-
code: result.code,
|
| 348 |
-
ms,
|
| 349 |
-
};
|
| 350 |
-
}
|
| 351 |
-
|
| 352 |
-
/**
|
| 353 |
-
* Inajaribu vyanzo kwa mfuatano (kraudius kisha liveblog kwa 1-36,
|
| 354 |
-
* liveblog pekee kwa 37-52), inarudisha ya kwanza yenye stream_url.
|
| 355 |
-
*/
|
| 356 |
-
async function getChannelData(chNo, preferredSource) {
|
| 357 |
-
let sourcesToTry;
|
| 358 |
-
if (preferredSource) {
|
| 359 |
-
sourcesToTry = [preferredSource];
|
| 360 |
-
} else if (chNo <= KRAUDIUS_MAX_CHANNEL) {
|
| 361 |
-
sourcesToTry = ['kraudius', 'liveblog'];
|
| 362 |
-
} else {
|
| 363 |
-
sourcesToTry = ['liveblog'];
|
| 364 |
-
}
|
| 365 |
-
|
| 366 |
-
let lastError = null;
|
| 367 |
-
for (const src of sourcesToTry) {
|
| 368 |
-
if (!channelExistsForSource(src, chNo)) continue;
|
| 369 |
-
const data = await processChannel(src, chNo);
|
| 370 |
-
if (data.ok && data.stream_url) return data;
|
| 371 |
-
lastError = data;
|
| 372 |
-
}
|
| 373 |
-
return lastError; // ya mwisho iliyojaribiwa (yenye error), au null
|
| 374 |
-
}
|
| 375 |
-
|
| 376 |
-
// ═══════════════════════════════════════════════════════════
|
| 377 |
-
// CACHE — faili ya sekunde chache kwa kila channel
|
| 378 |
-
// ═══════════════════════════════════════════════════════════
|
| 379 |
-
|
| 380 |
-
const cache = new Map();
|
| 381 |
-
const CACHE_TTL_MS = 60 * 1000; // sekunde 60
|
| 382 |
-
|
| 383 |
-
function getCached(key) {
|
| 384 |
-
const entry = cache.get(key);
|
| 385 |
-
if (entry && Date.now() - entry.time < CACHE_TTL_MS) return entry.data;
|
| 386 |
-
return null;
|
| 387 |
-
}
|
| 388 |
-
function setCached(key, data) {
|
| 389 |
-
cache.set(key, { data, time: Date.now() });
|
| 390 |
-
}
|
| 391 |
-
|
| 392 |
-
// ═══════════════════════════════════════════════════════════
|
| 393 |
-
// SUPABASE — kuandika (upsert) matokeo ya refresh
|
| 394 |
-
// ═══════════════════════════════════════════════════════════
|
| 395 |
-
|
| 396 |
-
const SUPABASE_URL = process.env.SUPABASE_URL || 'https://xxxxxxxxxxxx.supabase.co';
|
| 397 |
-
const SUPABASE_SERVICE_KEY = process.env.SUPABASE_SERVICE_KEY || 'WEKA_SERVICE_ROLE_KEY_YAKO';
|
| 398 |
-
// Tumia service_role key (siyo anon) kwa sababu server-to-server
|
| 399 |
-
// inahitaji ruhusa ya kuandika (insert/update), si soma tu.
|
| 400 |
-
|
| 401 |
-
// Funguo ya siri kulinda /refresh isiitwe na mtu yeyote asiyeruhusiwa
|
| 402 |
-
// (weka thamani yako mwenyewe, tumia hiyo hiyo kwenye cron-job.org)
|
| 403 |
-
const REFRESH_SECRET = process.env.REFRESH_SECRET || 'badilisha-hii-kuwa-siri-yako';
|
| 404 |
-
|
| 405 |
-
async function upsertChannelToSupabase(channelData) {
|
| 406 |
-
const row = {
|
| 407 |
-
channel_id: channelData.channel,
|
| 408 |
-
name: channelData.name,
|
| 409 |
-
source: channelData.source,
|
| 410 |
-
url: channelData.url,
|
| 411 |
-
mpd: channelData.mpd || null,
|
| 412 |
-
type: channelData.type,
|
| 413 |
-
category: channelData.norm ? guessCategory(channelData.norm) : 'General',
|
| 414 |
-
clearkey_kid: channelData.clearkey ? channelData.clearkey.kid : null,
|
| 415 |
-
clearkey_key: channelData.clearkey ? channelData.clearkey.key : null,
|
| 416 |
-
updated_at: new Date().toISOString(),
|
| 417 |
-
};
|
| 418 |
-
|
| 419 |
-
const res = await fetch(`${SUPABASE_URL}/rest/v1/channel_streams`, {
|
| 420 |
-
method: 'POST',
|
| 421 |
-
headers: {
|
| 422 |
-
'apikey': SUPABASE_SERVICE_KEY,
|
| 423 |
-
'Authorization': `Bearer ${SUPABASE_SERVICE_KEY}`,
|
| 424 |
-
'Content-Type': 'application/json',
|
| 425 |
-
'Prefer': 'resolution=merge-duplicates', // upsert kwa unique(channel_id)
|
| 426 |
-
},
|
| 427 |
-
body: JSON.stringify(row),
|
| 428 |
-
});
|
| 429 |
-
|
| 430 |
-
if (!res.ok) {
|
| 431 |
-
const text = await res.text().catch(() => '');
|
| 432 |
-
throw new Error(`Supabase upsert HTTP ${res.status}: ${text}`);
|
| 433 |
-
}
|
| 434 |
-
}
|
| 435 |
-
|
| 436 |
-
// ═══════════════════════════════════════════════════════════
|
| 437 |
-
// REFRESH TIERS
|
| 438 |
-
// FAST (channels 1-15) — kila dakika 30
|
| 439 |
-
// SLOW (channels 16-52) — kila masaa 24
|
| 440 |
-
// ═══════════════════════════════════════════════════════════
|
| 441 |
-
|
| 442 |
-
const FAST_TIER_IDS = Array.from({ length: 15 }, (_, i) => i + 1); // 1-15
|
| 443 |
-
const SLOW_TIER_IDS = Array.from({ length: 52 - 15 }, (_, i) => i + 16); // 16-52
|
| 444 |
-
|
| 445 |
-
const FAST_INTERVAL_MS = 30 * 60 * 1000; // dakika 30
|
| 446 |
-
const SLOW_INTERVAL_MS = 24 * 60 * 60 * 1000; // masaa 24
|
| 447 |
-
|
| 448 |
-
let isRefreshingFast = false;
|
| 449 |
-
let isRefreshingSlow = false;
|
| 450 |
-
let lastRefresh = { fast: null, slow: null };
|
| 451 |
-
|
| 452 |
-
async function refreshTier(ids, tierName) {
|
| 453 |
-
const results = { ok: 0, fail: 0, errors: [] };
|
| 454 |
-
for (const id of ids) {
|
| 455 |
-
try {
|
| 456 |
-
const data = await getChannelData(id, null);
|
| 457 |
-
if (data && data.ok && data.stream_url) {
|
| 458 |
-
const isDash = data.type === 'DASH';
|
| 459 |
-
await upsertChannelToSupabase({
|
| 460 |
-
channel: id,
|
| 461 |
-
name: data.name,
|
| 462 |
-
source: data.source,
|
| 463 |
-
url: data.stream_url,
|
| 464 |
-
mpd: isDash ? data.stream_url : null,
|
| 465 |
-
type: data.type,
|
| 466 |
-
norm: data.norm,
|
| 467 |
-
clearkey: data.clearkey,
|
| 468 |
-
});
|
| 469 |
-
results.ok++;
|
| 470 |
-
} else {
|
| 471 |
-
results.fail++;
|
| 472 |
-
results.errors.push({ channel: id, error: (data && data.error) || 'no stream' });
|
| 473 |
-
}
|
| 474 |
-
} catch (err) {
|
| 475 |
-
results.fail++;
|
| 476 |
-
results.errors.push({ channel: id, error: err.message });
|
| 477 |
-
}
|
| 478 |
-
}
|
| 479 |
-
lastRefresh[tierName] = { time: new Date().toISOString(), ...results };
|
| 480 |
-
return results;
|
| 481 |
-
}
|
| 482 |
-
|
| 483 |
-
async function runFastRefresh() {
|
| 484 |
-
if (isRefreshingFast) return { skipped: true, reason: 'already running' };
|
| 485 |
-
isRefreshingFast = true;
|
| 486 |
-
try {
|
| 487 |
-
return await refreshTier(FAST_TIER_IDS, 'fast');
|
| 488 |
-
} finally {
|
| 489 |
-
isRefreshingFast = false;
|
| 490 |
-
}
|
| 491 |
-
}
|
| 492 |
-
|
| 493 |
-
async function runSlowRefresh() {
|
| 494 |
-
if (isRefreshingSlow) return { skipped: true, reason: 'already running' };
|
| 495 |
-
isRefreshingSlow = true;
|
| 496 |
-
try {
|
| 497 |
-
return await refreshTier(SLOW_TIER_IDS, 'slow');
|
| 498 |
-
} finally {
|
| 499 |
-
isRefreshingSlow = false;
|
| 500 |
-
}
|
| 501 |
-
}
|
| 502 |
-
|
| 503 |
-
// Ratiba ya NDANI (setInterval) — inafanya kazi Space ikiwa "wazi".
|
| 504 |
-
// Hii ni ya ziada juu ya cron-job.org (nje), si badala yake — kama
|
| 505 |
-
// Space ililala na cron-job.org ikaigusa, refresh itaanza upya papo
|
| 506 |
-
// hapo (onPageFinished ya kwanza), kisha setInterval inaendelea
|
| 507 |
-
// kutoka hapo mpaka Space ilale tena.
|
| 508 |
-
setInterval(() => { runFastRefresh().catch((e) => console.error('fast refresh error:', e.message)); }, FAST_INTERVAL_MS);
|
| 509 |
-
setInterval(() => { runSlowRefresh().catch((e) => console.error('slow refresh error:', e.message)); }, SLOW_INTERVAL_MS);
|
| 510 |
-
|
| 511 |
-
// ═══════════════════════════════════════════════════════════
|
| 512 |
-
// ROUTES
|
| 513 |
-
// ═══════════════════════════════════════════════════════════
|
| 514 |
-
|
| 515 |
-
app.get('/', (req, res) => {
|
| 516 |
-
res.json({
|
| 517 |
-
name: 'JAYNES MAX TV backend (Node.js/Puppeteer)',
|
| 518 |
-
endpoints: ['/api/content/channels', '/api/channel/:id'],
|
| 519 |
-
total_channels: TOTAL_CHANNELS,
|
| 520 |
-
});
|
| 521 |
-
});
|
| 522 |
-
|
| 523 |
-
app.get('/api/content/channels', (req, res) => {
|
| 524 |
-
const channels = [];
|
| 525 |
-
for (let id = 1; id <= TOTAL_CHANNELS; id++) {
|
| 526 |
-
const rawName = CHANNEL_NAMES[id] || `Channel ${id}`;
|
| 527 |
-
const norm = normName(rawName);
|
| 528 |
-
const finalName = DISPLAY_NAMES[norm] || rawName;
|
| 529 |
-
const image = LOGOS[norm] || undefined;
|
| 530 |
-
const entry = { id, name: finalName };
|
| 531 |
-
if (image) entry.image = image;
|
| 532 |
-
channels.push(entry);
|
| 533 |
-
}
|
| 534 |
-
res.json({ success: true, total: channels.length, channels });
|
| 535 |
-
});
|
| 536 |
-
|
| 537 |
-
// Endpoint ya NJE — cron-job.org inapiga hii kwa ratiba (dakika 30
|
| 538 |
-
// kwa "fast", masaa 24 kwa "slow"). Hii ndiyo pia inayoiamsha Space
|
| 539 |
-
// ikiwa imelala (HF Space "kulala" kunatatuliwa moja kwa moja na
|
| 540 |
-
// request yoyote ya HTTP inayoifikia).
|
| 541 |
-
//
|
| 542 |
-
// MUHIMU: refresh ya channels kadhaa kwa Puppeteer inachukua muda
|
| 543 |
-
// mrefu kuliko timeout ya cron-job.org (kawaida sekunde 30). Kwa
|
| 544 |
-
// hiyo endpoint hii INARUDISHA JIBU MARA MOJA (haisubiri refresh
|
| 545 |
-
// ikamilike), na refresh inaendelea NYUMA (background). Tumia
|
| 546 |
-
// GET /status kuona hali/matokeo ya refresh ya mwisho.
|
| 547 |
-
app.get('/refresh', (req, res) => {
|
| 548 |
-
if (req.query.key !== REFRESH_SECRET) {
|
| 549 |
-
return res.status(403).json({ success: false, error: 'Funguo si sahihi' });
|
| 550 |
-
}
|
| 551 |
-
|
| 552 |
-
const tier = req.query.tier || 'all';
|
| 553 |
-
const started = [];
|
| 554 |
-
|
| 555 |
-
if ((tier === 'fast' || tier === 'all') && !isRefreshingFast) {
|
| 556 |
-
started.push('fast');
|
| 557 |
-
runFastRefresh().catch((e) => console.error('fast refresh error:', e.message));
|
| 558 |
-
}
|
| 559 |
-
if ((tier === 'slow' || tier === 'all') && !isRefreshingSlow) {
|
| 560 |
-
started.push('slow');
|
| 561 |
-
runSlowRefresh().catch((e) => console.error('slow refresh error:', e.message));
|
| 562 |
-
}
|
| 563 |
-
|
| 564 |
-
// Jibu la HARAKA — halisubiri refresh ikamilike kabisa
|
| 565 |
-
res.json({
|
| 566 |
-
success: true,
|
| 567 |
-
tier,
|
| 568 |
-
message: started.length
|
| 569 |
-
? `Refresh imeanza nyuma (background) kwa: ${started.join(', ')}. Tumia GET /status kuona matokeo.`
|
| 570 |
-
: 'Refresh tayari inaendelea (au haikuombwa) — angalia /status.',
|
| 571 |
-
already_running: {
|
| 572 |
-
fast: isRefreshingFast,
|
| 573 |
-
slow: isRefreshingSlow,
|
| 574 |
-
},
|
| 575 |
-
});
|
| 576 |
-
});
|
| 577 |
-
|
| 578 |
-
app.get('/status', (req, res) => {
|
| 579 |
-
res.json({
|
| 580 |
-
success: true,
|
| 581 |
-
fast_tier: { channels: FAST_TIER_IDS, interval_minutes: 30, last_refresh: lastRefresh.fast, running: isRefreshingFast },
|
| 582 |
-
slow_tier: { channels: SLOW_TIER_IDS, interval_hours: 24, last_refresh: lastRefresh.slow, running: isRefreshingSlow },
|
| 583 |
-
});
|
| 584 |
-
});
|
| 585 |
-
|
| 586 |
-
app.get('/api/channel/:id', async (req, res) => {
|
| 587 |
-
const id = parseInt(req.params.id, 10);
|
| 588 |
-
const preferredSource = req.query.source ? String(req.query.source) : null;
|
| 589 |
-
|
| 590 |
-
if (!id || id < 1 || id > TOTAL_CHANNELS) {
|
| 591 |
-
return res.status(404).json({
|
| 592 |
-
success: false,
|
| 593 |
-
error: `Channel id lazima iwe kati ya 1 na ${TOTAL_CHANNELS}`,
|
| 594 |
-
});
|
| 595 |
-
}
|
| 596 |
-
|
| 597 |
-
const cacheKey = `${id}:${preferredSource || 'auto'}`;
|
| 598 |
-
const cached = getCached(cacheKey);
|
| 599 |
-
if (cached) {
|
| 600 |
-
return res.json({ ...cached, cached: true });
|
| 601 |
-
}
|
| 602 |
-
|
| 603 |
-
const data = await getChannelData(id, preferredSource);
|
| 604 |
-
|
| 605 |
-
if (!data || !data.ok || !data.stream_url) {
|
| 606 |
-
return res.status(502).json({
|
| 607 |
-
success: false,
|
| 608 |
-
channel: id,
|
| 609 |
-
error: (data && data.error) || 'Imeshindwa kupata stream kutoka vyanzo vyote',
|
| 610 |
-
});
|
| 611 |
-
}
|
| 612 |
-
|
| 613 |
-
const isDash = data.type === 'DASH';
|
| 614 |
-
const result = {
|
| 615 |
-
success: true,
|
| 616 |
-
channel: id,
|
| 617 |
-
name: data.name,
|
| 618 |
-
source: data.source,
|
| 619 |
-
url: data.stream_url,
|
| 620 |
-
mpd: isDash ? data.stream_url : undefined,
|
| 621 |
-
type: data.type,
|
| 622 |
-
clearkey: data.clearkey || undefined,
|
| 623 |
-
};
|
| 624 |
-
// ondoa fields undefined
|
| 625 |
-
Object.keys(result).forEach((k) => result[k] === undefined && delete result[k]);
|
| 626 |
-
|
| 627 |
-
setCached(cacheKey, result);
|
| 628 |
-
res.json(result);
|
| 629 |
-
});
|
| 630 |
-
|
| 631 |
-
app.listen(PORT, () => {
|
| 632 |
-
console.log(`JAYNES MAX TV backend (Node.js) inaendesha kwenye port ${PORT}`);
|
| 633 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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