Skip to content

Commit 2a56332

Browse files
committed
added fallback streams to prevent null streaminglink
1 parent d4e8791 commit 2a56332

4 files changed

Lines changed: 45 additions & 11 deletions

File tree

src/extractors/streamInfo.extractor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async function extractStreamingInfo(id, name, type) {
5353
);
5454
}
5555
const streamingLink = await decryptSources_v1(
56+
id,
5657
requestedServer[0].data_id,
5758
name,
5859
type

src/parsers/decryptors/decrypt_v1.decryptor.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import axios from "axios";
22
import CryptoJS from "crypto-js";
33
import { v1_base_url } from "../../utils/base_v1.js";
4+
import { fallback_1, fallback_2 } from "../../utils/fallback.js";
45

5-
export async function decryptSources_v1(id, name, type) {
6+
export async function decryptSources_v1(epID, id, name, type) {
67
try {
78
const [{ data: sourcesData }, { data: key }] = await Promise.all([
89
axios.get(`https://${v1_base_url}/ajax/v2/episode/sources?id=${id}`),
910
axios.get(
10-
"https://raw.githubusercontent.com/itzzzme/megacloud-keys/refs/heads/main/key.txt"
11+
"https://raw.githubusercontent.com/itzzzme/megacloud-keys/refs/heads/main/key.txt",
1112
),
1213
]);
1314

@@ -19,21 +20,51 @@ export async function decryptSources_v1(id, name, type) {
1920
if (!sourceId) throw new Error("Unable to extract sourceId from link");
2021

2122
const { data: rawSourceData } = await axios.get(
22-
`https://megacloud.blog/embed-2/v2/e-1/getSources?id=${sourceId}`
23+
`https://megacloud.blog/embed-2/v3/e-1/getSources?id=${sourceId}`,
2324
);
24-
const encrypted = rawSourceData?.sources;
25-
if (!encrypted) throw new Error("Encrypted source missing in response");
26-
const decrypted = CryptoJS.AES.decrypt(encrypted, key.trim()).toString(
27-
CryptoJS.enc.Utf8
28-
);
29-
if (!decrypted) throw new Error("Failed to decrypt source");
3025

3126
let decryptedSources;
27+
3228
try {
29+
const encrypted = rawSourceData?.sources;
30+
if (!encrypted) throw new Error("Encrypted source missing");
31+
32+
const decrypted = CryptoJS.AES.decrypt(encrypted, key.trim()).toString(
33+
CryptoJS.enc.Utf8,
34+
);
35+
if (!decrypted) throw new Error("Failed to decrypt source");
36+
3337
decryptedSources = JSON.parse(decrypted);
3438
} catch (e) {
35-
throw new Error("Decrypted data is not valid JSON");
39+
try {
40+
const fallback = name.toLowerCase()==='hd-1'?fallback_1:fallback_2;
41+
const { data: html } = await axios.get(
42+
`https://${fallback}/stream/s-2/${epID}/${type}`,
43+
{
44+
headers: {
45+
Referer: `https://${fallback_1}/`,
46+
},
47+
},
48+
);
49+
const dataIdMatch = html.match(/data-id=["'](\d+)["']/);
50+
const realId = dataIdMatch?.[1];
51+
if (!realId) throw new Error("Could not extract data-id for fallback");
52+
53+
const { data: fallback_data } = await axios.get(
54+
`https://${fallback}/stream/getSources?id=${realId}`,
55+
{
56+
headers: {
57+
"X-Requested-With": "XMLHttpRequest",
58+
},
59+
},
60+
);
61+
62+
decryptedSources = [{ file: fallback_data.sources.file }];
63+
} catch (fallbackError) {
64+
throw new Error("Fallback failed: " + fallbackError.message);
65+
}
3666
}
67+
3768
return {
3869
id,
3970
type,

src/utils/base_v1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const v1_base_url = "hianimez.to";
1+
export const v1_base_url = "hianime.to";

src/utils/fallback.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const fallback_1="megaplay.buzz"
2+
export const fallback_2="vidwish.live"

0 commit comments

Comments
 (0)