@xct007/frieren-scraper
Version:
198 lines (197 loc) • 6.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.detail = exports.search = exports.latest = void 0;
const Utils_1 = require("../Utils");
const Constant_1 = require("../Constant");
async function latest() {
try {
const { data } = await Utils_1.Axios.get(Constant_1.OtakudesuBaseUrl + "/ongoing-anime").catch((e) => e?.response);
const $ = (0, Utils_1.Cheerio)(data);
const _temp = [];
$(".venz > ul > li").each((i, e) => {
const title = $(e).find("h2.jdlflm").text();
const day = $(e).find(".epztipe").text().trim();
const date = $(e).find(".newnime").text().trim();
const url = $(e).find(".thumb > a").attr("href");
const thumbnail = $(e).find(".thumbz > img").attr("src");
_temp.push({ title, day, date, url, thumbnail });
});
if (Array.isArray(_temp) && _temp.length) {
return _temp;
}
else {
throw new Error("_temp is not an Array");
}
}
catch (e) {
return {
error: true,
message: e?.TypeError || String(e),
};
}
}
exports.latest = latest;
async function search(query) {
try {
const { data } = await Utils_1.Axios.get(Constant_1.OtakudesuBaseUrl, {
params: {
s: query,
post_type: "anime",
},
}).catch((e) => e?.response);
const $ = (0, Utils_1.Cheerio)(data);
const _temp = [];
$(".venutama > .page > ul > li").each((i, e) => {
const title = $(e).find("h2").text().trim();
const url = $(e).find("h2 > a").attr("href");
const _set = [];
$(e)
.find(".set")
.each((_i, _e) => {
_set.push($(_e).text());
});
const _metadata = {};
_set.forEach((v) => {
const [a, b] = v.split(":");
Object.assign(_metadata, {
[a.toLowerCase().trim()]: b.trim(),
});
});
const thumbnail = $(e).find("img").attr("src");
_temp.push({ title, ..._metadata, url, thumbnail });
});
if (Array.isArray(_temp) && _temp.length) {
return _temp;
}
else {
throw new Error(`${query} probably not found`);
}
}
catch (e) {
return {
error: true,
message: e?.TypeError || String(e),
};
}
}
exports.search = search;
async function detail(url) {
try {
const { data } = await Utils_1.Axios.get(url).catch((e) => e?.response);
const $ = (0, Utils_1.Cheerio)(data);
if (/\/anime\//i.test(url)) {
const Info = {};
$(".infozingle > p").each((i, e) => {
Info[$(e).text().split(": ")[0].toLowerCase().replace(" ", "_")] = $(e)
.text()
.split(": ")[1];
});
const thumbnail = $(".fotoanime > img").attr("src");
const sinopsis = [];
$(".sinopc > p").each((i, e) => {
sinopsis.push($(e).text());
});
const hasEps = [];
let hasBatch = false;
$(".episodelist")
.find("a")
.each((i, e) => {
const _url = $(e).attr("href");
if (/\/batch\//i.test(_url)) {
hasBatch = _url;
}
});
$("#venkonten > div.venser > div.episodelist:nth-child(8)")
.find("a")
.each((i, e) => {
hasEps.push({
title: $(e).text(),
url: $(e).attr("href"),
});
});
return {
isAnime: true,
...Info,
thumbnail,
sinopsis: sinopsis.join("\n"),
url: {
batch: hasBatch,
episodes: [...hasEps],
},
};
}
else if (/\/batch\//i.test(url)) {
const title = $(".jdlrx > h1").text();
const thumbnail = $(".imganime").find("img").attr("src");
const episode = $(".totalepisode > .total").text();
const urls = {};
$("div.batchlink > ul > li").each((i, e) => {
const resolution = $(e)
.find("strong")
.text()
.replace(/MP4|MKV/g, "")
.trim();
$(e)
.find("a")
.each((_i, _e) => {
urls[resolution] = urls[resolution] ? urls[resolution] : [];
urls[resolution].push({
source: $(_e).text(),
url: $(_e).attr("href"),
});
});
});
return {
isBatch: true,
title,
episode,
thumbnail,
urls,
};
}
else if (/\/episode\//i.test(url)) {
const info = [];
let metadata = {};
$(".infozingle > p").each((i, e) => {
info.push($(e).text().split(": "));
});
metadata = info.reduce((final, [key, value]) => {
final[key.toLowerCase()] = value;
return final;
}, {});
const urls = {};
$("div.download > ul > li").each((i, e) => {
const resolution = $(e)
.find("strong")
.text()
.replace(/MP4|MKV/g, "")
.trim();
$(e)
.find("a")
.each((_i, _e) => {
urls[resolution] = urls[resolution] ? urls[resolution] : [];
urls[resolution].push({
source: $(_e).text(),
url: $(_e).attr("href"),
});
});
});
return {
isEpisode: true,
title: $(".download > h4").text(),
metadata,
urls,
};
}
else {
throw new Error("Url mismatch ?");
}
}
catch (e) {
return {
error: true,
message: e?.TypeError || String(e),
};
}
}
exports.detail = detail;