diff --git a/animeworld/animeworld.js b/animeworld/animeworld.js index 0582d14..1914ddd 100644 --- a/animeworld/animeworld.js +++ b/animeworld/animeworld.js @@ -1,179 +1,166 @@ async function searchResults(keyword) { - const results = []; - const baseUrl = "https://animeworld.ac"; - - try { - const response = await soraFetch( - `${baseUrl}/search?keyword=${encodeURIComponent(keyword)}` - ); - const html = await response.text(); - - const filmListRegex = - /
([\s\S]*?)
<\/div>\s*<\/div>/; - const filmListMatch = html.match(filmListRegex); - - if (!filmListMatch) { - return JSON.stringify(results); - } - - const filmListContent = filmListMatch[1]; - const itemRegex = /
[\s\S]*?<\/div>[\s]*<\/div>/g; - const items = filmListContent.match(itemRegex) || []; - - items.forEach((itemHtml) => { - const imgMatch = itemHtml.match(/src="([^"]+)"/); - let imageUrl = imgMatch ? imgMatch[1] : ""; - - const titleMatch = itemHtml.match(/class="name">([^<]+)([\s\S]*?)
<\/div>\s*<\/div>/; + const filmListMatch = html.match(filmListRegex); + + if (!filmListMatch) { + return JSON.stringify(results); } - if (!href.startsWith("https")) { - if (href.startsWith("/")) { - href = baseUrl + href; - } else { - href = baseUrl + "/" + href; - } - } - results.push({ - title: title.trim(), - image: imageUrl, - href: href, + + const filmListContent = filmListMatch[1]; + const itemRegex = /
[\s\S]*?<\/div>[\s]*<\/div>/g; + const items = filmListContent.match(itemRegex) || []; + + items.forEach((itemHtml) => { + const imgMatch = itemHtml.match(/src="([^"]+)"/); + let imageUrl = imgMatch ? imgMatch[1] : ""; + + const titleMatch = itemHtml.match(/class="name">([^<]+)([\s\S]*?)<\/div>/); - let description = descriptionMatch ? descriptionMatch[1] : ""; - - const aliasesMatch = html.match(/

/); - let aliases = aliasesMatch ? aliasesMatch[1] : ""; - - const airdateMatch = html.match( - /
Data di Uscita:<\/dt>\s*
([^<]+)<\/dd>/ - ); - let airdate = airdateMatch ? airdateMatch[1] : ""; - - if (description && aliases && airdate) { - details.push({ - description: description, - aliases: aliases, - airdate: airdate, - }); + try { + const response = await soraFetch(url); + const html = await response.text(); + + const details = []; + + const descriptionMatch = html.match(/
([\s\S]*?)<\/div>/); + let description = descriptionMatch ? descriptionMatch[1] : ""; + + const aliasesMatch = html.match(/

/); + let aliases = aliasesMatch ? aliasesMatch[1] : ""; + + const airdateMatch = html.match(/
Data di Uscita:<\/dt>\s*
([^<]+)<\/dd>/); + let airdate = airdateMatch ? airdateMatch[1] : ""; + + if (description && aliases && airdate) { + details.push({ + description: description, + aliases: aliases, + airdate: airdate, + }); + } + + console.log(JSON.stringify(details)); + return JSON.stringify(details); + } catch (error) { + console.log("Details error:", error); + return JSON.stringify([]); } - - console.log(JSON.stringify(details)); - return JSON.stringify(details); - } catch (error) { - console.log("Details error:", error); - return JSON.stringify([]); - } } async function extractEpisodes(url) { - try { - const response = await soraFetch(url); - const html = await response.text(); - - const episodes = []; - const baseUrl = "https://animeworld.ac"; - - const serverActiveRegex = - /
]*>([\s\S]*?)<\/ul>\s*<\/div>/; - const serverActiveMatch = html.match(serverActiveRegex); - - if (!serverActiveMatch) { - return JSON.stringify(episodes); - } - - const serverActiveContent = serverActiveMatch[1]; - const episodeRegex = - /
  • \s*]*?href="([^"]+)"[^>]*?>([^<]+)<\/a>/g; - let match; - - while ((match = episodeRegex.exec(serverActiveContent)) !== null) { - let href = match[1]; - const number = parseInt(match[2], 10); - - if (!href.startsWith("https")) { - if (href.startsWith("/")) { - href = baseUrl + href; - } else { - href = baseUrl + "/" + href; + try { + const response = await soraFetch(url); + const html = await response.text(); + + const episodes = []; + const baseUrl = "https://animeworld.ac"; + + const serverActiveRegex = /
    ]*>([\s\S]*?)<\/ul>\s*<\/div>/; + const serverActiveMatch = html.match(serverActiveRegex); + + if (!serverActiveMatch) { + return JSON.stringify(episodes); } - } - - episodes.push({ - href: href, - number: number, - }); + + const serverActiveContent = serverActiveMatch[1]; + const episodeRegex = /
  • \s*]*?href="([^"]+)"[^>]*?>([^<]+)<\/a>/g; + let match; + + while ((match = episodeRegex.exec(serverActiveContent)) !== null) { + let href = match[1]; + const number = parseInt(match[2], 10); + + if (!href.startsWith("https")) { + if (href.startsWith("/")) { + href = baseUrl + href; + } else { + href = baseUrl + "/" + href; + } + } + + episodes.push({ + href: href, + number: number, + }); + } + + console.log(JSON.stringify(episodes)); + return JSON.stringify(episodes); + } catch (error) { + console.log("Episodes error:", error); + return JSON.stringify([]); } - - console.log(JSON.stringify(episodes)); - return JSON.stringify(episodes); - } catch (error) { - console.log("Episodes error:", error); - return JSON.stringify([]); - } } async function extractStreamUrl(url) { - try { - const response = await soraFetch(url); - const html = await response.text(); - - const idRegex = /]+href="([^"]+)"[^>]*id="alternativeDownloadLink"/; - const match = html.match(idRegex); - return match ? match[1] : null; - } catch (error) { - console.log("Stream URL error:", error); - return "https://files.catbox.moe/avolvc.mp4"; - } + try { + const pathParts = url.split('/'); + const code = pathParts[pathParts.length - 1]; + + const apiUrl = `https://www.animeworld.ac/api/episode/info?id=${code}&alt=0`; + + const response = await soraFetch(apiUrl); + const json = JSON.parse(await response.text()); + + return json.grabber; + } catch (error) { + console.log("Stream URL error:", error); + return "https://files.catbox.moe/avolvc.mp4"; + } } -async function soraFetch( - url, - options = { headers: {}, method: "GET", body: null, encoding: "utf-8" } -) { - try { - return await fetchv2( - url, - options.headers ?? {}, - options.method ?? "GET", - options.body ?? null, - true, - options.encoding ?? "utf-8" - ); - } catch (e) { +async function soraFetch(url, options = { headers: {}, method: "GET", body: null, encoding: "utf-8" }) { try { - return await fetch(url, options); - } catch (error) { - return null; + return await fetchv2(url, options.headers ?? {}, options.method ?? "GET", options.body ?? null, true, options.encoding ?? "utf-8"); + } catch (e) { + try { + return await fetch(url, options); + } catch (error) { + return null; + } } - } } \ No newline at end of file