import * as cheerio from "cheerio"; import axios from "axios"; import { headers } from "../configs/header.config.js"; import { URLS } from "../configs/dataUrl.js"; const extractSuggestions = async (keyword) => { try { const url = `${URLS.search}?keyword=${encodeURIComponent(keyword)}`; const { data } = await axios.get(url, { headers }); const $ = cheerio.load(data); const suggestions = []; $("#list-items > .item").each((i, el) => { const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || ""; const poster = $(el).find(".ani.poster.tip > a > img").attr("src") || ""; const title = $(el).find(".info .b1 a.name.d-title").text().trim() || ""; const japaneseTitle = $(el).find(".info .b1 a.name.d-title").attr("data-jp") || ""; const type = $(el).find(".info .meta .m-item:nth-child(2) label").text().trim() || ""; const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0; const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0; if (slug) { suggestions.push({ slug, poster, title, japaneseTitle, type, sub, dub }); } }); return suggestions.slice(0, 10); } catch (error) { throw error; } }; export { extractSuggestions };