43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import * as cheerio from 'cheerio';
|
|
import { Context, Format, Meta, UrlResult } from '../types';
|
|
import { Extractor } from './Extractor';
|
|
|
|
export class Fsst extends Extractor {
|
|
public readonly id = 'fsst';
|
|
|
|
public readonly label = 'Fsst';
|
|
|
|
public supports(_ctx: Context, url: URL): boolean {
|
|
return null !== url.host.match(/fsst/);
|
|
};
|
|
|
|
protected async extractInternal(ctx: Context, url: URL, meta: Meta): Promise<UrlResult[]> {
|
|
const headers = { Referer: meta.referer ?? url.href };
|
|
|
|
const html = await this.fetcher.text(ctx, url, { headers, noProxyHeaders: true });
|
|
|
|
const $ = cheerio.load(html);
|
|
const title = $('title').text().trim();
|
|
|
|
const filesMatch = html.match(/file:"(.*)"/) as string[];
|
|
|
|
return Promise.all(
|
|
(filesMatch[1] as string).split(',').map(async (fileString) => {
|
|
const heightAndUrlMatch = fileString.match(/\[?([\d]*)p?]?(.*)/) as string[];
|
|
const fileHref = heightAndUrlMatch[2] as string;
|
|
|
|
return {
|
|
url: await this.fetcher.getFinalRedirectUrl(ctx, new URL(fileHref), { headers, noProxyHeaders: true }, 1),
|
|
format: Format.mp4,
|
|
label: this.label,
|
|
sourceId: `${this.id}_${meta.countryCodes?.join('_')}`,
|
|
meta: {
|
|
...meta,
|
|
height: parseInt(heightAndUrlMatch[1] as string),
|
|
title,
|
|
},
|
|
};
|
|
}),
|
|
);
|
|
};
|
|
}
|