pstreams-providers/src/providers/embeds/streamvid.ts
2024-03-27 14:40:17 -05:00

36 lines
970 B
TypeScript

import * as unpacker from 'unpacker';
import { flags } from '@/entrypoint/utils/targets';
import { makeEmbed } from '@/providers/base';
const packedRegex = /(eval\(function\(p,a,c,k,e,d\).*\)\)\))/;
const linkRegex = /src:"(https:\/\/[^"]+)"/;
export const streamvidScraper = makeEmbed({
id: 'streamvid',
name: 'Streamvid',
rank: 215,
async scrape(ctx) {
// Example url: https://streamvid.net/fu1jaf96vofx
const streamRes = await ctx.proxiedFetcher<string>(ctx.url);
const packed = streamRes.match(packedRegex);
if (!packed) throw new Error('streamvid packed not found');
const unpacked = unpacker.unpack(packed[1]);
const link = unpacked.match(linkRegex);
if (!link) throw new Error('streamvid link not found');
return {
stream: [
{
type: 'hls',
id: 'primary',
playlist: link[1],
flags: [flags.CORS_ALLOWED],
captions: [],
},
],
};
},
});