mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 23:51:44 +00:00
1 line
5.7 KiB
JavaScript
1 line
5.7 KiB
JavaScript
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())})};exports.getMeta=void 0,exports.fetchEpisodesFromSelectedLink=fetchEpisodesFromSelectedLink;const headers={Referer:"https://google.com","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"};function fetchEpisodesFromSelectedLink(url,providerContext){return __awaiter(this,void 0,void 0,function*(){const{axios:axios,cheerio:cheerio}=providerContext,res=yield axios.get(url,{headers:headers}),$=cheerio.load(res.data),episodes=[];return $("h4").each((_,h4El)=>{const epTitle=$(h4El).text().trim();if(!epTitle)return;const directLinks=[];$(h4El).nextUntil("h4, hr").find("a[href]").each((_,linkEl)=>{let href=($(linkEl).attr("href")||"").trim();if(!href)return;href.startsWith("http")||(href=new URL(href,url).href);const btnText=$(linkEl).text().trim()||"Watch Episode";directLinks.push({link:href,title:btnText,quality:"AUTO",type:"episode"})}),directLinks.length>0&&episodes.push({title:epTitle,directLinks:directLinks})}),episodes})}const getMeta=function(_a){return __awaiter(this,arguments,void 0,function*({link:link,providerContext:providerContext}){var _b,_c;const{axios:axios,cheerio:cheerio}=providerContext;link.startsWith("http")||(link=new URL(link,"https://vgmlinks.click").href);try{const res=yield axios.get(link,{headers:headers}),$=cheerio.load(res.data),content=$(".entry-content, .post-inner").length?$(".entry-content, .post-inner"):$("body"),title=$("h1.entry-title").first().text().trim()||(null===(_b=$("meta[property='og:title']").attr("content"))||void 0===_b?void 0:_b.trim())||"Unknown",pageText=content.text(),type=/Season\s*\d+/i.test(pageText)||/Episode\s*\d+/i.test(pageText)?"series":"movie";let image=$(".poster img").attr("src")||$("meta[property='og:image']").attr("content")||$("meta[name='twitter:image']").attr("content")||"";image&&!image.startsWith("http")&&(image=new URL(image,link).href);let synopsis="";$(".entry-content p").each((_,el)=>{const txt=$(el).text().trim();if(txt.length>40&&!txt.toLowerCase().includes("download"))return synopsis=txt,!1});const imdbLink=$("a[href*='imdb.com']").attr("href")||"",imdbId=imdbLink?"tt"+((null===(_c=imdbLink.split("/tt")[1])||void 0===_c?void 0:_c.split("/")[0])||""):"",tags=[];$(".entry-content p strong").each((_,el)=>{const txt=$(el).text().trim();txt.match(/drama|biography|action|thriller|romance|adventure|animation/i)&&tags.push(txt)});const extra={};$("p").each((_,el)=>{var _a,_b,_c,_d,_e,_f;const html=$(el).html()||"";html.includes("Series Name")&&(extra.name=null===(_a=$(el).text().split(":")[1])||void 0===_a?void 0:_a.trim()),html.includes("Language")&&(extra.language=null===(_b=$(el).text().split(":")[1])||void 0===_b?void 0:_b.trim()),html.includes("Released Year")&&(extra.year=null===(_c=$(el).text().split(":")[1])||void 0===_c?void 0:_c.trim()),html.includes("Quality")&&(extra.quality=null===(_d=$(el).text().split(":")[1])||void 0===_d?void 0:_d.trim()),html.includes("Episode Size")&&(extra.size=null===(_e=$(el).text().split(":")[1])||void 0===_e?void 0:_e.trim()),html.includes("Format")&&(extra.format=null===(_f=$(el).text().split(":")[1])||void 0===_f?void 0:_f.trim())});const links=[],episodeList=[],isInformationalHeading=text=>{const lowerText=text.toLowerCase();return lowerText.includes("series info")||lowerText.includes("series name")||lowerText.includes("language")||lowerText.includes("released year")||lowerText.includes("episode size")||lowerText.includes("format")||lowerText.includes("imdb rating")||lowerText.includes("winding up")||lowerText.length<5&&!/\d/.test(lowerText)};return"series"===type?content.find("h3").each((_,h3)=>{var _a;const h3Text=$(h3).text().trim();if(isInformationalHeading(h3Text))return;const qualityMatch=(null===(_a=h3Text.match(/\d+p/))||void 0===_a?void 0:_a[0])||"AUTO",vcloudLink=$(h3).nextUntil("h3, hr").find("a").filter((_,a)=>/v-cloud|mega|gdrive|download/i.test($(a).text())).first(),href=vcloudLink.attr("href");if(href){const btnText=vcloudLink.text().trim()||"Link";if(btnText.toLowerCase().includes("imdb rating")||btnText.toLowerCase().includes("winding up"))return;links.push({title:h3Text,quality:qualityMatch,episodesLink:href})}}):content.find("h3, h5").each((_,heading)=>{var _a;const headingText=$(heading).text().trim();if(isInformationalHeading(headingText))return;const qualityMatch=(null===(_a=headingText.match(/\d+p/))||void 0===_a?void 0:_a[0])||"AUTO",linkEl=$(heading).nextUntil("h3, h5, hr").find("a[href]").first(),href=linkEl.attr("href");if(href){let finalHref=href.trim();finalHref.startsWith("http")||(finalHref=new URL(finalHref,link).href);const btnText=linkEl.text().trim()||"Download Link";if(btnText.toLowerCase().includes("imdb rating")||btnText.toLowerCase().includes("winding up"))return;links.push({title:headingText,quality:qualityMatch,episodesLink:"",directLinks:[{title:btnText,link:finalHref,type:"movie"}]})}}),{title:title,synopsis:synopsis,image:image,imdbId:imdbId,type:type,tags:tags,cast:[],rating:$(".entry-meta .entry-date").text().trim()||"",linkList:links,extraInfo:extra,episodeList:episodeList}}catch(err){return{title:"",synopsis:"",image:"",imdbId:"",type:"movie",tags:[],cast:[],rating:"",linkList:[],extraInfo:{},episodeList:[]}}})};exports.getMeta=getMeta; |