chore(extractor): clean-up header/referer passing

This commit is contained in:
WebStreamr 2025-09-10 13:21:36 +00:00
parent 7f2cf10021
commit 057b2346dc
No known key found for this signature in database
5 changed files with 20 additions and 15 deletions

View file

@ -12,7 +12,9 @@ export class Fsst extends Extractor {
};
protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise<UrlResult[]> {
const html = await this.fetcher.text(ctx, url);
const headers = { Referer: meta.referer ?? url.origin };
const html = await this.fetcher.text(ctx, url, { headers });
const $ = cheerio.load(html);
const title = $('title').text().trim();

View file

@ -36,7 +36,9 @@ export class KinoGer extends Extractor {
}
protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise<UrlResult[]> {
const hexData = await this.fetcher.text(ctx, url, { headers: { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36' } });
const headers = { 'Referer': meta.referer ?? url.origin, 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36' };
const hexData = await this.fetcher.text(ctx, url, { headers });
const encrypted = Buffer.from(hexData, 'hex');
const key = Buffer.from('6b69656d7469656e6d75613931316361', 'hex');
@ -57,7 +59,7 @@ export class KinoGer extends Extractor {
ttl: this.ttl,
meta: {
...meta,
height: await guessHeightFromPlaylist(ctx, this.fetcher, m3u8Url, { headers: { Referer: url.origin } }),
height: await guessHeightFromPlaylist(ctx, this.fetcher, m3u8Url, { headers }),
title,
},
requestHeaders: {

View file

@ -15,13 +15,15 @@ export class SuperVideo extends Extractor {
}
public override normalize(url: URL): URL {
const fileUrl = new URL(url.href.replace('/e/', '/').replace('/embed-', '/').replace('.html', ''));
const fileUrl = new URL(url.href.replace('/e/', '/').replace('/k/', '/').replace('/embed-', '/').replace('.html', ''));
return new URL(`/e${fileUrl.pathname}`, fileUrl.origin);
}
protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise<UrlResult[]> {
const html = await this.fetcher.text(ctx, url);
const headers = { Referer: meta.referer ?? url.origin };
const html = await this.fetcher.text(ctx, url, { headers });
if (/'The file was deleted|The file expired|Video is processing/.test(html) || !html.includes('p,a,c,k,e,d')) {
throw new NotFoundError();
@ -38,7 +40,7 @@ export class SuperVideo extends Extractor {
ttl: this.ttl,
meta: {
...meta,
height: await guessHeightFromPlaylist(ctx, this.fetcher, m3u8Url),
height: await guessHeightFromPlaylist(ctx, this.fetcher, m3u8Url, { headers }),
},
},
];

View file

@ -39,7 +39,7 @@ export class VidSrc extends Extractor {
let html: string;
try {
html = await this.fetcher.text(ctx, newUrl, { queueLimit: 1 });
html = await this.fetcher.text(ctx, newUrl, { headers: { Referer: meta.referer ?? newUrl.origin }, queueLimit: 1 });
} catch (error) {
if (tlds.length && (error instanceof TooManyRequestsError || error instanceof BlockedError)) {
return this.extractUsingRandomTld(ctx, url, meta, tlds);
@ -51,6 +51,7 @@ export class VidSrc extends Extractor {
const $ = cheerio.load(html);
const iframeUrl = new URL(($('#player_iframe').attr('src') as string).replace(/^\/\//, 'https://'));
const headers = { Referer: iframeUrl.origin };
const title = $('title').text().trim();
return Promise.all(
@ -59,10 +60,10 @@ export class VidSrc extends Extractor {
.toArray()
.filter(({ serverName }) => serverName === 'CloudStream Pro')
.map(async ({ serverName, dataHash }) => {
const iframeHtml = await this.fetcher.text(ctx, new URL(`/rcp/${dataHash}`, iframeUrl.origin), { headers: { Referer: iframeUrl.origin } });
const iframeHtml = await this.fetcher.text(ctx, new URL(`/rcp/${dataHash}`, iframeUrl.origin), { headers });
const srcMatch = iframeHtml.match(`src:\\s?'(.*)'`) as string[];
const playerHtml = await this.fetcher.text(ctx, new URL(srcMatch[1] as string, iframeUrl.origin), { headers: { Referer: iframeUrl.origin } });
const playerHtml = await this.fetcher.text(ctx, new URL(srcMatch[1] as string, iframeUrl.origin), { headers });
const fileMatch = playerHtml.match(`file:\\s?'(.*)'`);
if (!fileMatch) {
throw new NotFoundError();
@ -78,7 +79,7 @@ export class VidSrc extends Extractor {
ttl: this.ttl,
meta: {
...meta,
height: await guessHeightFromPlaylist(ctx, this.fetcher, m3u8Url),
height: await guessHeightFromPlaylist(ctx, this.fetcher, m3u8Url, { headers }),
title,
},
};

View file

@ -27,7 +27,7 @@ export class XPrime extends Extractor {
protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise<UrlResult[]> {
const urlResults: UrlResult[] = [];
const referer = url.protocol + '//' + url.hostname.split('.').slice(-2).join('.'); // Strip subdomains
const headers = { Referer: meta.referer ?? url.protocol + '//' + url.hostname.split('.').slice(-2).join('.') };
if (url.href.includes('primebox')) {
const jsonResponse = JSON.parse(await this.fetcher.text(ctx, url)) as XPrimePrimeboxResponsePartial;
@ -46,13 +46,11 @@ export class XPrime extends Extractor {
ttl: this.ttl,
meta: {
...meta,
bytes: await guessSizeFromMp4(ctx, this.fetcher, url, { headers: { Referer: referer }, minCacheTtl: this.ttl }),
bytes: await guessSizeFromMp4(ctx, this.fetcher, url, { headers, minCacheTtl: this.ttl }),
height: parseInt(resolution),
title,
},
requestHeaders: {
Referer: referer,
},
requestHeaders: headers,
});
}
}