UNPKG

@xct007/frieren-scraper

Version:
104 lines (103 loc) 3.3 kB
import { Axios, Cheerio } from "../Utils.js"; import { BokepSinBaseUrl } from "../Constant.js"; async function latest() { try { const { data } = await Axios.get(BokepSinBaseUrl).catch((e) => e?.response); const $ = Cheerio(data); const _temp = []; $("#content > div > div > div > div > div > div").each((i, e) => { const title = $(e).find("a.thumb").attr("title"); const views = $(e).find("span.views-number").text().trim(); const duration = $(e).find("span.duration").text().trim(); const url = $(e).find("a.thumb").attr("href"); const thumbnail = $(e).find("a.thumb > img").attr("data-src"); _temp.push({ title, views, duration, url, thumbnail }); }); if (Array.isArray(_temp) && _temp.length) { return _temp; } else { throw new Error("Results is not an array"); } } catch (e) { return { error: true, message: String(e), }; } } async function search(query) { try { const { data } = await Axios.request({ baseURL: BokepSinBaseUrl, url: `/search/${query}`, }).catch((e) => e?.response); const $ = Cheerio(data); const _temp = []; $("div.row.no-gutters > div").each((i, e) => { const title = $(e).find("a.thumb").attr("title"); const views = $(e).find("span.views-number").text().trim(); const duration = $(e).find("span.duration").text().trim(); const url = $(e).find("a.thumb").attr("href"); const thumbnail = $(e).find("a.thumb > img").attr("data-src"); _temp.push({ title, views, duration, url, thumbnail }); }); if (Array.isArray(_temp) && _temp.length) { return _temp; } else { throw new Error("Results is not an array"); } } catch (e) { return { error: true, message: String(e), }; } } async function detail(url) { if (!url.includes(BokepSinBaseUrl)) { return { error: true, message: `Invalid ${BokepSinBaseUrl} base url`, }; } try { const { data } = await Axios.get(url).catch((e) => e?.response); const $ = Cheerio(data); const views = $(".single-video-infos") .find(".views-number") .text() .trim(); const index = $(".video-player"); const title = $(index) .find("meta[itemprop='name']") .attr("content"); const duration = $(index) .find("meta[itemprop='duration']") .attr("content") .replace(/[^DHMS\0-9]/g, ""); const thumbnail = $(index) .find("meta[itemprop='thumbnailUrl']") .attr("content"); const embed = $(index) .find("meta[itemprop='embedURL']") .attr("content"); return { title, views, duration, thumbnail, embed, }; } catch (e) { return { error: true, message: String(e), }; } } export { latest, search, detail };