mirror of
https://gitlab.com/vyla-entertainment/sdk.git
synced 2026-11-19 16:47:24 -05:00
chore: improve Socket.dev security and quality scores by removing node-tls-client, eliminating environment variable access and obfuscation patterns, refining package metadata, and cleaning up unused code, removed manga and cinemaarmy
This commit is contained in:
37
package.json
37
package.json
@@ -21,17 +21,44 @@
|
|||||||
"description": "Vyla's multi-provider stream scraper SDK",
|
"description": "Vyla's multi-provider stream scraper SDK",
|
||||||
"main": "src/sdk.js",
|
"main": "src/sdk.js",
|
||||||
"types": "src/sdk.d.ts",
|
"types": "src/sdk.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./src/sdk.d.ts",
|
||||||
|
"import": "./src/sdk.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/",
|
||||||
|
"README.md",
|
||||||
|
"LICENSE"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/vyla-entertainment/sdk.git"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/vyla-entertainment/sdk#readme",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/vyla-entertainment/sdk/issues"
|
||||||
|
},
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [
|
||||||
|
"vyla",
|
||||||
|
"sdk",
|
||||||
|
"streaming",
|
||||||
|
"scraper",
|
||||||
|
"tmdb",
|
||||||
|
"hls",
|
||||||
|
"subtitles"
|
||||||
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dotenv": "^17.4.2"
|
"dotenv": "17.4.2"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"node-tls-client": "^2.1.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,25 +254,6 @@ export const SOURCES = [
|
|||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
key: 'cinemaarmy',
|
|
||||||
label: 'CinemaArmy',
|
|
||||||
sourceFile: 'cinemaarmy',
|
|
||||||
proxyParam: 'ca',
|
|
||||||
timeout: 30000,
|
|
||||||
jitter: 500,
|
|
||||||
retries: 2,
|
|
||||||
multiUrl: true,
|
|
||||||
dedicated: true,
|
|
||||||
cdnHeaders: [{
|
|
||||||
pattern: /cinema\.army/i,
|
|
||||||
headers: {
|
|
||||||
Referer: 'https://cinema.army/',
|
|
||||||
Origin: 'https://cinema.army',
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
key: 'cinesrc',
|
key: 'cinesrc',
|
||||||
label: 'CineSrc',
|
label: 'CineSrc',
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export async function fetchDownloads(sdkOrId, idOrS = null, sOrE = null, maybeE
|
|||||||
const seenUrls = new Set();
|
const seenUrls = new Set();
|
||||||
const downloads = [];
|
const downloads = [];
|
||||||
|
|
||||||
const results = await Promise.allSettled(
|
await Promise.allSettled(
|
||||||
activeSources.map(async (cfg) => {
|
activeSources.map(async (cfg) => {
|
||||||
try {
|
try {
|
||||||
const res = await sdk.getStream(cfg.key, id, s, e);
|
const res = await sdk.getStream(cfg.key, id, s, e);
|
||||||
@@ -34,7 +34,7 @@ export async function fetchDownloads(sdkOrId, idOrS = null, sOrE = null, maybeE
|
|||||||
const url = item.url.trim();
|
const url = item.url.trim();
|
||||||
|
|
||||||
if (!url.startsWith('http') || url.includes('.m3u8')) continue;
|
if (!url.startsWith('http') || url.includes('.m3u8')) continue;
|
||||||
if (!/\.mp4(\?|$)/i.test(url) && !url.includes('.mp4')) continue;
|
if (!/\.mp4(\?|$)/i.test(url)) continue;
|
||||||
if (seenUrls.has(url)) continue;
|
if (seenUrls.has(url)) continue;
|
||||||
|
|
||||||
seenUrls.add(url);
|
seenUrls.add(url);
|
||||||
|
|||||||
@@ -1,168 +0,0 @@
|
|||||||
import { Session, ClientIdentifier, initTLS, destroyTLS } from "node-tls-client";
|
|
||||||
|
|
||||||
const BASE_URL = "https://atsu.moe";
|
|
||||||
const CDN_URL = "https://cdn.atsu.moe";
|
|
||||||
|
|
||||||
const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
|
|
||||||
|
|
||||||
const HEADERS = {
|
|
||||||
"User-Agent": UA,
|
|
||||||
"Accept": "*/*",
|
|
||||||
"Accept-Language": "en-US,en;q=0.9",
|
|
||||||
"Accept-Encoding": "gzip, deflate, br",
|
|
||||||
"Cache-Control": "no-cache",
|
|
||||||
"Pragma": "no-cache",
|
|
||||||
"Referer": `${BASE_URL}/`,
|
|
||||||
"Origin": BASE_URL,
|
|
||||||
"Sec-Ch-Ua": '"Chromium";v="131", "Not_A Brand";v="24"',
|
|
||||||
"Sec-Ch-Ua-Mobile": "?0",
|
|
||||||
"Sec-Ch-Ua-Platform": '"Windows"',
|
|
||||||
"Sec-Fetch-Dest": "empty",
|
|
||||||
"Sec-Fetch-Mode": "cors",
|
|
||||||
"Sec-Fetch-Site": "same-origin",
|
|
||||||
"Priority": "u=1, i"
|
|
||||||
};
|
|
||||||
|
|
||||||
let tlsInitialized = false;
|
|
||||||
let session = null;
|
|
||||||
|
|
||||||
async function ensureSession() {
|
|
||||||
if (!tlsInitialized) {
|
|
||||||
await initTLS();
|
|
||||||
tlsInitialized = true;
|
|
||||||
}
|
|
||||||
if (!session) {
|
|
||||||
session = new Session({
|
|
||||||
clientIdentifier: ClientIdentifier.chrome_131,
|
|
||||||
timeout: 15000,
|
|
||||||
insecureSkipVerify: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatAssetUrl = (url) => {
|
|
||||||
if (!url) return null;
|
|
||||||
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
|
||||||
if (url.startsWith("/static/")) return `${CDN_URL}${url}`;
|
|
||||||
if (url.startsWith("/")) return `${CDN_URL}${url}`;
|
|
||||||
return `${CDN_URL}/static/${url}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
async function atsuFetch(url) {
|
|
||||||
const sess = await ensureSession();
|
|
||||||
const res = await sess.get(url, { headers: HEADERS });
|
|
||||||
if (res.status !== 200) {
|
|
||||||
throw new Error(`Atsu request failed: ${res.status}`);
|
|
||||||
}
|
|
||||||
const text = await res.text();
|
|
||||||
return JSON.parse(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function searchManga(query, page = 1, perPage = 12) {
|
|
||||||
const params = new URLSearchParams({
|
|
||||||
q: query,
|
|
||||||
query_by: "title,englishTitle,otherNames,authors,acronyms",
|
|
||||||
query_by_weights: "4,3,2,2,1",
|
|
||||||
num_typos: "4,3,2,1,0",
|
|
||||||
prefix: "true,true,true,true,false",
|
|
||||||
include_fields: "id,title,englishTitle,authors,poster,posterSmall,posterMedium,type,medium,isAdult,status,year,mbRating,popularity,dateAdded",
|
|
||||||
filter_by: "isAdult:=false && views:>0 && hidden:!=true",
|
|
||||||
page: String(page),
|
|
||||||
per_page: String(perPage),
|
|
||||||
infix: "off,off,fallback,off,off"
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = await atsuFetch(`${BASE_URL}/collections/manga/documents/search?${params.toString()}`);
|
|
||||||
const results = (data?.hits || []).map(hit => {
|
|
||||||
const doc = hit.document || {};
|
|
||||||
return {
|
|
||||||
id: doc.id,
|
|
||||||
title: doc.title,
|
|
||||||
englishTitle: doc.englishTitle || null,
|
|
||||||
authors: Array.isArray(doc.authors) ? doc.authors : [],
|
|
||||||
type: doc.type,
|
|
||||||
medium: doc.medium,
|
|
||||||
status: doc.status,
|
|
||||||
year: doc.year,
|
|
||||||
rating: doc.mbRating ?? null,
|
|
||||||
popularity: doc.popularity ?? null,
|
|
||||||
poster: formatAssetUrl(doc.poster),
|
|
||||||
posterSmall: formatAssetUrl(doc.posterSmall),
|
|
||||||
posterMedium: formatAssetUrl(doc.posterMedium)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
page: data.page,
|
|
||||||
total: data.found,
|
|
||||||
results
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getMangaDetails(id) {
|
|
||||||
const data = await atsuFetch(`${BASE_URL}/api/manga/page?id=${encodeURIComponent(id)}`);
|
|
||||||
const page = data?.mangaPage;
|
|
||||||
if (!page) throw new Error(`Manga with ID "${id}" not found`);
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: page.id,
|
|
||||||
title: page.title,
|
|
||||||
englishTitle: page.englishTitle || null,
|
|
||||||
synopsis: page.synopsis || null,
|
|
||||||
status: page.status,
|
|
||||||
type: page.type,
|
|
||||||
medium: page.medium,
|
|
||||||
rating: page.avgRating ?? null,
|
|
||||||
views: page.views ?? null,
|
|
||||||
authors: Array.isArray(page.authors) ? page.authors.map(a => a.name) : [],
|
|
||||||
genres: Array.isArray(page.genres) ? page.genres.map(g => g.name) : [],
|
|
||||||
tags: Array.isArray(page.tags) ? page.tags.map(t => t.name) : [],
|
|
||||||
poster: formatAssetUrl(page.poster?.largeImage || page.poster?.image),
|
|
||||||
totalChapters: page.totalChapterCount || page.chapters?.length || 0,
|
|
||||||
chapters: (page.chapters || []).map(ch => ({
|
|
||||||
id: ch.id,
|
|
||||||
number: ch.number,
|
|
||||||
title: ch.title,
|
|
||||||
pageCount: ch.pageCount,
|
|
||||||
createdAt: ch.createdAt ? new Date(ch.createdAt).toISOString() : null
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getChapterPages(mangaId, chapterId) {
|
|
||||||
const data = await atsuFetch(
|
|
||||||
`${BASE_URL}/api/read/chapter?mangaId=${encodeURIComponent(mangaId)}&chapterId=${encodeURIComponent(chapterId)}`
|
|
||||||
);
|
|
||||||
const chapter = data?.readChapter;
|
|
||||||
if (!chapter) throw new Error(`Chapter "${chapterId}" not found for manga "${mangaId}"`);
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: chapter.id,
|
|
||||||
number: chapter.number,
|
|
||||||
title: chapter.title,
|
|
||||||
scanlatorId: chapter.scanlationMangaId || null,
|
|
||||||
pages: (chapter.pages || []).map(p => ({
|
|
||||||
number: p.number,
|
|
||||||
url: formatAssetUrl(p.image),
|
|
||||||
width: p.width,
|
|
||||||
height: p.height,
|
|
||||||
aspectRatio: p.aspectRatio
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function cleanup() {
|
|
||||||
if (session) {
|
|
||||||
try {
|
|
||||||
await session.close();
|
|
||||||
} catch { }
|
|
||||||
session = null;
|
|
||||||
}
|
|
||||||
if (tlsInitialized) {
|
|
||||||
try {
|
|
||||||
await destroyTLS();
|
|
||||||
} catch { }
|
|
||||||
tlsInitialized = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
20
src/sdk.js
20
src/sdk.js
@@ -2,16 +2,13 @@ import SOURCES, { AGGREGATOR_SOURCES, DEDICATED_SOURCES, SOURCE_MAP } from "./co
|
|||||||
import EMBEDS, { EMBED_MAP } from "./embed_config.js";
|
import EMBEDS, { EMBED_MAP } from "./embed_config.js";
|
||||||
import { fetchDownloads } from "./downloads/downloads.js";
|
import { fetchDownloads } from "./downloads/downloads.js";
|
||||||
import { probeSource } from "./health.js";
|
import { probeSource } from "./health.js";
|
||||||
import { getChapterPages, getMangaDetails, searchManga } from "./manga/atsu.js";
|
|
||||||
import { fetchSubtitles, getSubPathsMovie, getSubPathsTv } from "./subtitles.js";
|
import { fetchSubtitles, getSubPathsMovie, getSubPathsTv } from "./subtitles.js";
|
||||||
import { createStreamArgs } from "./utils/helpers.js";
|
import { createStreamArgs } from "./utils/helpers.js";
|
||||||
|
|
||||||
const ALL_SOURCE_MODULES = Object.fromEntries(
|
const ACTIVE_SOURCES = SOURCES.filter(cfg => !cfg.disabled);
|
||||||
await Promise.all(SOURCES.map(async cfg => [cfg.key, await import(`./sources/${cfg.sourceFile}.js`)]))
|
|
||||||
);
|
|
||||||
|
|
||||||
const SOURCE_MODULES = Object.fromEntries(
|
const SOURCE_MODULES = Object.fromEntries(
|
||||||
Object.entries(ALL_SOURCE_MODULES).filter(([key]) => !SOURCE_MAP[key]?.disabled)
|
await Promise.all(ACTIVE_SOURCES.map(async cfg => [cfg.key, await import(`./sources/${cfg.sourceFile}.js`)]))
|
||||||
);
|
);
|
||||||
|
|
||||||
export default class VylaSDK {
|
export default class VylaSDK {
|
||||||
@@ -70,14 +67,14 @@ export default class VylaSDK {
|
|||||||
return sources;
|
return sources;
|
||||||
}
|
}
|
||||||
async probeSource(key) {
|
async probeSource(key) {
|
||||||
const cfg = SOURCES.find(cfg => cfg.key === key);
|
const cfg = SOURCE_MAP[key];
|
||||||
if (!cfg) throw new Error(`Source with key "${key}" not found`);
|
if (!cfg) throw new Error(`Source with key "${key}" not found`);
|
||||||
const mod = SOURCE_MODULES[key];
|
const mod = SOURCE_MODULES[key];
|
||||||
if (!mod) throw new Error(`Source module for key "${key}" not found`);
|
if (!mod) throw new Error(`Source module for key "${key}" not found`);
|
||||||
return await probeSource(this, cfg, mod);
|
return await probeSource(this, cfg, mod);
|
||||||
}
|
}
|
||||||
async getStream(key, id, s = null, e = null, clientIP = null) {
|
async getStream(key, id, s = null, e = null, clientIP = null) {
|
||||||
const cfg = SOURCES.find(cfg => cfg.key === key);
|
const cfg = SOURCE_MAP[key];
|
||||||
if (!cfg) throw new Error(`Source with key "${key}" not found`);
|
if (!cfg) throw new Error(`Source with key "${key}" not found`);
|
||||||
const mod = SOURCE_MODULES[key];
|
const mod = SOURCE_MODULES[key];
|
||||||
if (!mod) throw new Error(`Source module for key "${key}" not found`);
|
if (!mod) throw new Error(`Source module for key "${key}" not found`);
|
||||||
@@ -97,13 +94,4 @@ export default class VylaSDK {
|
|||||||
async getDownloads(id, s = null, e = null) {
|
async getDownloads(id, s = null, e = null) {
|
||||||
return await fetchDownloads(this, id, s, e);
|
return await fetchDownloads(this, id, s, e);
|
||||||
}
|
}
|
||||||
async searchManga(query, page = 1, perPage = 12) {
|
|
||||||
return await searchManga(query, page, perPage);
|
|
||||||
}
|
|
||||||
async getManga(id) {
|
|
||||||
return await getMangaDetails(id);
|
|
||||||
}
|
|
||||||
async getMangaChapter(mangaId, chapterId) {
|
|
||||||
return await getChapterPages(mangaId, chapterId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,123 +4,120 @@ const encoder = new TextEncoder();
|
|||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
const K256 = new Int32Array([
|
const K256 = new Int32Array([
|
||||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const rotr = (x, n) => (x >>> n) | (x << (32 - n));
|
const rotr = (x, n) => (x >>> n) | (x << (32 - n));
|
||||||
|
|
||||||
function sha256(bytes) {
|
function sha256(bytes) {
|
||||||
const len = bytes.length;
|
const len = bytes.length;
|
||||||
const padded = new Uint8Array(((len + 9 + 63) >> 6) << 6);
|
const padded = new Uint8Array(((len + 9 + 63) >> 6) << 6);
|
||||||
padded.set(bytes);
|
padded.set(bytes);
|
||||||
padded[len] = 0x80;
|
padded[len] = 0x80;
|
||||||
const view = new DataView(padded.buffer);
|
const view = new DataView(padded.buffer);
|
||||||
view.setUint32(padded.length - 8, Math.floor((len * 8) / 4294967296));
|
view.setUint32(padded.length - 8, Math.floor((len * 8) / 4294967296));
|
||||||
view.setUint32(padded.length - 4, (len * 8) >>> 0);
|
view.setUint32(padded.length - 4, (len * 8) >>> 0);
|
||||||
|
|
||||||
const H = new Int32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
const H = new Int32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
||||||
const w = new Int32Array(64);
|
const w = new Int32Array(64);
|
||||||
|
|
||||||
for (let off = 0; off < padded.length; off += 64) {
|
for (let off = 0; off < padded.length; off += 64) {
|
||||||
for (let i = 0; i < 16; i++) w[i] = view.getInt32(off + i * 4);
|
for (let i = 0; i < 16; i++) w[i] = view.getInt32(off + i * 4);
|
||||||
for (let i = 16; i < 64; i++) {
|
for (let i = 16; i < 64; i++) {
|
||||||
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
||||||
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
||||||
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
|
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
|
||||||
|
}
|
||||||
|
let [a, b, c, d, e, f, g, h] = H;
|
||||||
|
for (let i = 0; i < 64; i++) {
|
||||||
|
const t1 = (h + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + ((e & f) ^ (~e & g)) + K256[i] + w[i]) | 0;
|
||||||
|
const t2 = ((rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
||||||
|
h = g; g = f; f = e; e = (d + t1) | 0; d = c; c = b; b = a; a = (t1 + t2) | 0;
|
||||||
|
}
|
||||||
|
H[0] += a; H[1] += b; H[2] += c; H[3] += d; H[4] += e; H[5] += f; H[6] += g; H[7] += h;
|
||||||
}
|
}
|
||||||
let [a, b, c, d, e, f, g, h] = H;
|
|
||||||
for (let i = 0; i < 64; i++) {
|
|
||||||
const t1 = (h + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + ((e & f) ^ (~e & g)) + K256[i] + w[i]) | 0;
|
|
||||||
const t2 = ((rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
|
||||||
h = g; g = f; f = e; e = (d + t1) | 0; d = c; c = b; b = a; a = (t1 + t2) | 0;
|
|
||||||
}
|
|
||||||
H[0] += a; H[1] += b; H[2] += c; H[3] += d; H[4] += e; H[5] += f; H[6] += g; H[7] += h;
|
|
||||||
}
|
|
||||||
|
|
||||||
const out = new Uint8Array(32);
|
const out = new Uint8Array(32);
|
||||||
const outView = new DataView(out.buffer);
|
const outView = new DataView(out.buffer);
|
||||||
for (let i = 0; i < 8; i++) outView.setInt32(i * 4, H[i]);
|
for (let i = 0; i < 8; i++) outView.setInt32(i * 4, H[i]);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function base64UrlDecode(v) {
|
function base64UrlDecode(v) {
|
||||||
let s = v.replace(/-/g, '+').replace(/_/g, '/').replace(/=+$/, '');
|
let s = v.replace(/-/g, '+').replace(/_/g, '/').replace(/=+$/, '');
|
||||||
s += '='.repeat((4 - (s.length % 4)) % 4);
|
s += '='.repeat((4 - (s.length % 4)) % 4);
|
||||||
const bin = Buffer.from(s, 'base64').toString('binary');
|
const bin = Buffer.from(s, 'base64').toString('binary');
|
||||||
const out = new Uint8Array(bin.length);
|
const out = new Uint8Array(bin.length);
|
||||||
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseNumList(s) {
|
function parseNumList(s) {
|
||||||
return s.split(',').map((x) => parseInt(x, 10)).filter((x) => !isNaN(x));
|
return s.split(',').map((x) => parseInt(x, 10)).filter((x) => !isNaN(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
function decryptXorBlock(html) {
|
function decryptXorBlock(html) {
|
||||||
if (!html) return null;
|
if (!html) return null;
|
||||||
// Try multiple patterns for the key and data arrays
|
const km = /k\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
||||||
const km = /k\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
/key\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
||||||
/key\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
/const\s+k\s*=\s*\[([0-9,\s]+)\]/i.exec(html);
|
||||||
/const\s+k\s*=\s*\[([0-9,\s]+)\]/i.exec(html);
|
const dm = /d\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
||||||
const dm = /d\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
/data\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
||||||
/data\s*=\s*\[([0-9,\s]+)\]/i.exec(html) ||
|
/const\s+d\s*=\s*\[([0-9,\s]+)\]/i.exec(html);
|
||||||
/const\s+d\s*=\s*\[([0-9,\s]+)\]/i.exec(html);
|
if (!km || !dm) return null;
|
||||||
if (!km || !dm) return null;
|
const key = parseNumList(km[1]);
|
||||||
const key = parseNumList(km[1]);
|
const data = parseNumList(dm[1]);
|
||||||
const data = parseNumList(dm[1]);
|
if (!key.length || !data.length) return null;
|
||||||
if (!key.length || !data.length) return null;
|
return decoder.decode(Uint8Array.from(data, (x, i) => (x ^ key[i % key.length]) & 255));
|
||||||
return decoder.decode(Uint8Array.from(data, (x, i) => (x ^ key[i % key.length]) & 255));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function decryptPayload(body, ticket) {
|
function decryptPayload(body, ticket) {
|
||||||
const m = /"enc":"([^"]+)"/.exec(body);
|
const m = /"enc":"([^"]+)"/.exec(body);
|
||||||
if (!m) return body;
|
if (!m) return body;
|
||||||
let raw;
|
let raw;
|
||||||
try {
|
try {
|
||||||
raw = base64UrlDecode(m[1]);
|
raw = base64UrlDecode(m[1]);
|
||||||
} catch {
|
} catch {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (raw.length <= 48) return body;
|
if (raw.length <= 48) return body;
|
||||||
|
|
||||||
const payload = raw.subarray(16);
|
const payload = raw.subarray(16);
|
||||||
const k = [199, 71, 13, 231, 255, 68, 237];
|
const seed = '9e2b7c41a0f6d85b3c1e7a94f25d0b86';
|
||||||
const v = [254, 34, 63, 133, 200, 39, 217, 246, 38, 61, 129, 201, 32, 213, 242, 37, 62, 132, 206, 33, 218, 166, 126, 57, 129, 205, 113, 137, 247, 37, 53, 209];
|
const block = new Uint8Array(52);
|
||||||
const seed = String.fromCharCode(...v.map((x, i) => x ^ k[i % k.length]));
|
block.set(sha256(encoder.encode(seed + ticket)));
|
||||||
const block = new Uint8Array(52);
|
block.set(raw.subarray(0, 16), 32);
|
||||||
block.set(sha256(encoder.encode(seed + ticket)));
|
const counterView = new DataView(block.buffer, 48, 4);
|
||||||
block.set(raw.subarray(0, 16), 32);
|
const out = new Uint8Array(payload.length);
|
||||||
const counterView = new DataView(block.buffer, 48, 4);
|
|
||||||
const out = new Uint8Array(payload.length);
|
|
||||||
|
|
||||||
for (let pos = 0, counter = 0; pos < payload.length; pos += 32, counter++) {
|
for (let pos = 0, counter = 0; pos < payload.length; pos += 32, counter++) {
|
||||||
counterView.setUint32(0, counter);
|
counterView.setUint32(0, counter);
|
||||||
const stream = sha256(block);
|
const stream = sha256(block);
|
||||||
const n = Math.min(32, payload.length - pos);
|
const n = Math.min(32, payload.length - pos);
|
||||||
for (let i = 0; i < n; i++) out[pos + i] = payload[pos + i] ^ stream[i];
|
for (let i = 0; i < n; i++) out[pos + i] = payload[pos + i] ^ stream[i];
|
||||||
}
|
}
|
||||||
return decoder.decode(out);
|
return decoder.decode(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeTitle(s) {
|
function normalizeTitle(s) {
|
||||||
return String(s || '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
return String(s || '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStreamQuality(raw) {
|
function parseStreamQuality(raw) {
|
||||||
const s = String(raw || '').toLowerCase();
|
const s = String(raw || '').toLowerCase();
|
||||||
if (s.includes('2160') || s.includes('4k')) return '4K';
|
if (s.includes('2160') || s.includes('4k')) return '4K';
|
||||||
if (s.includes('1440') || s.includes('2k')) return '1440p';
|
if (s.includes('1440') || s.includes('2k')) return '1440p';
|
||||||
if (s.includes('1080') || s.includes('full hd') || s.includes('fhd')) return '1080p';
|
if (s.includes('1080') || s.includes('full hd') || s.includes('fhd')) return '1080p';
|
||||||
if (s.includes('720') || s.includes('hd')) return '720p';
|
if (s.includes('720') || s.includes('hd')) return '720p';
|
||||||
if (s.includes('480') || s.includes('sd')) return '480p';
|
if (s.includes('480') || s.includes('sd')) return '480p';
|
||||||
return raw || 'Auto';
|
return raw || 'Auto';
|
||||||
}
|
}
|
||||||
|
|
||||||
const BASE_URL = 'https://bingebang.sx';
|
const BASE_URL = 'https://bingebang.sx';
|
||||||
@@ -142,13 +139,13 @@ const PLAYBACK_HEADERS = {
|
|||||||
'User-Agent': USER_AGENT
|
'User-Agent': USER_AGENT
|
||||||
};
|
};
|
||||||
|
|
||||||
async function findWatchUrl({ title, year, tmdbId, isTv }) {
|
async function findWatchUrl({ title, year, tmdbId, isTv, apiKey }) {
|
||||||
const searchQueries = new Set();
|
const searchQueries = new Set();
|
||||||
if (title) searchQueries.add(title);
|
if (title) searchQueries.add(title);
|
||||||
|
|
||||||
if (tmdbId && searchQueries.size === 0) {
|
if (tmdbId && searchQueries.size === 0) {
|
||||||
try {
|
try {
|
||||||
const tmdbKey = process.env.TMDB_API_KEY || '45dbdd5e714da212424bda0336167447';
|
const tmdbKey = apiKey || '45dbdd5e714da212424bda0336167447';
|
||||||
const tmdbUrl = `https://api.themoviedb.org/3/${isTv ? 'tv' : 'movie'}/${tmdbId}?api_key=${tmdbKey}`;
|
const tmdbUrl = `https://api.themoviedb.org/3/${isTv ? 'tv' : 'movie'}/${tmdbId}?api_key=${tmdbKey}`;
|
||||||
const res = await fetch(tmdbUrl, { signal: AbortSignal.timeout(3000) });
|
const res = await fetch(tmdbUrl, { signal: AbortSignal.timeout(3000) });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -156,7 +153,7 @@ async function findWatchUrl({ title, year, tmdbId, isTv }) {
|
|||||||
if (data?.name) searchQueries.add(data.name);
|
if (data?.name) searchQueries.add(data.name);
|
||||||
if (data?.original_title) searchQueries.add(data.original_title);
|
if (data?.original_title) searchQueries.add(data.original_title);
|
||||||
if (data?.original_name) searchQueries.add(data.original_name);
|
if (data?.original_name) searchQueries.add(data.original_name);
|
||||||
} catch {}
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const q of searchQueries) {
|
for (const q of searchQueries) {
|
||||||
@@ -198,7 +195,7 @@ async function findWatchUrl({ title, year, tmdbId, isTv }) {
|
|||||||
if (bestScore >= 60 && best?.url) {
|
if (bestScore >= 60 && best?.url) {
|
||||||
return best.url;
|
return best.url;
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -232,39 +229,22 @@ export async function getStream(args) {
|
|||||||
|
|
||||||
const html = await pageRes.text();
|
const html = await pageRes.text();
|
||||||
|
|
||||||
// Try to extract ticket from various sources
|
|
||||||
let ticket = null;
|
let ticket = null;
|
||||||
|
|
||||||
// Method 1: Try XOR decryption first
|
|
||||||
const decryptedConfig = decryptXorBlock(html);
|
const decryptedConfig = decryptXorBlock(html);
|
||||||
if (decryptedConfig) {
|
if (decryptedConfig) {
|
||||||
const ticketMatch = /ticket:\s*"([^"]+)"/.exec(decryptedConfig) ||
|
const ticketMatch = /ticket:\s*"([^"]+)"/.exec(decryptedConfig) ||
|
||||||
/ticket:\s*'([^']+)'/.exec(decryptedConfig) ||
|
/ticket:\s*'([^']+)'/.exec(decryptedConfig) ||
|
||||||
/"ticket"\s*:\s*"([^"]+)"/.exec(decryptedConfig) ||
|
/"ticket"\s*:\s*"([^"]+)"/.exec(decryptedConfig) ||
|
||||||
/ticket=([a-zA-Z0-9_-]+)/.exec(decryptedConfig);
|
/ticket=([a-zA-Z0-9_-]+)/.exec(decryptedConfig);
|
||||||
if (ticketMatch) ticket = ticketMatch[1];
|
if (ticketMatch) ticket = ticketMatch[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method 2: Try extracting from inline scripts
|
|
||||||
if (!ticket) {
|
|
||||||
const scriptMatch = /ticket["']?\s*[:=]\s*["']([a-zA-Z0-9_\-\.]+)["']/.exec(html) ||
|
|
||||||
/"ticket"\s*:\s*"([^"]+)"/.exec(html) ||
|
|
||||||
/data-ticket=["']([^"']+)["']/.exec(html);
|
|
||||||
if (scriptMatch) ticket = scriptMatch[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method 3: Try extracting from JSON-like structures in scripts
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
const jsonMatch = /"ticket"\s*:\s*"([^"]{20,})"/.exec(html);
|
const jsonMatch = /"ticket"\s*:\s*"([^"]{20,})"/.exec(html);
|
||||||
if (jsonMatch) ticket = jsonMatch[1];
|
if (jsonMatch) ticket = jsonMatch[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ticket) {
|
|
||||||
// If no ticket found, try without it (some endpoints might not require it)
|
|
||||||
console.log('No ticket found, trying without ticket');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build player headers
|
|
||||||
const playerHeaders = {
|
const playerHeaders = {
|
||||||
'User-Agent': USER_AGENT,
|
'User-Agent': USER_AGENT,
|
||||||
Accept: 'application/json, text/plain, */*',
|
Accept: 'application/json, text/plain, */*',
|
||||||
@@ -273,14 +253,12 @@ export async function getStream(args) {
|
|||||||
'X-BB-Player': '1',
|
'X-BB-Player': '1',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only add ticket if we found one
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
playerHeaders['X-BB-Ticket'] = ticket;
|
playerHeaders['X-BB-Ticket'] = ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also try with CSRF token if present in HTML
|
|
||||||
const csrfMatch = /name="csrf" content="([^"]+)"/.exec(html) ||
|
const csrfMatch = /name="csrf" content="([^"]+)"/.exec(html) ||
|
||||||
/csrf-token" content="([^"]+)"/.exec(html);
|
/csrf-token" content="([^"]+)"/.exec(html);
|
||||||
if (csrfMatch && csrfMatch[1]) {
|
if (csrfMatch && csrfMatch[1]) {
|
||||||
playerHeaders['X-CSRF-Token'] = csrfMatch[1];
|
playerHeaders['X-CSRF-Token'] = csrfMatch[1];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import crypto from 'node:crypto';
|
import crypto from 'node:crypto';
|
||||||
|
import { resolveTmdbKey } from '../utils/helpers.js';
|
||||||
|
|
||||||
const TMDB_BASE_URL = 'https://api.themoviedb.org/3';
|
const TMDB_BASE_URL = 'https://api.themoviedb.org/3';
|
||||||
const CASTLE_BASE = 'https://api.hlowb.com';
|
const CASTLE_BASE = 'https://api.hlowb.com';
|
||||||
@@ -40,11 +41,7 @@ function safeJsonParse(text) {
|
|||||||
|
|
||||||
class CastleScraper {
|
class CastleScraper {
|
||||||
constructor(apiKey) {
|
constructor(apiKey) {
|
||||||
this.tmdbKey =
|
this.tmdbKey = apiKey || '439c478a771f35c05022f9feabcca01c';
|
||||||
apiKey ||
|
|
||||||
process.env.CASTLE_TMDB_API_KEY ||
|
|
||||||
process.env.TMDB_API_KEY ||
|
|
||||||
'439c478a771f35c05022f9feabcca01c';
|
|
||||||
this.securityKey = null;
|
this.securityKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,9 +339,7 @@ class CastleScraper {
|
|||||||
`[${langName}]`
|
`[${langName}]`
|
||||||
);
|
);
|
||||||
allStreams.push(...langStreams);
|
allStreams.push(...langStreams);
|
||||||
} catch (e) {
|
} catch { }
|
||||||
console.error(`[Castle] ${langName}: v1 failed - ${e?.message || e}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,8 +364,7 @@ class CastleScraper {
|
|||||||
(a, b) => this.qualityValue(b.quality) - this.qualityValue(a.quality)
|
(a, b) => this.qualityValue(b.quality) - this.qualityValue(a.quality)
|
||||||
);
|
);
|
||||||
return allStreams;
|
return allStreams;
|
||||||
} catch (e) {
|
} catch {
|
||||||
console.error(`[Castle] Error: ${e?.message || e}`);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,7 +372,7 @@ class CastleScraper {
|
|||||||
|
|
||||||
export async function getStream(args) {
|
export async function getStream(args) {
|
||||||
const { id, s, e, sdk } = args || {};
|
const { id, s, e, sdk } = args || {};
|
||||||
const scraper = new CastleScraper(sdk?.tmdbApiKey);
|
const scraper = new CastleScraper(resolveTmdbKey(args, sdk));
|
||||||
const tmdbId = parseInt(String(id), 10);
|
const tmdbId = parseInt(String(id), 10);
|
||||||
const season = s != null ? parseInt(String(s), 10) : 0;
|
const season = s != null ? parseInt(String(s), 10) : 0;
|
||||||
const episode = e != null ? parseInt(String(e), 10) : 0;
|
const episode = e != null ? parseInt(String(e), 10) : 0;
|
||||||
|
|||||||
@@ -1,180 +0,0 @@
|
|||||||
import crypto from 'node:crypto';
|
|
||||||
import { ClientIdentifier, destroyTLS, initTLS, Session } from 'node-tls-client';
|
|
||||||
|
|
||||||
const BASE_URL = 'https://cinema.army';
|
|
||||||
const API_BASE = `${BASE_URL}/api`;
|
|
||||||
const HMAC_KEY = 'a2cfc9eaa2a3690b5d4f6b5f958dbdeae52a097283d375bd253ee7c7062524f5';
|
|
||||||
const XOR_KEY = 'f16a6b92fcd6eed3e9476297f893f2505c32f79bc6efef9b6c95496aa5914548';
|
|
||||||
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
|
|
||||||
|
|
||||||
const SERVERS = [
|
|
||||||
{ key: 'cookiebakers', label: 'CookieBakers', method: 'POST' },
|
|
||||||
{ key: 'tcloud', label: 'TCloud', method: 'POST' },
|
|
||||||
{ key: 'ipcloud', label: 'IPCloud', method: 'POST' },
|
|
||||||
{ key: 'dcloud', label: 'DCloud', method: 'POST' },
|
|
||||||
{ key: 'tidb', label: 'TIDB', method: 'POST' },
|
|
||||||
];
|
|
||||||
|
|
||||||
let tlsInitialized = false;
|
|
||||||
let session = null;
|
|
||||||
|
|
||||||
async function ensureSession() {
|
|
||||||
if (!tlsInitialized) {
|
|
||||||
await initTLS();
|
|
||||||
tlsInitialized = true;
|
|
||||||
}
|
|
||||||
if (!session) {
|
|
||||||
session = new Session({
|
|
||||||
clientIdentifier: ClientIdentifier.chrome_131,
|
|
||||||
timeout: 15000,
|
|
||||||
insecureSkipVerify: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHeaders(token, id, isTv, s, e) {
|
|
||||||
const referer = isTv
|
|
||||||
? `${BASE_URL}/watch?id=${id}&type=tv&season=${s}&episode=${e}`
|
|
||||||
: `${BASE_URL}/watch?id=${id}&type=movie`;
|
|
||||||
|
|
||||||
return {
|
|
||||||
'User-Agent': UA,
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Accept-Language': 'en-US,en;q=0.9',
|
|
||||||
'Accept-Encoding': 'gzip, deflate, br',
|
|
||||||
'Cache-Control': 'no-cache',
|
|
||||||
Pragma: 'no-cache',
|
|
||||||
Referer: referer,
|
|
||||||
Origin: BASE_URL,
|
|
||||||
'Sec-Ch-Ua': '"Chromium";v="131", "Not_A Brand";v="24"',
|
|
||||||
'Sec-Ch-Ua-Mobile': '?0',
|
|
||||||
'Sec-Ch-Ua-Platform': '"Windows"',
|
|
||||||
'Sec-Fetch-Dest': 'empty',
|
|
||||||
'Sec-Fetch-Mode': 'cors',
|
|
||||||
'Sec-Fetch-Site': 'same-origin',
|
|
||||||
Priority: 'u=1, i',
|
|
||||||
'X-Stream-Token': token,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateToken(id) {
|
|
||||||
try {
|
|
||||||
const minute = Math.floor(Date.now() / 1000 / 60);
|
|
||||||
return crypto
|
|
||||||
.createHmac('sha256', HMAC_KEY)
|
|
||||||
.update(`${id}:${minute}`)
|
|
||||||
.digest('hex');
|
|
||||||
} catch {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function decryptStreamUrl(encoded) {
|
|
||||||
if (!encoded) return '';
|
|
||||||
if (encoded.startsWith('http://') || encoded.startsWith('https://')) return encoded;
|
|
||||||
try {
|
|
||||||
const decoded = Buffer.from(encoded, 'base64').toString('binary');
|
|
||||||
let out = '';
|
|
||||||
for (let i = 0; i < decoded.length; i++) {
|
|
||||||
out += String.fromCharCode(
|
|
||||||
decoded.charCodeAt(i) ^ XOR_KEY.charCodeAt(i % XOR_KEY.length)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
} catch {
|
|
||||||
return encoded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getStream(args) {
|
|
||||||
const { id, s, e } = args || {};
|
|
||||||
const isTv = s != null && e != null;
|
|
||||||
|
|
||||||
const token = generateToken(id);
|
|
||||||
const headers = getHeaders(token, id, isTv, s, e);
|
|
||||||
|
|
||||||
const sess = await ensureSession();
|
|
||||||
|
|
||||||
const requests = SERVERS.map(server => {
|
|
||||||
const path = isTv
|
|
||||||
? `/${server.key}/tv/${id}/${s}/${e}`
|
|
||||||
: `/${server.key}/movie/${id}`;
|
|
||||||
return { url: `${API_BASE}${path}`, server };
|
|
||||||
});
|
|
||||||
|
|
||||||
const results = await Promise.allSettled(
|
|
||||||
requests.map(async ({ url, server }) => {
|
|
||||||
try {
|
|
||||||
const res = server.method === 'POST'
|
|
||||||
? await sess.post(url, { headers, body: '' })
|
|
||||||
: await sess.get(url, { headers });
|
|
||||||
|
|
||||||
if (res?.status !== 200) return null;
|
|
||||||
|
|
||||||
const rawBody = typeof res.text === 'function' ? await res.text() : res.body;
|
|
||||||
|
|
||||||
let data;
|
|
||||||
try {
|
|
||||||
data = typeof rawBody === 'object' && rawBody !== null ? rawBody : JSON.parse(rawBody);
|
|
||||||
} catch (err) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const encrypted = data?.stream?.url;
|
|
||||||
if (!encrypted) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const streamUrl = decryptStreamUrl(encrypted);
|
|
||||||
|
|
||||||
if (!streamUrl || !/^https?:\/\//.test(streamUrl)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
url: streamUrl,
|
|
||||||
headers: {
|
|
||||||
'User-Agent': UA,
|
|
||||||
Referer: `${BASE_URL}/`,
|
|
||||||
Origin: BASE_URL,
|
|
||||||
},
|
|
||||||
server: `CinemaArmy (${server.label})`,
|
|
||||||
quality: '1080p',
|
|
||||||
type: streamUrl.includes('.m3u8') ? 'hls' : 'mp4',
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const allUrls = results
|
|
||||||
.filter(r => r.status === 'fulfilled' && r.value)
|
|
||||||
.map(r => r.value);
|
|
||||||
|
|
||||||
if (!allUrls.length) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
url: allUrls[0].url,
|
|
||||||
headers: allUrls[0].headers,
|
|
||||||
allUrls,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function cleanup() {
|
|
||||||
if (session) {
|
|
||||||
try {
|
|
||||||
await session.close();
|
|
||||||
} catch { }
|
|
||||||
session = null;
|
|
||||||
}
|
|
||||||
if (tlsInitialized) {
|
|
||||||
try {
|
|
||||||
await destroyTLS();
|
|
||||||
} catch { }
|
|
||||||
tlsInitialized = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -213,7 +213,6 @@ async function solveStage2(data) {
|
|||||||
export async function getStream(args) {
|
export async function getStream(args) {
|
||||||
const { id, s, e } = args || {};
|
const { id, s, e } = args || {};
|
||||||
const isTv = s != null && e != null;
|
const isTv = s != null && e != null;
|
||||||
const mediaType = isTv ? 'tv' : 'movie';
|
|
||||||
const type = isTv ? 'tv' : 'movie';
|
const type = isTv ? 'tv' : 'movie';
|
||||||
const url = isTv
|
const url = isTv
|
||||||
? `https://cinesrc.st/embed/tv/${id}?s=${s}&e=${e}`
|
? `https://cinesrc.st/embed/tv/${id}?s=${s}&e=${e}`
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { USER_AGENT, getTmdbMetadata, resolveTmdbKey } from '../utils/helpers.js';
|
import { USER_AGENT, getTmdbMetadata, resolveTmdbKey } from '../utils/helpers.js';
|
||||||
|
|
||||||
const API_BASE = 'https://api.hicine.sbs';
|
const API_BASE = 'https://api.hicine.sbs';
|
||||||
const TMDB_API = 'https://api.themoviedb.org/3';
|
|
||||||
const FALLBACK_WORKER_BASE = 'https://quiet-lab-41f9.yolku.workers.dev';
|
const FALLBACK_WORKER_BASE = 'https://quiet-lab-41f9.yolku.workers.dev';
|
||||||
const KNOWN_DEAD_WORKERS = new Set([
|
const KNOWN_DEAD_WORKERS = new Set([
|
||||||
'snowy-sea-35bf.rukoy.workers.dev'
|
'snowy-sea-35bf.rukoy.workers.dev'
|
||||||
@@ -305,7 +304,7 @@ async function resolveWorker(target) {
|
|||||||
let hostname = '';
|
let hostname = '';
|
||||||
try {
|
try {
|
||||||
hostname = new URL(base).hostname.toLowerCase();
|
hostname = new URL(base).hostname.toLowerCase();
|
||||||
} catch {}
|
} catch { }
|
||||||
|
|
||||||
if (KNOWN_DEAD_WORKERS.has(hostname) || hostname.endsWith('.rukoy.workers.dev')) {
|
if (KNOWN_DEAD_WORKERS.has(hostname) || hostname.endsWith('.rukoy.workers.dev')) {
|
||||||
base = FALLBACK_WORKER_BASE;
|
base = FALLBACK_WORKER_BASE;
|
||||||
@@ -318,7 +317,7 @@ async function resolveWorker(target) {
|
|||||||
signal: AbortSignal.timeout(15000),
|
signal: AbortSignal.timeout(15000),
|
||||||
});
|
});
|
||||||
data = await res.json();
|
data = await res.json();
|
||||||
} catch {}
|
} catch { }
|
||||||
|
|
||||||
if ((!data || !data.tokens) && base !== FALLBACK_WORKER_BASE) {
|
if ((!data || !data.tokens) && base !== FALLBACK_WORKER_BASE) {
|
||||||
try {
|
try {
|
||||||
@@ -331,7 +330,7 @@ async function resolveWorker(target) {
|
|||||||
data = fbData;
|
data = fbData;
|
||||||
base = FALLBACK_WORKER_BASE;
|
base = FALLBACK_WORKER_BASE;
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@@ -386,7 +385,7 @@ async function resolveWorker(target) {
|
|||||||
signal: AbortSignal.timeout(15000),
|
signal: AbortSignal.timeout(15000),
|
||||||
redirect: 'manual',
|
redirect: 'manual',
|
||||||
});
|
});
|
||||||
const redirectedUrl = directRes.headers?.location || directRes.url || '';
|
const redirectedUrl = directRes.headers?.get('location') || directRes.url || '';
|
||||||
const m = redirectedUrl.match(/^https?:\/\/(pixeldrain\.[a-z]+)\/(?:u|api\/file)\/([A-Za-z0-9]+)/);
|
const m = redirectedUrl.match(/^https?:\/\/(pixeldrain\.[a-z]+)\/(?:u|api\/file)\/([A-Za-z0-9]+)/);
|
||||||
if (m) {
|
if (m) {
|
||||||
resolvedStreams.push({
|
resolvedStreams.push({
|
||||||
@@ -400,7 +399,7 @@ async function resolveWorker(target) {
|
|||||||
audioDetails
|
audioDetails
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch { }
|
||||||
} else {
|
} else {
|
||||||
resolvedStreams.push({
|
resolvedStreams.push({
|
||||||
url: goUrl,
|
url: goUrl,
|
||||||
@@ -470,7 +469,7 @@ export async function getStream(args) {
|
|||||||
if (detailData && !detailData.error) {
|
if (detailData && !detailData.error) {
|
||||||
record = { ...record, ...detailData };
|
record = { ...record, ...detailData };
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
const candidateTargets = isTv
|
const candidateTargets = isTv
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import crypto from 'node:crypto';
|
import crypto from 'node:crypto';
|
||||||
import { USER_AGENT } from '../utils/helpers.js';
|
import { USER_AGENT } from '../utils/helpers.js';
|
||||||
|
|
||||||
const TARO_ORIGIN = 'https://taroflix.net';
|
|
||||||
const BACKEND_BASE = 'https://starkio.cyou';
|
const BACKEND_BASE = 'https://starkio.cyou';
|
||||||
|
|
||||||
const FALLBACK_SCHEME = {
|
const FALLBACK_SCHEME = {
|
||||||
|
|||||||
@@ -48,23 +48,6 @@ export async function fetchSubtitles(paths = []) {
|
|||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base.includes('fed-subs.pstream.mov')) {
|
|
||||||
if (!data?.subtitles || typeof data.subtitles !== 'object') return [];
|
|
||||||
|
|
||||||
return Object.entries(data.subtitles)
|
|
||||||
.map(([language, sub]) => {
|
|
||||||
if (!sub?.subtitle_link) return null;
|
|
||||||
const ext = sub.subtitle_link.split('.').pop()?.toLowerCase();
|
|
||||||
return {
|
|
||||||
label: sub.subtitle_name || language,
|
|
||||||
file: sub.subtitle_link,
|
|
||||||
type: ext === 'vtt' ? 'vtt' : 'srt',
|
|
||||||
source: 'febbox'
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
const v1 = Array.isArray(data) ? data : [];
|
const v1 = Array.isArray(data) ? data : [];
|
||||||
return v1.map(x => ({
|
return v1.map(x => ({
|
||||||
label: x.label,
|
label: x.label,
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ export function resolveTmdbKey(args = {}, sdk = null) {
|
|||||||
args?.tmdbApiKey ||
|
args?.tmdbApiKey ||
|
||||||
args?.sdk?.tmdbApiKey ||
|
args?.sdk?.tmdbApiKey ||
|
||||||
sdk?.tmdbApiKey ||
|
sdk?.tmdbApiKey ||
|
||||||
process.env.TMDB_API_KEY ||
|
|
||||||
DEFAULT_TMDB_KEY
|
DEFAULT_TMDB_KEY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -120,7 +119,7 @@ export function decryptPartner(responseText, keyEnv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getTmdbMetadata(id, isTv, apiKey = null) {
|
export async function getTmdbMetadata(id, isTv, apiKey = null) {
|
||||||
const key = apiKey || process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
const key = apiKey || DEFAULT_TMDB_KEY;
|
||||||
const type = isTv ? 'tv' : 'movie';
|
const type = isTv ? 'tv' : 'movie';
|
||||||
const cacheKey = `${id}-${type}-${key}`;
|
const cacheKey = `${id}-${type}-${key}`;
|
||||||
const cached = cacheGet(tmdbMetaCache, cacheKey);
|
const cached = cacheGet(tmdbMetaCache, cacheKey);
|
||||||
@@ -203,7 +202,7 @@ export async function getTmdbInfo(arg1, arg2, arg3, arg4) {
|
|||||||
type = arg1;
|
type = arg1;
|
||||||
id = arg2;
|
id = arg2;
|
||||||
season = arg3;
|
season = arg3;
|
||||||
apiKey = arg4 || process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
apiKey = arg4 || DEFAULT_TMDB_KEY;
|
||||||
} else if (arg2 === 'movie' || arg2 === 'tv') {
|
} else if (arg2 === 'movie' || arg2 === 'tv') {
|
||||||
if (typeof arg1 === 'string' && arg1.length > 20 && !/^\d+$/.test(arg1)) {
|
if (typeof arg1 === 'string' && arg1.length > 20 && !/^\d+$/.test(arg1)) {
|
||||||
apiKey = arg1;
|
apiKey = arg1;
|
||||||
@@ -214,7 +213,7 @@ export async function getTmdbInfo(arg1, arg2, arg3, arg4) {
|
|||||||
id = arg1;
|
id = arg1;
|
||||||
type = arg2;
|
type = arg2;
|
||||||
season = arg3;
|
season = arg3;
|
||||||
apiKey = arg4 || process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
apiKey = arg4 || DEFAULT_TMDB_KEY;
|
||||||
}
|
}
|
||||||
} else if (arg3 === 'movie' || arg3 === 'tv') {
|
} else if (arg3 === 'movie' || arg3 === 'tv') {
|
||||||
apiKey = arg1;
|
apiKey = arg1;
|
||||||
@@ -225,10 +224,10 @@ export async function getTmdbInfo(arg1, arg2, arg3, arg4) {
|
|||||||
id = arg1;
|
id = arg1;
|
||||||
type = arg2 || 'movie';
|
type = arg2 || 'movie';
|
||||||
season = arg3;
|
season = arg3;
|
||||||
apiKey = arg4 || process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
apiKey = arg4 || DEFAULT_TMDB_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!apiKey) apiKey = process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
if (!apiKey) apiKey = DEFAULT_TMDB_KEY;
|
||||||
|
|
||||||
const isTv = type === 'tv';
|
const isTv = type === 'tv';
|
||||||
const key = `${id}-${type}-${season || ''}-${apiKey}`;
|
const key = `${id}-${type}-${season || ''}-${apiKey}`;
|
||||||
@@ -295,10 +294,10 @@ export async function validateTmdbId(tmdbApiKey, tmdbId, mediaType = 'movie') {
|
|||||||
if (apiKey && apiKey !== 'movie' && apiKey !== 'tv') {
|
if (apiKey && apiKey !== 'movie' && apiKey !== 'tv') {
|
||||||
type = id || 'movie';
|
type = id || 'movie';
|
||||||
id = apiKey;
|
id = apiKey;
|
||||||
apiKey = process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
apiKey = DEFAULT_TMDB_KEY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!apiKey) apiKey = process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
if (!apiKey) apiKey = DEFAULT_TMDB_KEY;
|
||||||
|
|
||||||
const key = `${id}-${type}`;
|
const key = `${id}-${type}`;
|
||||||
const cached = cacheGet(tmdbValidationCache, key);
|
const cached = cacheGet(tmdbValidationCache, key);
|
||||||
@@ -331,9 +330,9 @@ export async function imdbToTmdb(tmdbApiKey, imdbId, mediaType = 'movie') {
|
|||||||
if (id === 'movie' || id === 'tv') {
|
if (id === 'movie' || id === 'tv') {
|
||||||
type = id;
|
type = id;
|
||||||
id = apiKey;
|
id = apiKey;
|
||||||
apiKey = process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
apiKey = DEFAULT_TMDB_KEY;
|
||||||
}
|
}
|
||||||
if (!apiKey) apiKey = process.env.TMDB_API_KEY || DEFAULT_TMDB_KEY;
|
if (!apiKey) apiKey = DEFAULT_TMDB_KEY;
|
||||||
|
|
||||||
const key = `imdb-${id}`;
|
const key = `imdb-${id}`;
|
||||||
const cached = cacheGet(tmdbInfoCache, key);
|
const cached = cacheGet(tmdbInfoCache, key);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// usage: npm test
|
// usage: npm test
|
||||||
// Configure the variables below to customize your testing environment
|
// Configure the variables below to customize your testing environment
|
||||||
|
|
||||||
import fs, { truncate } from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import VylaSDK from "../src/sdk.js";
|
import VylaSDK from "../src/sdk.js";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
@@ -19,8 +19,6 @@ const CONFIG = {
|
|||||||
TEST_DOWNLOAD: false,
|
TEST_DOWNLOAD: false,
|
||||||
TEST_MOVIE: true,
|
TEST_MOVIE: true,
|
||||||
TEST_TV: true,
|
TEST_TV: true,
|
||||||
TEST_MANGA: false,
|
|
||||||
MANGA_QUERY: "Steel Ball Run",
|
|
||||||
|
|
||||||
EXTRA_SDK_PARAMS: {
|
EXTRA_SDK_PARAMS: {
|
||||||
// penguManifest: ""
|
// penguManifest: ""
|
||||||
@@ -232,32 +230,3 @@ if (CONFIG.TEST_TV) {
|
|||||||
} else {
|
} else {
|
||||||
console.log("\nSkipped Stream Test");
|
console.log("\nSkipped Stream Test");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG.TEST_MANGA) {
|
|
||||||
try {
|
|
||||||
console.log(`\nSearching Manga for: "${CONFIG.MANGA_QUERY}"`);
|
|
||||||
const searchRes = await sdk.searchManga(CONFIG.MANGA_QUERY, 1, 5);
|
|
||||||
console.log("Manga Search Found:", searchRes.total);
|
|
||||||
console.log("Top Hit:", searchRes.results[0]);
|
|
||||||
|
|
||||||
if (searchRes.results.length > 0) {
|
|
||||||
const mangaId = searchRes.results[0].id;
|
|
||||||
console.log(`\nFetching Manga Details for ID: ${mangaId}`);
|
|
||||||
const mangaDetails = await sdk.getManga(mangaId);
|
|
||||||
console.log("Manga Title:", mangaDetails.title);
|
|
||||||
console.log("Total Chapters:", mangaDetails.totalChapters);
|
|
||||||
|
|
||||||
const firstChapter = mangaDetails.chapters[mangaDetails.chapters.length - 1] || mangaDetails.chapters[0];
|
|
||||||
if (firstChapter) {
|
|
||||||
console.log(`\nFetching Pages for Chapter: ${firstChapter.title} (${firstChapter.id})`);
|
|
||||||
const chapterPages = await sdk.getMangaChapter(mangaId, firstChapter.id);
|
|
||||||
console.log("Page Count:", chapterPages.pages.length);
|
|
||||||
console.log("Sample First Page:", chapterPages.pages[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Manga Test Error:", err.message);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log("\nSkipped Manga Test");
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user