From b7d7ffd419d75152e77ed480be5dc35d3ec5c0be Mon Sep 17 00:00:00 2001 From: aka paul <50n50@noreply.localhost> Date: Sun, 9 Nov 2025 18:24:55 +0000 Subject: [PATCH] Update himovies/himovies.js --- himovies/himovies.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/himovies/himovies.js b/himovies/himovies.js index 9669a6c..c7fb24a 100644 --- a/himovies/himovies.js +++ b/himovies/himovies.js @@ -1,10 +1,11 @@ async function searchResults(keyword) { const results = []; + const formattedKeyword = keyword.replace(/ /g, '-'); try { - const response = await fetchv2("https://himovies.sx/search/" + encodeURIComponent(keyword)); + const response = await fetchv2("https://himovies.sx/search/" + encodeURIComponent(formattedKeyword)); const html = await response.text(); - + console.log("Search HTML: " + html); const blocks = html.split('
').slice(1); for (const block of blocks) { @@ -65,35 +66,35 @@ async function extractEpisodes(url) { if (!showIdMatch) return JSON.stringify([]); const showId = showIdMatch[1]; - const seasonsRes = await fetchv2("https://himovies.sx/ajax/season/list/" + showId); const seasonsHtml = await seasonsRes.text(); - const seasonMatch = seasonsHtml.match(/data-id="(\d+)"/); - if (!seasonMatch) { + const seasonIdMatches = [...seasonsHtml.matchAll(/data-id="(\d+)"/g)]; + if (!seasonIdMatches.length) { return JSON.stringify([{ href: "https://himovies.sx/ajax/episode/list/" + showId, - number: 1 + number: 1, + season: 1 }]); } - const seasonId = seasonMatch[1]; - - const epsRes = await fetchv2("https://himovies.sx/ajax/season/episodes/" + seasonId); - const epsHtml = await epsRes.text(); - - const matches = epsHtml.match(/data-id="(\d+)"/g) || []; - - matches.forEach((m, i) => { - const id = m.replace(/data-id="|"/g, ""); - results.push({ - href: "https://himovies.sx/ajax/episode/servers/" + id, - number: i + 1 + const allEpisodes = await Promise.all(seasonIdMatches.map(async (match, seasonIdx) => { + const seasonId = match[1]; + const epsRes = await fetchv2("https://himovies.sx/ajax/season/episodes/" + seasonId); + const epsHtml = await epsRes.text(); + const episodeMatches = epsHtml.match(/data-id="(\d+)"/g) || []; + return episodeMatches.map((m, i) => { + const id = m.replace(/data-id="|"/g, ""); + return { + href: "https://himovies.sx/ajax/episode/servers/" + id, + number: i + 1, + season: seasonIdx + 1 + }; }); - }); + })); + const results = allEpisodes.flat(); return JSON.stringify(results); - } catch (err) { return JSON.stringify([{ href: "Error",