refactor(extractor): move title height guessing into central place
This commit is contained in:
parent
61f515e4d2
commit
5da52d648a
8 changed files with 19 additions and 9 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import randomstring from 'randomstring';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { Extractor } from './Extractor';
|
||||
import { Fetcher, guessHeightFromTitle } from '../utils';
|
||||
import { Fetcher } from '../utils';
|
||||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
import { NotFoundError } from '../error';
|
||||
|
||||
|
|
@ -57,7 +57,6 @@ export class DoodStream extends Extractor {
|
|||
ttl: this.ttl,
|
||||
meta: {
|
||||
countryCodes: [countryCode],
|
||||
height: guessHeightFromTitle(title),
|
||||
title,
|
||||
...(mp4Head['content-length'] && { bytes: parseInt(mp4Head['content-length'] as string) }),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
import { NotFoundError } from '../error';
|
||||
import { guessHeightFromTitle } from '../utils';
|
||||
|
||||
export abstract class Extractor {
|
||||
public abstract readonly id: string;
|
||||
|
|
@ -20,7 +21,17 @@ export abstract class Extractor {
|
|||
|
||||
public async extract(ctx: Context, url: URL, countryCode: CountryCode, title?: string | undefined): Promise<UrlResult[]> {
|
||||
try {
|
||||
return await this.extractInternal(ctx, url, countryCode, title);
|
||||
const urlResults = await this.extractInternal(ctx, url, countryCode, title);
|
||||
|
||||
return urlResults.map((urlResult) => {
|
||||
let height = urlResult.meta.height;
|
||||
|
||||
if (!height && urlResult.meta.title) {
|
||||
height = guessHeightFromTitle(urlResult.meta.title);
|
||||
}
|
||||
|
||||
return { ...urlResult, meta: { ...urlResult.meta, height } };
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError) {
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import crypto from 'crypto';
|
||||
import { Extractor } from './Extractor';
|
||||
import { Fetcher, guessHeightFromTitle } from '../utils';
|
||||
import { Fetcher } from '../utils';
|
||||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
|
||||
/** @see https://github.com/Gujal00/ResolveURL/blob/master/script.module.resolveurl/lib/resolveurl/plugins/kinoger.py */
|
||||
|
|
@ -45,7 +45,6 @@ export class KinoGer extends Extractor {
|
|||
ttl: this.ttl,
|
||||
meta: {
|
||||
countryCodes: [countryCode],
|
||||
height: guessHeightFromTitle(title),
|
||||
title,
|
||||
},
|
||||
requestHeaders: {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import bytes from 'bytes';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { Extractor } from './Extractor';
|
||||
import { buildMediaFlowProxyExtractorRedirectUrl, Fetcher, guessHeightFromTitle, supportsMediaFlowProxy } from '../utils';
|
||||
import { buildMediaFlowProxyExtractorRedirectUrl, Fetcher, supportsMediaFlowProxy } from '../utils';
|
||||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
import { NotFoundError } from '../error';
|
||||
|
||||
|
|
@ -48,7 +48,6 @@ export class Mixdrop extends Extractor {
|
|||
ttl: this.ttl,
|
||||
meta: {
|
||||
countryCodes: [countryCode],
|
||||
height: guessHeightFromTitle(title),
|
||||
title,
|
||||
...(sizeMatch && {
|
||||
bytes: bytes.parse((sizeMatch[1] as string).replace(',', '')) as number,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { Extractor } from './Extractor';
|
|||
import {
|
||||
buildMediaFlowProxyExtractorRedirectUrl,
|
||||
Fetcher,
|
||||
guessHeightFromTitle,
|
||||
supportsMediaFlowProxy,
|
||||
} from '../utils';
|
||||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
|
|
@ -42,7 +41,6 @@ export class Streamtape extends Extractor {
|
|||
ttl: this.ttl,
|
||||
meta: {
|
||||
countryCodes: [countryCode],
|
||||
height: guessHeightFromTitle(title),
|
||||
title,
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ exports[`ExternalUrl johnalwayssame.com with title 1`] = `
|
|||
"countryCodes": [
|
||||
"fr",
|
||||
],
|
||||
"height": undefined,
|
||||
"title": "Black Mirror 4x2",
|
||||
},
|
||||
"sourceId": "external_fr",
|
||||
|
|
@ -31,6 +32,7 @@ exports[`ExternalUrl netu.fanstream.us 1`] = `
|
|||
"countryCodes": [
|
||||
"fr",
|
||||
],
|
||||
"height": undefined,
|
||||
"title": undefined,
|
||||
},
|
||||
"sourceId": "external_fr",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ exports[`ExtractorRegistry returns external URLs if enabled by config 1`] = `
|
|||
"countryCodes": [
|
||||
"de",
|
||||
],
|
||||
"height": undefined,
|
||||
"title": undefined,
|
||||
},
|
||||
"sourceId": "external_de",
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ exports[`SuperVideo embed only 1`] = `
|
|||
"countryCodes": [
|
||||
"it",
|
||||
],
|
||||
"height": undefined,
|
||||
"title": "",
|
||||
},
|
||||
"sourceId": "supervideo_it",
|
||||
|
|
|
|||
Loading…
Reference in a new issue