refactor: introduce guessSizeFromMp4
This commit is contained in:
parent
cefc80fa55
commit
4a1a3b19aa
2 changed files with 14 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ import * as cheerio from 'cheerio';
|
|||
import randomstring from 'randomstring';
|
||||
import { NotFoundError } from '../error';
|
||||
import { Context, CountryCode, Format, UrlResult } from '../types';
|
||||
import { guessSizeFromMp4 } from '../utils/size';
|
||||
import { Extractor } from './Extractor';
|
||||
|
||||
export class DoodStream extends Extractor {
|
||||
|
|
@ -41,10 +42,7 @@ export class DoodStream extends Extractor {
|
|||
mp4Url = new URL(baseUrl);
|
||||
} else {
|
||||
mp4Url = new URL(`${baseUrl}${randomstring.generate(10)}?token=${token}&expiry=${Date.now()}`);
|
||||
const mp4Head = await this.fetcher.head(ctx, mp4Url, { headers: { Referer: url.origin } });
|
||||
if (mp4Head['content-length']) {
|
||||
bytes = parseInt(mp4Head['content-length'] as string);
|
||||
}
|
||||
bytes = await guessSizeFromMp4(ctx, this.fetcher, mp4Url, { headers: { Referer: url.origin } });
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
|
|||
12
src/utils/size.ts
Normal file
12
src/utils/size.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { Context } from '../types';
|
||||
import { CustomRequestInit, Fetcher } from './Fetcher';
|
||||
|
||||
export const guessSizeFromMp4 = async (ctx: Context, fetcher: Fetcher, url: URL, init?: CustomRequestInit): Promise<number | undefined> => {
|
||||
const mp4Head = await fetcher.head(ctx, url, init);
|
||||
|
||||
if (mp4Head['content-length']) {
|
||||
return parseInt(mp4Head['content-length'] as string);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
Loading…
Reference in a new issue