@@ -7,45 +7,47 @@ export async function decryptSources_v1(epID, id, name, type) {
77 try {
88 const [ { data : sourcesData } , { data : key } ] = await Promise . all ( [
99 axios . get ( `https://${ v1_base_url } /ajax/v2/episode/sources?id=${ id } ` ) ,
10- axios . get (
11- "https://raw.githubusercontent.com/itzzzme/megacloud-keys/refs/heads/main/key.txt" ,
12- ) ,
10+ axios . get ( "https://raw.githubusercontent.com/itzzzme/megacloud-keys/refs/heads/main/key.txt" ) ,
1311 ] ) ;
1412
1513 const ajaxLink = sourcesData ?. link ;
1614 if ( ! ajaxLink ) throw new Error ( "Missing link in sourcesData" ) ;
1715
18- const match = / \/ ( [ ^ \/ \ ?] + ) \? / . exec ( ajaxLink ) ;
19- const sourceId = match ?. [ 1 ] ;
16+ const sourceIdMatch = / \/ ( [ ^ / ? ] + ) \? / . exec ( ajaxLink ) ;
17+ const sourceId = sourceIdMatch ?. [ 1 ] ;
2018 if ( ! sourceId ) throw new Error ( "Unable to extract sourceId from link" ) ;
2119
22- const { data : rawSourceData } = await axios . get (
23- `https://megacloud.blog/embed-2/v3/e-1/getSources?id= ${ sourceId } ` ,
24- ) ;
20+ const baseUrlMatch = ajaxLink . match ( / ^ ( h t t p s ? : \/ \/ [ ^ \/ ] + (?: \/ [ ^ \/ ] + ) { 3 } ) / ) ;
21+ if ( ! baseUrlMatch ) throw new Error ( "Could not extract base URL from ajaxLink" ) ;
22+ const baseUrl = baseUrlMatch [ 1 ] ;
2523
26- let decryptedSources ;
24+ let decryptedSources = null ;
25+ let rawSourceData = { } ;
2726
2827 try {
28+ const { data } = await axios . get ( `${ baseUrl } /getSources?id=${ sourceId } ` ) ;
29+ rawSourceData = data ;
30+
2931 const encrypted = rawSourceData ?. sources ;
3032 if ( ! encrypted ) throw new Error ( "Encrypted source missing" ) ;
3133
32- const decrypted = CryptoJS . AES . decrypt ( encrypted , key . trim ( ) ) . toString (
33- CryptoJS . enc . Utf8 ,
34- ) ;
34+ const decrypted = CryptoJS . AES . decrypt ( encrypted , key . trim ( ) ) . toString ( CryptoJS . enc . Utf8 ) ;
3535 if ( ! decrypted ) throw new Error ( "Failed to decrypt source" ) ;
3636
3737 decryptedSources = JSON . parse ( decrypted ) ;
38- } catch ( e ) {
38+ } catch ( decryptionError ) {
3939 try {
40- const fallback = name . toLowerCase ( ) === 'hd-1' ?fallback_1 :fallback_2 ;
40+ const fallback = name . toLowerCase ( ) === "hd-1" ? fallback_1 : fallback_2 ;
41+
4142 const { data : html } = await axios . get (
4243 `https://${ fallback } /stream/s-2/${ epID } /${ type } ` ,
4344 {
4445 headers : {
4546 Referer : `https://${ fallback_1 } /` ,
4647 } ,
47- } ,
48+ }
4849 ) ;
50+
4951 const dataIdMatch = html . match ( / d a t a - i d = [ " ' ] ( \d + ) [ " ' ] / ) ;
5052 const realId = dataIdMatch ?. [ 1 ] ;
5153 if ( ! realId ) throw new Error ( "Could not extract data-id for fallback" ) ;
@@ -56,10 +58,13 @@ export async function decryptSources_v1(epID, id, name, type) {
5658 headers : {
5759 "X-Requested-With" : "XMLHttpRequest" ,
5860 } ,
59- } ,
61+ }
6062 ) ;
6163
6264 decryptedSources = [ { file : fallback_data . sources . file } ] ;
65+ rawSourceData . tracks = fallback_data . tracks ?? [ ] ;
66+ rawSourceData . intro = fallback_data . intro ?? null ;
67+ rawSourceData . outro = fallback_data . outro ?? null ;
6368 } catch ( fallbackError ) {
6469 throw new Error ( "Fallback failed: " + fallbackError . message ) ;
6570 }
0 commit comments