import cheerio from "npm:cheerio";
import CryptoJS from "npm:crypto-js";
class AnimeScraper {
constructor(url) {
this.url = url;
this.result = [];
this.results = {
sourceA: "",
sourceB: "",
sourceC: "",
sourceD: "",
sourceE: "",
};
this.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "en-US,en;q=0.5",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
"X-Requested-With": "XMLHttpRequest",
"Priority": "u=4",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
};
}
async fetchPage() {
try {
const response = await fetch(this.url, { headers: this.headers });
if (!response.ok) throw new Error(`Failed to fetch page: ${response.statusText}`);
const $ = cheerio.load(await response.text());
const listItems = $(".anime_muti_link li");
this.result = listItems
.map((_, element) => {
const $element = $(element);
const $anchor = $element.find("a");
return {
class: $element.attr("class") || "",
rel: $anchor.attr("rel"),
video: $anchor.attr("data-video"),
text: $anchor.contents().first().text().trim(),
};
})
.get();
} catch (error) {
console.error("Error:", error);
}
}
async processServers() {
for (const server of this.result) {
if (server.class === "vidcdn") {
const data = await extract(server.video);
this.results.sourceA = data.source[0].file;
this.results.sourceB = data.source_bk[0].file;
}
console.log(server.class);
if (server.class === "doodstream") {
const id = server.video.split("/")[4];
const data = await (await fetch(`https://tempguy-scarletsole.web.val.run/dood/${id}`)).json();
this.results.sourceC = data.stream[0].qualities.unknown.url;
}
if (server.class === "streamwish") this.results.sourceD = server.video;
if (server.class === "vidhide") this.results.sourceE = server.video;
}
console.log(this.results);
}
}
async function extract(url) {
try {
const response = await fetch(url, {
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "en-US,en;q=0.5",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
"X-Requested-With": "XMLHttpRequest",
"Priority": "u=4",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
},
});
if (!response.ok) throw new Error(`Failed to fetch data: ${response.statusText}`);
const text = await response.text();
const $ = cheerio.load(text);