import * as cheerio from 'cheerio'; import { Context, Format, InternalUrlResult, Meta } from '../types'; import { extractUrlFromPacked, guessHeightFromPlaylist } from '../utils'; import { Extractor } from './Extractor'; export class Vidora extends Extractor { public readonly id = 'vidora'; public readonly label = 'Vidora'; public override readonly ttl: number = 43200000; // 12h public supports(_ctx: Context, url: URL): boolean { return null !== url.host.match(/vidora/); } public override normalize(url: URL): URL { return new URL(url.href.replace('/embed/', '/')); } protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise { const html = await this.fetcher.text(ctx, url); const $ = cheerio.load(html); const title = $('title').text().trim().replace(/^Watch /, '').trim(); const m3u8Url = extractUrlFromPacked(html, [/file: ?"(.*?)"/]); const headers = { Origin: url.origin }; return [ { url: m3u8Url, format: Format.hls, meta: { ...meta, height: meta.height ?? await guessHeightFromPlaylist(ctx, this.fetcher, m3u8Url, { headers }), title, }, requestHeaders: headers, }, ]; }; }