chore(extractor): re-use and optimise mediaflow default fetch init slightly

This commit is contained in:
WebStreamr 2025-10-06 08:00:43 +00:00
parent eea8cac018
commit 7191c59b8a
No known key found for this signature in database
4 changed files with 18 additions and 8 deletions

View file

@ -1,7 +1,12 @@
import bytes from 'bytes';
import * as cheerio from 'cheerio';
import { Context, Format, Meta, UrlResult } from '../types';
import { buildMediaFlowProxyExtractorStreamUrl, guessHeightFromPlaylist, supportsMediaFlowProxy } from '../utils';
import {
buildMediaFlowProxyExtractorStreamUrl,
guessHeightFromPlaylist,
MEDIAFLOW_DEFAULT_INIT,
supportsMediaFlowProxy,
} from '../utils';
import { Extractor } from './Extractor';
/** @see https://github.com/Gujal00/ResolveURL/commits/master/script.module.resolveurl/lib/resolveurl/plugins/filelions.py */
@ -80,7 +85,7 @@ export class FileLions extends Extractor {
ttl: this.ttl,
meta: {
...meta,
height: await guessHeightFromPlaylist(ctx, this.fetcher, playlistUrl, { headers: { Referer: url.href }, queueLimit: 4 }),
height: await guessHeightFromPlaylist(ctx, this.fetcher, playlistUrl, { ...MEDIAFLOW_DEFAULT_INIT, headers: { Referer: url.href } }),
...(sizeMatch && {
bytes: bytes.parse(sizeMatch[1] as string) as number,
}),

View file

@ -1,7 +1,7 @@
import * as cheerio from 'cheerio';
import { Context, Format, Meta, UrlResult } from '../types';
import {
buildMediaFlowProxyExtractorRedirectUrl,
buildMediaFlowProxyExtractorRedirectUrl, MEDIAFLOW_DEFAULT_INIT,
supportsMediaFlowProxy,
} from '../utils';
import { guessSizeFromMp4 } from '../utils/size';
@ -40,7 +40,7 @@ export class Streamtape extends Extractor {
meta: {
...meta,
title,
bytes: await guessSizeFromMp4(ctx, this.fetcher, mp4Url, { queueLimit: 4 }),
bytes: await guessSizeFromMp4(ctx, this.fetcher, mp4Url, MEDIAFLOW_DEFAULT_INIT),
},
},
];

View file

@ -1,7 +1,7 @@
import * as cheerio from 'cheerio';
import { NotFoundError } from '../error';
import { Context, Format, Meta, UrlResult } from '../types';
import { buildMediaFlowProxyExtractorRedirectUrl, supportsMediaFlowProxy } from '../utils';
import { buildMediaFlowProxyExtractorRedirectUrl, MEDIAFLOW_DEFAULT_INIT, supportsMediaFlowProxy } from '../utils';
import { guessSizeFromMp4 } from '../utils/size';
import { Extractor } from './Extractor';
@ -46,7 +46,7 @@ export class Uqload extends Extractor {
meta: {
...meta,
title,
bytes: await guessSizeFromMp4(ctx, this.fetcher, mp4Url, { headers: { Referer: url.href }, queueLimit: 4 }),
bytes: await guessSizeFromMp4(ctx, this.fetcher, mp4Url, { ...MEDIAFLOW_DEFAULT_INIT, headers: { Referer: url.href } }),
...(heightMatch && {
height: parseInt(heightMatch[1] as string),
}),

View file

@ -1,5 +1,5 @@
import { Context } from '../types';
import { Fetcher } from './Fetcher';
import { CustomRequestInit, Fetcher } from './Fetcher';
interface ExtractResult {
destination_url: string;
@ -8,6 +8,11 @@ interface ExtractResult {
query_params: Record<string, string>;
}
export const MEDIAFLOW_DEFAULT_INIT: CustomRequestInit = {
queueLimit: 4,
queueTimeout: 10000,
};
export const supportsMediaFlowProxy = (ctx: Context): boolean => !!ctx.config['mediaFlowProxyUrl'];
const buildMediaFlowProxyExtractorUrl = (ctx: Context, host: string, url: URL, headers: Record<string, string>): URL => {
@ -35,7 +40,7 @@ export const buildMediaFlowProxyExtractorRedirectUrl = (ctx: Context, host: stri
export const buildMediaFlowProxyExtractorStreamUrl = async (ctx: Context, fetcher: Fetcher, host: string, url: URL, headers: Record<string, string>): Promise<URL> => {
const mediaFlowProxyUrl = buildMediaFlowProxyExtractorUrl(ctx, host, url, headers);
const extractResult: ExtractResult = await fetcher.json(ctx, mediaFlowProxyUrl, { queueLimit: 4 });
const extractResult: ExtractResult = await fetcher.json(ctx, mediaFlowProxyUrl, MEDIAFLOW_DEFAULT_INIT);
const streamUrl = new URL(extractResult.mediaflow_proxy_url);