refactor(extractor): remove embed part from extractor
This commit is contained in:
parent
8740979a80
commit
87ec328a66
25 changed files with 58 additions and 58 deletions
|
|
@ -1 +0,0 @@
|
|||
export * from './EmbedExtractorRegistry';
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import randomstring from 'randomstring';
|
||||
import { EmbedExtractor } from './types';
|
||||
import { Extractor } from './types';
|
||||
import { Fetcher } from '../utils';
|
||||
import { Context } from '../types';
|
||||
|
||||
// DoodStream does not return the pass_md5 from some IPs like e.g. Oracle cloud
|
||||
// In such cases a VPN might be needed
|
||||
export class DoodStream implements EmbedExtractor {
|
||||
export class DoodStream implements Extractor {
|
||||
readonly id = 'doodstream';
|
||||
|
||||
readonly label = 'DoodStream';
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import { EmbedExtractor } from './types';
|
||||
import { Extractor } from './types';
|
||||
import { extractUrlFromPacked, Fetcher } from '../utils';
|
||||
import { Context } from '../types';
|
||||
import bytes from 'bytes';
|
||||
|
||||
export class Dropload implements EmbedExtractor {
|
||||
export class Dropload implements Extractor {
|
||||
readonly id = 'dropload';
|
||||
|
||||
readonly label = 'Dropload';
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import winston from 'winston';
|
||||
import { EmbedExtractorRegistry } from './EmbedExtractorRegistry';
|
||||
import { ExtractorRegistry } from './ExtractorRegistry';
|
||||
import { Context } from '../types';
|
||||
import { Fetcher } from '../utils';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
|
@ -7,20 +7,20 @@ jest.mock('../utils/Fetcher');
|
|||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const embedExtractors = new EmbedExtractorRegistry(logger, fetcher);
|
||||
const extractorRegistry = new ExtractorRegistry(logger, fetcher);
|
||||
|
||||
describe('EmbedExtractorRegistry', () => {
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
test('returns undefined when no embed extractor can be found', async () => {
|
||||
const urlResult = await embedExtractors.handle(ctx, new URL('https://some-url.test'), 'en');
|
||||
const urlResult = await extractorRegistry.handle(ctx, new URL('https://some-url.test'), 'en');
|
||||
|
||||
expect(urlResult).toBeUndefined();
|
||||
});
|
||||
|
||||
test('returns from memory cache if possible', async () => {
|
||||
const urlResult1 = await embedExtractors.handle(ctx, new URL('https://dropload.io/lyo2h1snpe5c.html'), 'de');
|
||||
const urlResult2 = await embedExtractors.handle(ctx, new URL('https://dropload.io/lyo2h1snpe5c.html'), 'de');
|
||||
const urlResult1 = await extractorRegistry.handle(ctx, new URL('https://dropload.io/lyo2h1snpe5c.html'), 'de');
|
||||
const urlResult2 = await extractorRegistry.handle(ctx, new URL('https://dropload.io/lyo2h1snpe5c.html'), 'de');
|
||||
|
||||
expect(urlResult2).toBe(urlResult1);
|
||||
});
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
import TTLCache from '@isaacs/ttlcache';
|
||||
import winston from 'winston';
|
||||
import { EmbedExtractor } from './types';
|
||||
import { Extractor } from './types';
|
||||
import { Context, UrlResult } from '../types';
|
||||
import { Fetcher } from '../utils';
|
||||
import { DoodStream } from './DoodStream';
|
||||
import { Dropload } from './Dropload';
|
||||
import { SuperVideo } from './SuperVideo';
|
||||
|
||||
export class EmbedExtractorRegistry {
|
||||
export class ExtractorRegistry {
|
||||
private readonly logger: winston.Logger;
|
||||
private readonly embedExtractors: EmbedExtractor[];
|
||||
private readonly embedExtractors: Extractor[];
|
||||
private readonly urlResultCache: TTLCache<string, UrlResult>;
|
||||
|
||||
constructor(logger: winston.Logger, fetcher: Fetcher) {
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import bytes from 'bytes';
|
||||
import { EmbedExtractor } from './types';
|
||||
import { Extractor } from './types';
|
||||
import { extractUrlFromPacked, Fetcher } from '../utils';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class SuperVideo implements EmbedExtractor {
|
||||
export class SuperVideo implements Extractor {
|
||||
readonly id = 'supervideo';
|
||||
|
||||
readonly label = 'SuperVideo';
|
||||
1
src/extractor/index.ts
Normal file
1
src/extractor/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './ExtractorRegistry';
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { Context, UrlResult } from '../types';
|
||||
|
||||
export interface EmbedExtractor {
|
||||
export interface Extractor {
|
||||
readonly id: string;
|
||||
|
||||
readonly label: string;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import winston from 'winston';
|
||||
import { CineHDPlus } from './CineHDPlus';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Fetcher } from '../utils';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
|
@ -8,7 +8,7 @@ jest.mock('../utils/Fetcher');
|
|||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new CineHDPlus(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const handler = new CineHDPlus(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('CineHDPlus', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Handler } from './types';
|
||||
import { Fetcher, ImdbId, parseImdbId } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class CineHDPlus implements Handler {
|
||||
|
|
@ -14,9 +14,9 @@ export class CineHDPlus implements Handler {
|
|||
readonly languages = ['es', 'mx'];
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
private readonly embedExtractors: EmbedExtractorRegistry;
|
||||
private readonly embedExtractors: ExtractorRegistry;
|
||||
|
||||
constructor(fetcher: Fetcher, embedExtractors: EmbedExtractorRegistry) {
|
||||
constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) {
|
||||
this.fetcher = fetcher;
|
||||
this.embedExtractors = embedExtractors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import winston from 'winston';
|
||||
import { Eurostreaming } from './Eurostreaming';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Fetcher } from '../utils';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
|
@ -8,7 +8,7 @@ jest.mock('../utils/Fetcher');
|
|||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new Eurostreaming(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const handler = new Eurostreaming(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('Eurostreaming', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Handler } from './types';
|
||||
import { ImdbId, parseImdbId, Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class Eurostreaming implements Handler {
|
||||
|
|
@ -14,9 +14,9 @@ export class Eurostreaming implements Handler {
|
|||
readonly languages = ['it'];
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
private readonly embedExtractors: EmbedExtractorRegistry;
|
||||
private readonly embedExtractors: ExtractorRegistry;
|
||||
|
||||
constructor(fetcher: Fetcher, embedExtractors: EmbedExtractorRegistry) {
|
||||
constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) {
|
||||
this.fetcher = fetcher;
|
||||
this.embedExtractors = embedExtractors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { FrenchCloud } from './FrenchCloud';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new FrenchCloud(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const handler = new FrenchCloud(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('FrenchCloud', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Handler } from './types';
|
||||
import { Fetcher, parseImdbId } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class FrenchCloud implements Handler {
|
||||
|
|
@ -14,9 +14,9 @@ export class FrenchCloud implements Handler {
|
|||
readonly languages = ['fr'];
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
private readonly embedExtractors: EmbedExtractorRegistry;
|
||||
private readonly embedExtractors: ExtractorRegistry;
|
||||
|
||||
constructor(fetcher: Fetcher, embedExtractors: EmbedExtractorRegistry) {
|
||||
constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) {
|
||||
this.fetcher = fetcher;
|
||||
this.embedExtractors = embedExtractors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import winston from 'winston';
|
||||
import { KinoKiste } from './KinoKiste';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Fetcher } from '../utils';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
|
@ -8,7 +8,7 @@ jest.mock('../utils/Fetcher');
|
|||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new KinoKiste(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const handler = new KinoKiste(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('KinoKiste', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Handler } from './types';
|
||||
import { ImdbId, parseImdbId, Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class KinoKiste implements Handler {
|
||||
|
|
@ -14,9 +14,9 @@ export class KinoKiste implements Handler {
|
|||
readonly languages = ['de'];
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
private readonly embedExtractors: EmbedExtractorRegistry;
|
||||
private readonly embedExtractors: ExtractorRegistry;
|
||||
|
||||
constructor(fetcher: Fetcher, embedExtractors: EmbedExtractorRegistry) {
|
||||
constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) {
|
||||
this.fetcher = fetcher;
|
||||
this.embedExtractors = embedExtractors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { MeineCloud } from './MeineCloud';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new MeineCloud(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const handler = new MeineCloud(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('MeineCloud', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Handler } from './types';
|
||||
import { Fetcher, parseImdbId } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class MeineCloud implements Handler {
|
||||
|
|
@ -14,9 +14,9 @@ export class MeineCloud implements Handler {
|
|||
readonly languages = ['de'];
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
private readonly embedExtractors: EmbedExtractorRegistry;
|
||||
private readonly embedExtractors: ExtractorRegistry;
|
||||
|
||||
constructor(fetcher: Fetcher, embedExtractors: EmbedExtractorRegistry) {
|
||||
constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) {
|
||||
this.fetcher = fetcher;
|
||||
this.embedExtractors = embedExtractors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { MostraGuarda } from './MostraGuarda';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new MostraGuarda(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const handler = new MostraGuarda(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('MostraGuarda', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Handler } from './types';
|
||||
import { Fetcher, parseImdbId } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class MostraGuarda implements Handler {
|
||||
|
|
@ -14,9 +14,9 @@ export class MostraGuarda implements Handler {
|
|||
readonly languages = ['it'];
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
private readonly embedExtractors: EmbedExtractorRegistry;
|
||||
private readonly embedExtractors: ExtractorRegistry;
|
||||
|
||||
constructor(fetcher: Fetcher, embedExtractors: EmbedExtractorRegistry) {
|
||||
constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) {
|
||||
this.fetcher = fetcher;
|
||||
this.embedExtractors = embedExtractors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { VerHdLink } from './VerHdLink';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new VerHdLink(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const handler = new VerHdLink(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('VerHdLink', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import { Handler } from './types';
|
||||
import { Fetcher, parseImdbId } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { Context } from '../types';
|
||||
|
||||
export class VerHdLink implements Handler {
|
||||
|
|
@ -14,9 +14,9 @@ export class VerHdLink implements Handler {
|
|||
readonly languages = ['es', 'mx'];
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
private readonly embedExtractors: EmbedExtractorRegistry;
|
||||
private readonly embedExtractors: ExtractorRegistry;
|
||||
|
||||
constructor(fetcher: Fetcher, embedExtractors: EmbedExtractorRegistry) {
|
||||
constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) {
|
||||
this.fetcher = fetcher;
|
||||
this.embedExtractors = embedExtractors;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {
|
|||
MostraGuarda,
|
||||
VerHdLink,
|
||||
} from './handler';
|
||||
import { EmbedExtractorRegistry } from './embed-extractor';
|
||||
import { ExtractorRegistry } from './extractor';
|
||||
import { ConfigureController, ManifestController, StreamController } from './controller';
|
||||
import { Fetcher, StreamResolver } from './utils';
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ axiosRetry(axios, {
|
|||
|
||||
const fetcher = new Fetcher(axios, logger);
|
||||
|
||||
const embedExtractors = new EmbedExtractorRegistry(logger, fetcher);
|
||||
const embedExtractors = new ExtractorRegistry(logger, fetcher);
|
||||
|
||||
const handlers: Handler[] = [
|
||||
// ES / MX
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import winston from 'winston';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
import { StreamResolver } from './StreamResolver';
|
||||
import { MeineCloud, MostraGuarda } from '../handler';
|
||||
import { Fetcher } from './Fetcher';
|
||||
|
|
@ -12,7 +12,7 @@ const ctx: Context = { ip: '127.0.0.1' };
|
|||
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const embedExtractorRegistry = new EmbedExtractorRegistry(logger, fetcher);
|
||||
const embedExtractorRegistry = new ExtractorRegistry(logger, fetcher);
|
||||
const meineCloud = new MeineCloud(fetcher, embedExtractorRegistry);
|
||||
const mostraGuarda = new MostraGuarda(fetcher, embedExtractorRegistry);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import winston from 'winston';
|
|||
import { buildManifest } from './manifest';
|
||||
import { KinoKiste } from '../handler';
|
||||
import { Fetcher } from './Fetcher';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { ExtractorRegistry } from '../extractor';
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
|
|
@ -16,14 +16,14 @@ describe('buildManifest', () => {
|
|||
});
|
||||
|
||||
test('has unchecked handler without a config', () => {
|
||||
const manifest = buildManifest([new KinoKiste(fetcher, new EmbedExtractorRegistry(logger, fetcher))], {});
|
||||
const manifest = buildManifest([new KinoKiste(fetcher, new ExtractorRegistry(logger, fetcher))], {});
|
||||
|
||||
expect(manifest.config).toHaveLength(1);
|
||||
expect(manifest.config[0]?.default).toBeUndefined();
|
||||
});
|
||||
|
||||
test('has checked handler with appropriate config', () => {
|
||||
const kinokiste = new KinoKiste(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const kinokiste = new KinoKiste(fetcher, new ExtractorRegistry(logger, fetcher));
|
||||
const manifest = buildManifest([kinokiste], { [kinokiste.id]: 'on' });
|
||||
|
||||
expect(manifest.config).toHaveLength(1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue