"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P(function(resolve){resolve(value)})).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getStream=void 0;const getStream=function(_a){return __awaiter(this,arguments,void 0,function*({link:url,type:type,providerContext:providerContext}){var _b;const{axios:axios,cheerio:cheerio}=providerContext,headers={"sec-ch-ua":'"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"Sec-Fetch-Site":"none","Sec-Fetch-User":"?1","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0"};try{if("movie"===type){const linkData=(yield axios.get(url,{headers:headers})).data;url=cheerio.load(linkData)('strong:contains("INSTANT")').parent().attr("href")||url}if(url.includes("fastilinks")){const fastilinksData=(yield axios.get(url,{headers:headers})).data,fastilinksKey=cheerio.load(fastilinksData)('input[name="_csrf_token_645a83a41868941e4692aa31e7235f2"]').attr("value"),fastilinksFormData=new FormData;fastilinksFormData.append("_csrf_token_645a83a41868941e4692aa31e7235f2",fastilinksKey||"");const fastilinksRes2=yield fetch(url,{method:"POST",headers:headers,body:fastilinksFormData}),fastilinksHtml=yield fastilinksRes2.text(),$$$=cheerio.load(fastilinksHtml);url=$$$('a:contains("mediafire")').attr("href")||$$$('a:contains("photolinx")').attr("href")||url}if(url.includes("photolinx")){const photolinxData=(yield axios.get(url,{headers:headers})).data,$$$=cheerio.load(photolinxData),access_token=$$$("#generate_url").attr("data-token"),body={type:"DOWNLOAD_GENERATE",payload:{access_token:access_token,uid:$$$("#generate_url").attr("data-uid")}},photolinxRes2=yield fetch("https://photolinx.shop/action",{headers:{"sec-fetch-site":"same-origin","x-requested-with":"xmlhttprequest",cookie:"PHPSESSID=9a8d855c700cf0711831c04960c2e2b4",Referer:"https://photolinx.shop/download/5mPkrBD0D2x","Referrer-Policy":"strict-origin-when-cross-origin"},body:JSON.stringify(body),method:"POST"}),photolinxData2=yield photolinxRes2.json(),dwUrl=null==photolinxData2?void 0:photolinxData2.download_url;if(dwUrl){return[{server:"Photolinx",link:dwUrl,type:"mkv"}]}}const html=(yield axios.get(url,{headers:headers})).data,streamLinks=[];let data={download:""};try{const key=(null===(_b=html.match(/formData\.append\('key',\s*'(\d+)'\);/))||void 0===_b?void 0:_b[1])||"",formData=new FormData;formData.append("key",key);const streamRes=yield fetch(url,{method:"POST",headers:headers,body:formData});data=yield streamRes.json()}catch(err){}let $=cheerio.load(html);const mediafireUrl=$('h1:contains("Download")').find("a").attr("href")||$(".input.popsok").attr("href");if(mediafireUrl){const urlContentType=(yield axios.head(mediafireUrl)).headers["content-type"];if(urlContentType&&urlContentType.includes("video"))return streamLinks.push({server:"Mediafire",link:mediafireUrl,type:"mkv"}),streamLinks;{const repairHtml=(yield axios.get(mediafireUrl,{headers:{Referer:url}})).data,hrefRegex=/window\.location\.href\s*=\s*['"]([^'"]+)['"]/,match=repairHtml.match(hrefRegex);let downloadLInk=match?match[1]:null;return downloadLInk&&streamLinks.push({server:"Mediafire",link:downloadLInk,type:"mkv"}),streamLinks}}const contentType=(yield axios.head(data.download)).headers["content-type"];if(contentType&&contentType.includes("video"))return streamLinks.push({server:"Mediafire",link:data.download,type:"mkv"}),streamLinks;{const repairHtml=(yield axios.get(data.download,{headers:{Referer:url}})).data,repairLink=cheerio.load(repairHtml)("#continue-btn").attr("href"),repairRequireRepairRes=yield axios.get("https://www.mediafire.com"+repairLink),repairDownloadLink=cheerio.load(repairRequireRepairRes.data)(".input.popsok").attr("href");repairDownloadLink&&streamLinks.push({server:"Mediafire",link:repairDownloadLink,type:"mkv"})}return streamLinks}catch(err){return[]}})};exports.getStream=getStream;