perf(extractor): do not guess size from mp4 for Streamtape
This commit is contained in:
parent
b8c5c1a4f3
commit
e11cf8986e
5 changed files with 359 additions and 26 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import bytes from 'bytes';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { Context, Format, Meta, UrlResult } from '../types';
|
||||
import {
|
||||
buildMediaFlowProxyExtractorRedirectUrl, MEDIAFLOW_DEFAULT_INIT,
|
||||
buildMediaFlowProxyExtractorRedirectUrl,
|
||||
supportsMediaFlowProxy,
|
||||
} from '../utils';
|
||||
import { guessSizeFromMp4 } from '../utils/size';
|
||||
import { Extractor } from './Extractor';
|
||||
|
||||
export class Streamtape extends Extractor {
|
||||
|
|
@ -17,22 +17,25 @@ export class Streamtape extends Extractor {
|
|||
}
|
||||
|
||||
public override normalize(url: URL): URL {
|
||||
return new URL(url.href.replace('/v/', '/e/'));
|
||||
return new URL(url.href.replace('/e/', '/v/'));
|
||||
}
|
||||
|
||||
protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise<UrlResult[]> {
|
||||
const headers = { Referer: meta.referer ?? url.href };
|
||||
|
||||
// Only needed to properly find non-existing files via 404 response
|
||||
await this.fetcher.text(ctx, new URL(url.href.replace('/v/', '/e/')), { headers });
|
||||
|
||||
const html = await this.fetcher.text(ctx, url, { headers });
|
||||
|
||||
const sizeMatch = html.match(/([\d.]+ ?[GM]B)/) as string[];
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
const title = $('meta[name="og:title"]').attr('content') as string;
|
||||
|
||||
const mp4Url = buildMediaFlowProxyExtractorRedirectUrl(ctx, 'Streamtape', url, headers);
|
||||
|
||||
return [
|
||||
{
|
||||
url: mp4Url,
|
||||
url: buildMediaFlowProxyExtractorRedirectUrl(ctx, 'Streamtape', url, headers),
|
||||
format: Format.mp4,
|
||||
label: this.label,
|
||||
sourceId: `${this.id}_${meta.countryCodes?.join('_')}`,
|
||||
|
|
@ -40,7 +43,7 @@ export class Streamtape extends Extractor {
|
|||
meta: {
|
||||
...meta,
|
||||
title,
|
||||
bytes: await guessSizeFromMp4(ctx, this.fetcher, mp4Url, MEDIAFLOW_DEFAULT_INIT),
|
||||
bytes: bytes.parse(sizeMatch[1] as string) as number,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
{"connection":"close","content-length":"1293552945","content-range":"bytes 0-1293552944/1293552945","content-type":"video/mp4","date":"Thu, 25 Sep 2025 19:52:25 GMT","etag":"\"6878008a-4d1a0d31\"","last-modified":"Wed, 16 Jul 2025 19:42:02 GMT","server":"nginx/1.24.0 (Ubuntu)"}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -6,13 +6,13 @@ exports[`Streamtape streamtape.com /e 1`] = `
|
|||
"format": "mp4",
|
||||
"label": "Streamtape (via MediaFlow Proxy)",
|
||||
"meta": {
|
||||
"bytes": 1293552945,
|
||||
"bytes": 1288490188,
|
||||
"countryCodes": [],
|
||||
"title": "WALL-E.2008.1080p.BrRip.x264.YIFY.mp4",
|
||||
},
|
||||
"sourceId": "streamtape_",
|
||||
"ttl": 900000,
|
||||
"url": "https://mediaflow.test.org/extractor/video?host=Streamtape&api_password=test&d=https%3A%2F%2Fstreamtape.com%2Fe%2FDjmZBG0K9gHkJ7z%2FWALL-E.2008.1080p.BrRip.x264.YIFY.mp4&h_referer=https%3A%2F%2Fstreamtape.com%2Fe%2FDjmZBG0K9gHkJ7z%2FWALL-E.2008.1080p.BrRip.x264.YIFY.mp4&redirect_stream=true",
|
||||
"url": "https://mediaflow.test.org/extractor/video?host=Streamtape&api_password=test&d=https%3A%2F%2Fstreamtape.com%2Fv%2FDjmZBG0K9gHkJ7z%2FWALL-E.2008.1080p.BrRip.x264.YIFY.mp4&h_referer=https%3A%2F%2Fstreamtape.com%2Fv%2FDjmZBG0K9gHkJ7z%2FWALL-E.2008.1080p.BrRip.x264.YIFY.mp4&redirect_stream=true",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue