import{t as e}from"./cache-DUthuMSu.mjs";import{t}from"./got-BBDj7u1e.mjs";import{load as n}from"cheerio";const r={path:`/games`,categories:[`game`],example:`/elamigos/games`,parameters:{},features:{requireConfig:!1,requirePuppeteer:!1,antiCrawler:!1,supportBT:!1,supportPodcast:!1,supportScihub:!1},radar:[{source:[`elamigos.site/`,`elamigos.site/index.html`],target:`/games`}],name:`Releases`,maintainers:[`Kylon92`],handler:i,description:`Latest game releases from ElAmigos`};async function i(e){let r=Number(e.req.query(`limit`))||40,i=`https://elamigos.site`,{data:a}=await t(i),s=o(n(a),r,i),c=await Promise.all(s.map(e=>l(e)));return{title:`ElAmigos - Latest Games`,link:i,description:`Latest game releases from ElAmigos (${c.length} entries)`,item:c}}function a(e,t=!1){let[n,r,i]=e.split(`.`).map(Number),a=new Date(Date.UTC(i,r-1,n));return t?new Date(a.getTime()+1440*60*1e3):a}function o(e,t,n){let r=/^\d{2}\.\d{2}\.\d{4}/,i=[],a=!1;return e(`h1, h3, h5`).each((o,s)=>{let c=e(s),l=s.tagName.toLowerCase();if(l===`h1`){let e=c.text().trim().match(r);if(!e)return;a=!0;for(let t of i)(t.pubDate===null||t.pubDate.trim()===``)&&(t.pubDate=e[0])}else if((l===`h3`||l===`h5`)&&a){let e=c.find(`a[href]`).first();if(!e.length||i.length>=t)return;let r=e.attr(`href`),a=c.text().replaceAll(`DOWNLOAD`,``).trim(),o=r.startsWith(`http`)?r:`${n}/${r.replace(/^\//,``)}`;i.push({title:a,link:o,pubDate:null})}}),i}function s(e){let t=e.match(/\b\d{2}\.\d{2}\.\d{4}\b/g)||[],n=[...new Set(t)],r=null;for(let e of n){let t=a(e);(r===null||t>r)&&(r=t)}return r}function c(e){let t=n(e);t(`script, style, link, nav`).remove(),t(`*`).each((e,n)=>{if(n.attribs){let e=Object.keys(n.attribs);for(let r of e)r.toLowerCase().startsWith(`on`)&&t(n).removeAttr(r)}});let r=t(`body`).html()||``;return r=r.replaceAll(/^\s*[\r\n]/gm,``).replaceAll(/body\s*\{\s*margin-top:\s*1em;\s*\}/gi,``).trim(),r}function l(n){let r=`elamigos:${n.link}`;return e.tryGet(r,async()=>{try{let{data:e}=await t(n.link),r=s(e),i=null;n.pubDate&&(i=a(n.pubDate,!0)),(i===null||r!==null&&r>i)&&(i=r);let o=c(e);return{title:n.title,link:n.link,pubDate:i===null?void 0:i.toUTCString(),description:o}}catch{return{title:n.title,link:n.link,description:`<p>View game page: <a href="${n.link}">${n.link}</a></p>`}}})}export{r as route};