Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix streamwish throwing 403 forbidden streams most of the time + Fix proxy header issue in gogoanime #589

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions dist/extractors/streamwish.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/extractors/streamwish.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/providers/anime/gogoanime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/providers/anime/gogoanime.js.map

Large diffs are not rendered by default.

47 changes: 27 additions & 20 deletions src/extractors/streamwish.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { VideoExtractor, IVideo } from '../models';
import { USER_AGENT } from '../utils';
import zlib from 'zlib';
class StreamWish extends VideoExtractor {
protected override serverName = 'streamwish';
protected override sources: IVideo[] = [];
Expand All @@ -8,19 +9,22 @@ class StreamWish extends VideoExtractor {
try {
const options = {
headers: {
Accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Encoding': 'gzip, deflate, zstd',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'max-age=0',
Priority: 'u=0, i',
'Sec-Ch-Ua': 'Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126',
Origin: videoUrl.origin,
Referer: videoUrl.origin,
'Sec-Ch-Ua': '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': 'Windows',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
'Referrer-Policy': 'no-referrer-when-downgrade',
Referer: videoUrl.href,
'User-Agent': USER_AGENT,
},
};
Expand All @@ -35,7 +39,7 @@ class StreamWish extends VideoExtractor {
let p = '';
if (match) {
const params = match[1].split(',').map(param => param.trim());
const encodedString = match[2];
const encodedString = match[0];

p = encodedString.split("',36,")?.[0].trim();
const a = 36;
Expand All @@ -53,38 +57,41 @@ class StreamWish extends VideoExtractor {
} else {
console.log('No match found');
}
const links = p.match(/file:\s*"([^"]+)"/) ?? [];
// console.log(links, "links");
const links = p.match(/file:\s*"([^"]+\.m3u8[^"]*)"/) ?? [];
let lastLink: string | null = null;
links.forEach((link: string) => {
if (link.includes('file:"')) {
link = link.replace('file:"', '').replace(new RegExp('"', 'g'), '');
}
const linkParser = new URL(link);
linkParser.searchParams.set('i', '0.0');
this.sources.push({
quality: lastLink! ? 'backup' : 'default',
url: link.replace(/&i=\d+,'\.4&/, '&i=0.4&'),
url: linkParser.href,
isM3U8: link.includes('.m3u8'),
});
lastLink = link;
});

const m3u8Content = await this.client.get(links[1].replace(/&i=\d+,'\.4&/, '&i=0.4&'), options);
try {
const m3u8Content = await this.client.get(this.sources[0].url, options);

if (m3u8Content.data.includes('EXTM3U')) {
const videoList = m3u8Content.data.split('#EXT-X-STREAM-INF:');
for (const video of videoList ?? []) {
if (!video.includes('m3u8')) continue;
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 = links[1].split('master.m3u8')[0] + video.split('\n')[1];
const quality = video.split('RESOLUTION=')[1].split(',')[0].split('x')[1];
const url = links[1].split('master.m3u8')[0] + video.split('\n')[1];
const quality = video.split('RESOLUTION=')[1].split(',')[0].split('x')[1];

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

return this.sources;
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions src/providers/anime/gogoanime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Gogoanime extends AnimeParser {
switch (server) {
case StreamingServers.GogoCDN:
return {
headers: { Referer: serverUrl.href },
headers: { Referer: serverUrl.origin },
sources: await new GogoCDN(this.proxyConfig, this.adapter).extract(serverUrl),
download: downloadUrl ? downloadUrl : `https://${serverUrl.host}/download${serverUrl.search}`,
};
Expand All @@ -210,14 +210,14 @@ class Gogoanime extends AnimeParser {
case StreamingServers.StreamWish:
return {
headers: {
Referer: serverUrl.href,
Referer: serverUrl.origin
},
sources: await new StreamWish(this.proxyConfig, this.adapter).extract(serverUrl),
download: downloadUrl ? downloadUrl : `https://${serverUrl.host}/download${serverUrl.search}`,
};
default:
return {
headers: { Referer: serverUrl.href },
headers: { Referer: serverUrl.origin },
sources: await new GogoCDN(this.proxyConfig, this.adapter).extract(serverUrl),
download: downloadUrl ? downloadUrl : `https://${serverUrl.host}/download${serverUrl.search}`,
};
Expand Down
Loading