refactor: pass Context instead of Config to MFP helper
This commit is contained in:
parent
16870aa257
commit
7ea57222d9
3 changed files with 11 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import bytes from 'bytes';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { Extractor } from './Extractor';
|
||||
import { buildMediaFlowProxyExtractorRedirectUrl, Fetcher, hasMediaFlowProxy } from '../utils';
|
||||
import { buildMediaFlowProxyExtractorRedirectUrl, Fetcher, supportsMediaFlowProxy } from '../utils';
|
||||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
import { NotFoundError } from '../error';
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ export class Mixdrop extends Extractor {
|
|||
}
|
||||
|
||||
public supports(ctx: Context, url: URL): boolean {
|
||||
return null !== url.host.match(/mixdrop/) && hasMediaFlowProxy(ctx.config);
|
||||
return null !== url.host.match(/mixdrop/) && supportsMediaFlowProxy(ctx);
|
||||
}
|
||||
|
||||
protected async extractInternal(ctx: Context, url: URL, countryCode: CountryCode): Promise<UrlResult[]> {
|
||||
|
|
@ -39,7 +39,7 @@ export class Mixdrop extends Extractor {
|
|||
|
||||
return [
|
||||
{
|
||||
url: buildMediaFlowProxyExtractorRedirectUrl(ctx.config, 'Mixdrop', url),
|
||||
url: buildMediaFlowProxyExtractorRedirectUrl(ctx, 'Mixdrop', url),
|
||||
format: Format.mp4,
|
||||
label: this.label,
|
||||
sourceId: `${this.id}_${countryCode}`,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Extractor } from './Extractor';
|
||||
import { buildMediaFlowProxyExtractorRedirectUrl, Fetcher, hasMediaFlowProxy } from '../utils';
|
||||
import { buildMediaFlowProxyExtractorRedirectUrl, Fetcher, supportsMediaFlowProxy } from '../utils';
|
||||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
|
||||
export class Uqload extends Extractor {
|
||||
|
|
@ -19,7 +19,7 @@ export class Uqload extends Extractor {
|
|||
}
|
||||
|
||||
public supports(ctx: Context, url: URL): boolean {
|
||||
return null !== url.host.match(/uqload/) && hasMediaFlowProxy(ctx.config);
|
||||
return null !== url.host.match(/uqload/) && supportsMediaFlowProxy(ctx);
|
||||
}
|
||||
|
||||
public override normalize(url: URL): URL {
|
||||
|
|
@ -36,7 +36,7 @@ export class Uqload extends Extractor {
|
|||
|
||||
return [
|
||||
{
|
||||
url: buildMediaFlowProxyExtractorRedirectUrl(ctx.config, 'Uqload', url),
|
||||
url: buildMediaFlowProxyExtractorRedirectUrl(ctx, 'Uqload', url),
|
||||
format: Format.mp4,
|
||||
label: this.label,
|
||||
sourceId: `${this.id}_${countryCode}`,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { Config } from '../types';
|
||||
import { Context } from '../types';
|
||||
|
||||
export const hasMediaFlowProxy = (config: Config): boolean => !!(config['mediaFlowProxyUrl'] && config['mediaFlowProxyPassword']);
|
||||
export const supportsMediaFlowProxy = (ctx: Context): boolean => !!(ctx.config['mediaFlowProxyUrl'] && ctx.config['mediaFlowProxyPassword']);
|
||||
|
||||
export const buildMediaFlowProxyExtractorRedirectUrl = (config: Config, host: string, url: URL): URL => {
|
||||
const mediaFlowProxyUrl = new URL(`${config.mediaFlowProxyUrl}/extractor/video`);
|
||||
export const buildMediaFlowProxyExtractorRedirectUrl = (ctx: Context, host: string, url: URL): URL => {
|
||||
const mediaFlowProxyUrl = new URL(`${ctx.config.mediaFlowProxyUrl}/extractor/video`);
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('host', host);
|
||||
params.append('redirect_stream', 'true');
|
||||
params.append('api_password', `${config.mediaFlowProxyPassword}`);
|
||||
params.append('api_password', `${ctx.config.mediaFlowProxyPassword}`);
|
||||
params.append('d', url.href);
|
||||
mediaFlowProxyUrl.search = params.toString();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue