mirror of
https://github.com/sussy-code/providers.git
synced 2026-03-31 06:58:34 +00:00
Merge pull request #5 from ztpn/ext-less
Add convertPlaylistsToDataUrls
This commit is contained in:
commit
964cddcae5
6 changed files with 42 additions and 7 deletions
|
|
@ -87,6 +87,7 @@
|
|||
"cookie": "^0.6.0",
|
||||
"crypto-js": "^4.2.0",
|
||||
"form-data": "^4.0.0",
|
||||
"hls-parser": "^0.13.2",
|
||||
"iso-639-1": "^3.1.2",
|
||||
"nanoid": "^3.3.7",
|
||||
"node-fetch": "^3.3.2",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ dependencies:
|
|||
form-data:
|
||||
specifier: ^4.0.0
|
||||
version: 4.0.0
|
||||
hls-parser:
|
||||
specifier: ^0.13.2
|
||||
version: 0.13.2
|
||||
iso-639-1:
|
||||
specifier: ^3.1.2
|
||||
version: 3.1.2
|
||||
|
|
@ -2531,6 +2534,10 @@ packages:
|
|||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/hls-parser@0.13.2:
|
||||
resolution: {integrity: sha512-lKZitdq8Awcsb271BkbUCzXgBBZEhnMNcyAqre/cns2hItCV8nF3ucleT2QS37Ck+eUv7LwAD1t+F/1D/Vxkgg==}
|
||||
dev: false
|
||||
|
||||
/html-escaper@2.0.2:
|
||||
resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==}
|
||||
dev: true
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { load } from 'cheerio';
|
||||
import crypto from 'crypto-js';
|
||||
|
||||
import { flags } from '@/entrypoint/utils/targets';
|
||||
import { makeEmbed } from '@/providers/base';
|
||||
import { convertPlaylistsToDataUrls } from '@/utils/playlist';
|
||||
|
||||
const { AES, MD5 } = crypto;
|
||||
|
||||
|
|
@ -113,9 +115,9 @@ export const playm4uNMScraper = makeEmbed({
|
|||
{
|
||||
id: 'primary',
|
||||
type: 'hls',
|
||||
playlist: apiRes.data,
|
||||
playlist: await convertPlaylistsToDataUrls(ctx.proxiedFetcher, apiRes.data),
|
||||
captions: [],
|
||||
flags: [],
|
||||
flags: [flags.CORS_ALLOWED],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// thanks Paradox_77
|
||||
import { load } from 'cheerio';
|
||||
|
||||
import { flags } from '@/entrypoint/utils/targets';
|
||||
import { SourcererEmbed, makeSourcerer } from '@/providers/base';
|
||||
import { compareMedia } from '@/utils/compare';
|
||||
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
||||
|
|
@ -150,7 +151,7 @@ export const m4uScraper = makeSourcerer({
|
|||
id: 'm4ufree',
|
||||
name: 'M4UFree',
|
||||
rank: 125,
|
||||
flags: [],
|
||||
flags: [flags.CORS_ALLOWED],
|
||||
scrapeMovie: universalScraper,
|
||||
scrapeShow: universalScraper,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { flags } from '@/entrypoint/utils/targets';
|
|||
import { Caption, labelToLanguageCode } from '@/providers/captions';
|
||||
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
||||
import { NotFoundError } from '@/utils/errors';
|
||||
import { convertPlaylistsToDataUrls } from '@/utils/playlist';
|
||||
|
||||
import { InfoResponse } from './types';
|
||||
import { SourcererOutput, makeSourcerer } from '../../base';
|
||||
|
|
@ -90,18 +91,18 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext): Pr
|
|||
stream: [
|
||||
{
|
||||
id: 'primary',
|
||||
playlist: streamResJson.val,
|
||||
playlist: await convertPlaylistsToDataUrls(ctx.proxiedFetcher, streamResJson.val),
|
||||
type: 'hls',
|
||||
flags: [flags.IP_LOCKED],
|
||||
flags: [flags.CORS_ALLOWED],
|
||||
captions,
|
||||
},
|
||||
...(streamResJson.val_bak
|
||||
? [
|
||||
{
|
||||
id: 'backup',
|
||||
playlist: streamResJson.val_bak,
|
||||
playlist: await convertPlaylistsToDataUrls(ctx.proxiedFetcher, streamResJson.val_bak),
|
||||
type: 'hls' as const,
|
||||
flags: [flags.IP_LOCKED],
|
||||
flags: [flags.CORS_ALLOWED],
|
||||
captions,
|
||||
},
|
||||
]
|
||||
|
|
|
|||
23
src/utils/playlist.ts
Normal file
23
src/utils/playlist.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { parse, stringify } from 'hls-parser';
|
||||
import { MasterPlaylist } from 'hls-parser/types';
|
||||
|
||||
import { UseableFetcher } from '@/fetchers/types';
|
||||
|
||||
export async function convertPlaylistsToDataUrls(
|
||||
fetcher: UseableFetcher,
|
||||
playlistUrl: string,
|
||||
headers?: Record<string, string>,
|
||||
) {
|
||||
const playlistData = await fetcher(playlistUrl, { headers });
|
||||
const playlist = parse(playlistData);
|
||||
|
||||
if (playlist.isMasterPlaylist) {
|
||||
for (const variant of (playlist as MasterPlaylist).variants) {
|
||||
const variantPlaylistData = await fetcher(variant.uri, { headers });
|
||||
const variantPlaylist = parse(variantPlaylistData);
|
||||
variant.uri = `data:application/vnd.apple.mpegurl;base64,${btoa(stringify(variantPlaylist))}`;
|
||||
}
|
||||
}
|
||||
|
||||
return `data:application/vnd.apple.mpegurl;base64,${btoa(stringify(playlist))}`;
|
||||
}
|
||||
Loading…
Reference in a new issue