Spaces:
Paused
Paused
File size: 2,876 Bytes
13ae2ca 61767ce a15d88a b7c5456 61767ce c3b08b5 9cd41ab 61767ce 3555937 61767ce 5d6fc5f ddb3ecc 94612d2 a15d88a 9cd41ab 61767ce 5d6fc5f 94c2ba4 9cd41ab 61767ce 94612d2 5911378 61767ce ddb3ecc 9cd41ab 61767ce 2279a60 a15d88a 816e180 a15d88a 61767ce 9aa960e 61767ce 9aa960e 13ae2ca 61767ce 13ae2ca 9aa960e a15d88a 61767ce 9cd41ab d604e39 13ae2ca a2180fa cd2e4e5 61767ce d604e39 5911378 61767ce 4a7aea8 a15d88a 010f8f1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | // addon.js
const fetch = require('node-fetch');
const { addonBuilder } = require('stremio-addon-sdk');
// Javna CSV lista
const CSV_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vTe-SkouXuRu5EX8ApUjUe2mCbjHrd3OR4HJ46OH3ai2wLHwkWR5_1dIp3BDjQpq4wHgsi1_pDEeuSi/pub?output=csv';
// Round-robin API baze
const STREAM_APIS = [
'https://haxwitcher-yt-plex.hf.space',
'https://haxwitcher-yt2-plex.hf.space',
'https://haxwitcher-yt3-plex.hf.space',
'https://haxwitcher-yt4-plex.hf.space',
'https://haxwitcher-yt5-plex.hf.space'
];
let rrIndex = 0;
function getNextApi() {
const api = STREAM_APIS[rrIndex];
rrIndex = (rrIndex + 1) % STREAM_APIS.length;
return api;
}
// Izvlači YouTube ID iz URL-a
function extractId(url) {
const m = url.match(/(?:v=|\.be\/)([A-Za-z0-9_-]{11})/);
return m ? m[1] : null;
}
// Učita CSV, parsira timestamp, title i sortira po timestamp-u opadajuće
async function fetchList() {
const res = await fetch(CSV_URL);
const txt = await res.text();
return txt
.trim()
.split('\n')
.slice(1)
.map(line => {
const [ts, url, ...rest] = line.split(',');
const id = extractId(url);
if (!id) return null;
const title = rest.join(',').trim() || id;
return {
id,
name: title,
poster: `https://img.youtube.com/vi/${id}/hqdefault.jpg`,
ts: new Date(ts),
};
})
.filter(Boolean)
.sort((a, b) => b.ts - a.ts); // najnoviji prvi
}
const manifest = require('./manifest.json');
const builder = new addonBuilder(manifest);
// === Catalog handler ===
builder.defineCatalogHandler(async ({ id }) => {
if (id !== 'yt-sheet') {
return { metas: [] };
}
const list = await fetchList();
return {
metas: list.map(v => ({
id: v.id,
type: 'channel',
name: v.name, // sada se vidi title iz CSV
poster: v.poster,
}))
};
});
// === Meta handler ===
// Prikazuje title iz CSV umesto samog ID-ja
builder.defineMetaHandler(async ({ id, type }) => {
const list = await fetchList();
const entry = list.find(v => v.id === id) || {};
return {
meta: {
id,
type,
name: entry.name || id,
poster: entry.poster || `https://img.youtube.com/vi/${id}/hqdefault.jpg`,
description: '',
runtime: 0,
}
};
});
// === Stream handler (round-robin baza) ===
builder.defineStreamHandler(async ({ type, id }) => {
if (type !== 'channel') {
return { streams: [] };
}
const youtubeUrl = `https://www.youtube.com/watch?v=${id}`;
const base = getNextApi();
const apiUrl = `${base}/stream/?url=${encodeURIComponent(youtubeUrl)}&resolution=1080`;
return {
streams: [{
title: `YouTube stream`,
url: apiUrl,
isLive: false
}]
};
});
module.exports = builder.getInterface();
|