"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__name=(target,value)=>__defProp(target,"name",{value:value,configurable:!0}),__export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod),__async=(__this,__arguments,generator)=>new Promise((resolve,reject)=>{var fulfilled=value=>{try{step(generator.next(value))}catch(e){reject(e)}},rejected=value=>{try{step(generator.throw(value))}catch(e){reject(e)}},step=x=>x.done?resolve(x.value):Promise.resolve(x.value).then(fulfilled,rejected);step((generator=generator.apply(__this,__arguments)).next())}),episodes_exports={};__export(episodes_exports,{getEpisodes:()=>getEpisodes});var formatEpisodeTitle=__name(fileName=>{try{const match=fileName.match(/S(\d+)E(\d+)/i);if(match){return`S${match[1].padStart(2,"0")} E${match[2].padStart(2,"0")}`}return fileName}catch(e){return fileName}},"formatEpisodeTitle"),getEpisodes=__name(function(_0){return __async(this,arguments,function*({url:url,providerContext:providerContext}){var _a,_b,_c,_d;const{axios:axios,cheerio:cheerio,commonHeaders:headers}=providerContext;console.log("getEpisodeLinks",url);try{const baseUrl=url.split("/").slice(0,3).join("/"),id=url.split("/").filter(Boolean).pop()||"",apiUrl=`${baseUrl}/api/packs/${id}`;let res;console.log("apiUrl:",apiUrl);try{res=yield axios.get(apiUrl,{headers:headers})}catch(error){if(404===(null==(_a=error.response)?void 0:_a.status)){const alternativeUrl=`${baseUrl}/api/s/${id}/`;console.log("Trying alternative URL:",alternativeUrl);const altRes=yield axios.get(alternativeUrl,{headers:headers});if(null==(_b=altRes.data)?void 0:_b.hasHubcloud){const hubcloudUrl=`${baseUrl}/api/s/${id}/hubcloud`;return[{title:formatEpisodeTitle(altRes.data.fileName||"Movie"),link:hubcloudUrl}]}return[]}throw error}const episodes=[],items=(null==(_d=null==(_c=res.data)?void 0:_c.pack)?void 0:_d.items)||[];for(const item of items)item.file_name&&item.hubcloud_link&&episodes.push({title:formatEpisodeTitle(item.file_name),link:item.hubcloud_link});return episodes}catch(err){throw err}})},"getEpisodes");exports.getEpisodes=getEpisodes;