Fix vidsrcsu again
Some checks failed
Testing / Testing (push) Has been cancelled

hopefully futureproof enough this time
This commit is contained in:
TPN 2025-01-22 14:45:17 +00:00
parent 1b1940b390
commit 1549f84df0

View file

@ -1,8 +1,5 @@
import JSON5 from 'json5';
import { flags } from '@/entrypoint/utils/targets';
import { SourcererOutput, makeSourcerer } from '@/providers/base';
import { Caption, labelToLanguageCode } from '@/providers/captions';
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors';
@ -10,41 +7,26 @@ async function comboScraper(ctx: ShowScrapeContext | MovieScrapeContext): Promis
const embedPage = await ctx.proxiedFetcher(
`https://vidsrc.su/embed/${ctx.media.type === 'movie' ? `movie/${ctx.media.tmdbId}` : `tv/${ctx.media.tmdbId}/${ctx.media.season.number}/${ctx.media.episode.number}`}`,
);
const serverDataMatch = embedPage.match(/const fixedServers = +(\[.*?\])/s);
if (!serverDataMatch[1]) throw new NotFoundError('No data found');
// const servers: { label: string; url: string }[] = JSON.parse(serverDataMatch[1].replace(/([a-zA-Z0-9_]+): /g, '"$1":').replace(/'/g, '"').replace(/,\s*\]$/, ']'))
const servers: { label: string; url: string }[] = JSON5.parse(serverDataMatch[1]);
let playlist;
// we only want flixhq which is server 1 and server 2
servers.forEach((server) => {
if (['Server 1', 'Server 2', 'Server 3'].includes(server.label) && server.url) playlist = server.url;
});
if (!playlist) throw new NotFoundError('No flixhq playlist found');
const captionsDataMatch = embedPage.match(/const subtitles = +(\[.*?\])/s);
const captions: Caption[] = [];
if (captionsDataMatch[1]) {
const captionsData: { label: string; file: string }[] = JSON5.parse(captionsDataMatch[1]);
for (const caption of captionsData) {
const language = labelToLanguageCode(caption.label);
if (!language) continue;
captions.push({
id: caption.file,
url: caption.file,
type: 'vtt',
hasCorsRestrictions: false,
language,
});
}
}
const servers = [...embedPage.matchAll(/label: 'Server (1|2|3)', url: '(https.*)'/g)] // only server 1,2 and 3 are flixhq
.sort((a, b) => {
// ranking for servers
const ranks: Record<string, number> = { '1': 10, '2': 30, '3': 20 }; // server 2 > 3 > 1
return ranks[b[1]] - ranks[a[1]];
})
.map((x) => x[2]);
if (!servers[0]) throw new NotFoundError('No flixhq playlist found');
return {
embeds: [],
stream: [
{
id: 'primary',
playlist,
playlist: servers[0],
type: 'hls',
flags: [flags.CORS_ALLOWED],
captions,
captions: [],
},
],
};