Spaces:
Paused
Paused
Update addon.js
Browse files
addon.js
CHANGED
|
@@ -2,68 +2,88 @@
|
|
| 2 |
const fetch = require('node-fetch');
|
| 3 |
const { addonBuilder } = require('stremio-addon-sdk');
|
| 4 |
|
|
|
|
| 5 |
const CSV_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vTe-SkouXuRu5EX8ApUjUe2mCbjHrd3OR4HJ46OH3ai2wLHwkWR5_1dIp3BDjQpq4wHgsi1_pDEeuSi/pub?output=csv';
|
|
|
|
|
|
|
| 6 |
function extractId(url) {
|
| 7 |
const m = url.match(/(?:v=|\.be\/)([A-Za-z0-9_-]{11})/);
|
| 8 |
return m ? m[1] : null;
|
| 9 |
}
|
|
|
|
|
|
|
| 10 |
async function fetchList() {
|
| 11 |
const res = await fetch(CSV_URL);
|
| 12 |
const txt = await res.text();
|
| 13 |
-
return txt
|
|
|
|
|
|
|
|
|
|
| 14 |
.map(line => {
|
| 15 |
const [ts, url, ...rest] = line.split(',');
|
| 16 |
-
const id
|
| 17 |
if (!id) return null;
|
| 18 |
-
const title = rest.join(',');
|
| 19 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
})
|
| 21 |
-
.filter(Boolean)
|
|
|
|
| 22 |
}
|
| 23 |
|
| 24 |
const manifest = require('./manifest.json');
|
| 25 |
const builder = new addonBuilder(manifest);
|
| 26 |
|
| 27 |
-
//
|
| 28 |
builder.defineCatalogHandler(async ({ id }) => {
|
| 29 |
-
if (id !== 'yt-sheet')
|
|
|
|
|
|
|
| 30 |
const list = await fetchList();
|
| 31 |
return {
|
| 32 |
metas: list.map(v => ({
|
| 33 |
id: v.id,
|
| 34 |
type: 'channel',
|
| 35 |
-
name: v.name,
|
| 36 |
-
poster: v.poster
|
| 37 |
}))
|
| 38 |
};
|
| 39 |
});
|
| 40 |
-
builder.defineMetaHandler(async ({ id, type }) => ({
|
| 41 |
-
meta: {
|
| 42 |
-
id,
|
| 43 |
-
type,
|
| 44 |
-
name: id,
|
| 45 |
-
poster: `https://img.youtube.com/vi/${id}/hqdefault.jpg`,
|
| 46 |
-
description: '',
|
| 47 |
-
runtime: 0
|
| 48 |
-
}
|
| 49 |
-
}));
|
| 50 |
|
| 51 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
builder.defineStreamHandler(async ({ type, id }) => {
|
| 53 |
if (type !== 'channel') {
|
| 54 |
return { streams: [] };
|
| 55 |
}
|
| 56 |
-
|
| 57 |
-
// Sastavi URL ka tvom HF yt-dlp end-pointu
|
| 58 |
const youtubeUrl = `https://www.youtube.com/watch?v=${id}`;
|
| 59 |
const apiUrl = `https://haxwitcher-yt-plex.hf.space/download/`
|
| 60 |
+ `?url=${encodeURIComponent(youtubeUrl)}`
|
| 61 |
+ `&resolution=1080&mode=url`;
|
| 62 |
|
| 63 |
-
// NE pokušavamo JSON parsing, samo vraćamo direktan URL
|
| 64 |
return {
|
| 65 |
streams: [{
|
| 66 |
-
title: `YouTube
|
| 67 |
url: apiUrl,
|
| 68 |
isLive: false
|
| 69 |
}]
|
|
|
|
| 2 |
const fetch = require('node-fetch');
|
| 3 |
const { addonBuilder } = require('stremio-addon-sdk');
|
| 4 |
|
| 5 |
+
// Javna CSV lista
|
| 6 |
const CSV_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vTe-SkouXuRu5EX8ApUjUe2mCbjHrd3OR4HJ46OH3ai2wLHwkWR5_1dIp3BDjQpq4wHgsi1_pDEeuSi/pub?output=csv';
|
| 7 |
+
|
| 8 |
+
// Izvlači YouTube ID iz URL-a
|
| 9 |
function extractId(url) {
|
| 10 |
const m = url.match(/(?:v=|\.be\/)([A-Za-z0-9_-]{11})/);
|
| 11 |
return m ? m[1] : null;
|
| 12 |
}
|
| 13 |
+
|
| 14 |
+
// Učita CSV, parsira timestamp, title i sortira po timestamp-u opadajuće
|
| 15 |
async function fetchList() {
|
| 16 |
const res = await fetch(CSV_URL);
|
| 17 |
const txt = await res.text();
|
| 18 |
+
return txt
|
| 19 |
+
.trim()
|
| 20 |
+
.split('\n')
|
| 21 |
+
.slice(1)
|
| 22 |
.map(line => {
|
| 23 |
const [ts, url, ...rest] = line.split(',');
|
| 24 |
+
const id = extractId(url);
|
| 25 |
if (!id) return null;
|
| 26 |
+
const title = rest.join(',').trim() || id;
|
| 27 |
+
return {
|
| 28 |
+
id,
|
| 29 |
+
name: title,
|
| 30 |
+
poster: `https://img.youtube.com/vi/${id}/hqdefault.jpg`,
|
| 31 |
+
ts: new Date(ts),
|
| 32 |
+
};
|
| 33 |
})
|
| 34 |
+
.filter(Boolean)
|
| 35 |
+
.sort((a, b) => b.ts - a.ts); // najnoviji prvi
|
| 36 |
}
|
| 37 |
|
| 38 |
const manifest = require('./manifest.json');
|
| 39 |
const builder = new addonBuilder(manifest);
|
| 40 |
|
| 41 |
+
// === Catalog handler ===
|
| 42 |
builder.defineCatalogHandler(async ({ id }) => {
|
| 43 |
+
if (id !== 'yt-sheet') {
|
| 44 |
+
return { metas: [] };
|
| 45 |
+
}
|
| 46 |
const list = await fetchList();
|
| 47 |
return {
|
| 48 |
metas: list.map(v => ({
|
| 49 |
id: v.id,
|
| 50 |
type: 'channel',
|
| 51 |
+
name: v.name, // sada se vidi title iz CSV
|
| 52 |
+
poster: v.poster,
|
| 53 |
}))
|
| 54 |
};
|
| 55 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
// === Meta handler ===
|
| 58 |
+
// Prikazuje title iz CSV umesto samog ID-ja
|
| 59 |
+
builder.defineMetaHandler(async ({ id, type }) => {
|
| 60 |
+
const list = await fetchList();
|
| 61 |
+
const entry = list.find(v => v.id === id) || {};
|
| 62 |
+
return {
|
| 63 |
+
meta: {
|
| 64 |
+
id,
|
| 65 |
+
type,
|
| 66 |
+
name: entry.name || id,
|
| 67 |
+
poster: entry.poster || `https://img.youtube.com/vi/${id}/hqdefault.jpg`,
|
| 68 |
+
description: '',
|
| 69 |
+
runtime: 0,
|
| 70 |
+
}
|
| 71 |
+
};
|
| 72 |
+
});
|
| 73 |
+
|
| 74 |
+
// === Stream handler ostaje nepromenjen ===
|
| 75 |
builder.defineStreamHandler(async ({ type, id }) => {
|
| 76 |
if (type !== 'channel') {
|
| 77 |
return { streams: [] };
|
| 78 |
}
|
|
|
|
|
|
|
| 79 |
const youtubeUrl = `https://www.youtube.com/watch?v=${id}`;
|
| 80 |
const apiUrl = `https://haxwitcher-yt-plex.hf.space/download/`
|
| 81 |
+ `?url=${encodeURIComponent(youtubeUrl)}`
|
| 82 |
+ `&resolution=1080&mode=url`;
|
| 83 |
|
|
|
|
| 84 |
return {
|
| 85 |
streams: [{
|
| 86 |
+
title: `YouTube stream`,
|
| 87 |
url: apiUrl,
|
| 88 |
isLive: false
|
| 89 |
}]
|