Skip to content

Commit

Permalink
StreamHub Extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Raghav1729 committed Jul 6, 2023
1 parent 8ce5610 commit 5f90cb9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/extractors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BilibiliExtractor from './bilibili';
import AsianLoad from './asianload';
import StreamLare from './streamlare';
import SmashyStream from './smashystream';
import StreamHub from './streamhub';

export {
GogoCDN,
Expand All @@ -24,6 +25,7 @@ export {
Filemoon,
BilibiliExtractor,
AsianLoad,
StreamHub,
StreamLare,
SmashyStream
SmashyStream,
};
62 changes: 62 additions & 0 deletions src/extractors/streamhub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import axios from 'axios';
import { load } from 'cheerio';

import { VideoExtractor, IVideo, ISubtitle } from '../models';

class StreamHub extends VideoExtractor {
protected override serverName = 'StreamHub';
protected override sources: IVideo[] = [];

override extract = async (videoUrl: URL): Promise<{ sources: IVideo[] } & { subtitles: ISubtitle[] }> => {
try {
const result: { sources: IVideo[]; subtitles: ISubtitle[] } = {
sources: [],
subtitles: [],
};

const { data } = await axios.get(videoUrl.href).catch(() => {
throw new Error('Video not found');
});

const $ = load(data);
const ss = $.html().indexOf('eval(function(p,a,c,k,e,d)');
const se = $.html().indexOf('</script>', ss);
const s = $.html().substring(ss, se).replace('eval', '');
const unpackedData = eval(s) as string;

const links = unpackedData.match(new RegExp('sources:\\[\\{src:"(.*?)"')) ?? [];
const m3u8Content = await axios.get(links[1], {
headers: {
Referer: links[1],
},
});

result.sources.push({
quality: 'auto',
url: links[1],
isM3U8: links[1].includes('.m3u8'),
});

if (m3u8Content.data.includes('EXTM3U')) {
const videoList = m3u8Content.data.split('#EXT-X-STREAM-INF:');
for (const video of videoList ?? []) {
if (!video.includes('m3u8')) continue;

const url = video.split('\n')[1];
const quality = video.split('RESOLUTION=')[1].split(',')[0].split('x')[1];

result.sources.push({
url: url,
quality: `${quality}p`,
isM3U8: url.includes('.m3u8'),
});
}
}

return result;
} catch (err) {
throw new Error((err as Error).message);
}
};
}
export default StreamHub;
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
StreamTape,
VidCloud,
StreamLare,
StreamHub,
SmashyStream
} from './extractors';
import {
Expand Down Expand Up @@ -100,6 +101,7 @@ export {
Kwik,
RapidCloud,
StreamTape,
StreamHub,
SmashyStream,
VizCloud,
Filemoon,
Expand Down

0 comments on commit 5f90cb9

Please sign in to comment.