chore(handler): add height detection to Soaper

This commit is contained in:
WebStreamr 2025-06-08 18:21:52 +00:00
parent 2d9f602256
commit 7d0544a590
No known key found for this signature in database
4 changed files with 5931 additions and 2 deletions

View file

@ -2,6 +2,11 @@ import { Extractor } from './types';
import { Fetcher } from '../utils';
import { Context, Meta } from '../types';
interface SoaperInfoResponsePartial {
val: string;
val_bak: string;
}
export class Soaper implements Extractor {
readonly id = 'soaper';
@ -37,14 +42,21 @@ export class Soaper implements Extractor {
},
},
);
const jsonResponse = JSON.parse(response);
const jsonResponse = JSON.parse(response) as SoaperInfoResponsePartial;
const m3u8Url = new URL(jsonResponse['val'], url.origin);
const m3u8Data = await this.fetcher.text(ctx, m3u8Url);
const height = m3u8Data.match(/\d+x(\d+)|(\d+)p/) as string[];
return {
url: new URL(jsonResponse['val'], url.origin),
label: this.label,
sourceId: `${this.id}_${meta.countryCode.toLowerCase()}`,
ttl: this.ttl,
meta,
meta: {
...(height && { height: parseInt(height[1] ?? height[2] as string) }),
...meta,
},
};
};
}

View file

@ -6,6 +6,7 @@ exports[`Soaper handle imdb black mirror s4e2 1`] = `
"label": "Soaper",
"meta": {
"countryCode": "en",
"height": 720,
"title": "Black Mirror 4x2",
},
"sourceId": "soaper_en",
@ -21,6 +22,7 @@ exports[`Soaper handle imdb full metal jacket 1`] = `
"label": "Soaper",
"meta": {
"countryCode": "en",
"height": 1080,
"title": "Full Metal Jacket (1987)",
},
"sourceId": "soaper_en",
@ -36,6 +38,7 @@ exports[`Soaper handle tmdb black mirror s4e2 1`] = `
"label": "Soaper",
"meta": {
"countryCode": "en",
"height": 720,
"title": "Black Mirror 4x2",
},
"sourceId": "soaper_en",