Skip to content

Commit

Permalink
feat(streamwish): Refactor StreamWish decoding to get proper hls urls
Browse files Browse the repository at this point in the history
  • Loading branch information
2004durgesh committed Sep 21, 2024
1 parent 84a7453 commit e85f989
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
38 changes: 34 additions & 4 deletions src/extractors/streamwish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,52 @@ class StreamWish extends VideoExtractor {
'User-Agent': USER_AGENT,
},
};
// console.log(videoUrl.href,"videoUrl")
const { data } = await this.client.get(videoUrl.href, options);
const links = data.match(/file:\s*"([^"]+)"/);
let lastLink = null;

// Code adapted from Zenda-Cross (https://github.com/Zenda-Cross/vega-app/blob/main/src/lib/providers/multi/multiGetStream.ts)
// Thank you to Zenda-Cross for the original implementation.

var functionRegex =

Check warning on line 33 in src/extractors/streamwish.ts

View check run for this annotation

codefactor.io / CodeFactor

src/extractors/streamwish.ts#L33

Unexpected var, use let or const instead. (no-var)
/eval\(function\((.*?)\)\{.*?return p\}.*?\('(.*?)'\.split/;
var match = functionRegex.exec(data);

Check warning on line 35 in src/extractors/streamwish.ts

View check run for this annotation

codefactor.io / CodeFactor

src/extractors/streamwish.ts#L35

Unexpected var, use let or const instead. (no-var)
let p = '';
if (match) {
var params = match[1].split(',').map(param => param.trim());

Check warning on line 38 in src/extractors/streamwish.ts

View check run for this annotation

codefactor.io / CodeFactor

src/extractors/streamwish.ts#L38

Unexpected var, use let or const instead. (no-var)
var encodedString = match[2];

Check warning on line 39 in src/extractors/streamwish.ts

View check run for this annotation

codefactor.io / CodeFactor

src/extractors/streamwish.ts#L39

Unexpected var, use let or const instead. (no-var)

p = encodedString.split("',36,")?.[0].trim();
let a = 36;

Check warning on line 42 in src/extractors/streamwish.ts

View check run for this annotation

codefactor.io / CodeFactor

src/extractors/streamwish.ts#L42

'a' is never reassigned. Use 'const' instead. (prefer-const)
let c = encodedString.split("',36,")[1].slice(2).split('|').length;
let k = encodedString.split("',36,")[1].slice(2).split('|');

Check warning on line 44 in src/extractors/streamwish.ts

View check run for this annotation

codefactor.io / CodeFactor

src/extractors/streamwish.ts#L44

'k' is never reassigned. Use 'const' instead. (prefer-const)

while (c--) {
if (k[c]) {
var regex = new RegExp('\\b' + c.toString(a) + '\\b', 'g');

Check warning on line 48 in src/extractors/streamwish.ts

View check run for this annotation

codefactor.io / CodeFactor

src/extractors/streamwish.ts#L48

Unexpected var, use let or const instead. (no-var)
p = p.replace(regex, k[c]);
}
}

// console.log('Decoded String:', p);
} else {
console.log('No match found');
}
const links = p.match(/file:\s*"([^"]+)"/) ?? [];
// console.log(links, "links");
let lastLink: string | null = null;
links.forEach((link: string) => {
if (link.includes('file:"')) {
link = link.replace('file:"', '').replace(new RegExp('"', 'g'), '');
}
this.sources.push({
quality: lastLink! ? 'backup' : 'default',
url: link,
url: link.replace(/&i=\d+,'\.4&/, '&i=0.4&'),
isM3U8: link.includes('.m3u8'),
});
lastLink = link;
});

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

if (m3u8Content.data.includes('EXTM3U')) {
const videoList = m3u8Content.data.split('#EXT-X-STREAM-INF:');
Expand Down
2 changes: 1 addition & 1 deletion src/providers/anime/gogoanime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ class Gogoanime extends AnimeParser {

// (async () => {
// const gogo = new Gogoanime();
// const search = await gogo.fetchEpisodeSources('jigokuraku-dub-episode-1');
// const search = await gogo.fetchEpisodeSources('jigokuraku-dub-episode-1',StreamingServers.StreamWish);
// console.log(search);
// })();

Expand Down
3 changes: 2 additions & 1 deletion test/anime/gogoanime.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { info } from 'console';
import { ANIME } from '../../src/providers';
import { StreamingServers } from '../../src/models';

jest.setTimeout(120000);

Expand All @@ -26,7 +27,7 @@ test('returns a filled array of servers', async () => {
});

test('returns a filled object of episode sources', async () => {
const data = await gogoanime.fetchEpisodeSources('spy-x-family-episode-9');
const data = await gogoanime.fetchEpisodeSources('spy-x-family-episode-9',StreamingServers.StreamWish);
expect(data.sources).not.toEqual([]);
});

Expand Down

0 comments on commit e85f989

Please sign in to comment.