From 355521f1a6622db389be29d0505799cc82ce7966 Mon Sep 17 00:00:00 2001 From: GSTAR <44748406+GLlgGL@users.noreply.github.com> Date: Wed, 19 Nov 2025 22:41:33 +0100 Subject: [PATCH] Create Vidmoly.ts --- src/extractor/Vidmoly.ts | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/extractor/Vidmoly.ts diff --git a/src/extractor/Vidmoly.ts b/src/extractor/Vidmoly.ts new file mode 100644 index 0000000..b619694 --- /dev/null +++ b/src/extractor/Vidmoly.ts @@ -0,0 +1,85 @@ +import { NotFoundError } from '../error'; +import { Context, Format, Meta, UrlResult } from '../types'; +import { Extractor } from './Extractor'; +import { + buildMediaFlowProxyExtractorStreamUrl, + supportsMediaFlowProxy, + guessHeightFromPlaylist +} from '../utils'; +import * as cheerio from 'cheerio'; + +export class Vidmoly extends Extractor { + public readonly id = 'Vidmoly'; + public readonly label = 'VidMoly(MFP)'; + public override readonly ttl = 10800000; // 3h + public override viaMediaFlowProxy = true; + + private domains = ['vidmoly.me', 'vidmoly.to', 'vidmoly.net']; + + public supports(ctx: Context, url: URL): boolean { + return this.domains.some(d => url.host.includes(d)) && supportsMediaFlowProxy(ctx); + } + + // Normalize to embed URL + public override normalize(url: URL): URL { + let path = url.pathname.replace(/^\/+/, ''); + if (!path.startsWith('embed-')) path = `embed-${path}`; + if (!path.endsWith('.html')) path += '.html'; + return new URL(`${url.origin}/${path}`); + } + + protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise { + const headers: Record = { Referer: 'https://vidmoly.net' }; + + // --- 1. Fetch embed page for HLS --- + const embedHtml = await this.fetcher.text(ctx, url, headers); + if (!embedHtml || embedHtml.includes('Video not found')) throw new NotFoundError(); + + // Extract HLS URL from embed page + const sourcesMatch = embedHtml.match(/sources:\s*\[\{file:"(?[^"]+)"/); + const mediaUrl = sourcesMatch?.groups?.['url']; + + let height: number | undefined; + if (mediaUrl) { + const streamUrl = mediaUrl.startsWith('//') + ? 'https:' + mediaUrl + : mediaUrl.startsWith('/') + ? url.origin + mediaUrl + : mediaUrl; + + try { + // Pass the actual HLS URL (not MediaFlow) to get best height + height = await guessHeightFromPlaylist(ctx, this.fetcher, new URL(streamUrl), url, headers); + } catch { + // ignore + } + } + + // --- 2. Fetch main page for title --- + const mainUrl = url.href.replace('embed-', ''); + let title = this.label; + try { + const mainHtml = await this.fetcher.text(ctx, new URL(mainUrl), headers); + const $ = cheerio.load(mainHtml); + const vidDiv = $('div.vid-d'); + const innerSpan = vidDiv.find('span span').first(); + title = innerSpan.text().trim() || this.label; + title = title.replace(/\.mp4$/i, ''); + } catch { + // fallback + } + + // --- 3. MediaFlow proxy --- + const proxiedUrl = await buildMediaFlowProxyExtractorStreamUrl(ctx, this.fetcher, this.id, url, headers); + + return [{ + url: proxiedUrl, + format: Format.hls, + label: this.label, + sourceId: `${this.id}_${meta.countryCodes?.join('_') ?? 'all'}`, + ttl: this.ttl, + requestHeaders: headers, + meta: { ...meta, title, height }, + }]; + } +}