Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -1203,9 +1203,10 @@ async function scrapeHAnime(query) {
|
|
1203 |
}
|
1204 |
}
|
1205 |
|
|
|
1206 |
async function scrapeHAnimeDetails(url) {
|
1207 |
const browser = await puppeteer.launch({
|
1208 |
-
headless: true,
|
1209 |
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
1210 |
});
|
1211 |
|
@@ -1218,7 +1219,7 @@ async function scrapeHAnimeDetails(url) {
|
|
1218 |
// Buka halaman utama
|
1219 |
await page.goto(url, { waitUntil: "domcontentloaded" });
|
1220 |
|
1221 |
-
// Ambil metadata
|
1222 |
const result = await page.evaluate(() => {
|
1223 |
const getText = (selector) => {
|
1224 |
const element = document.querySelector(selector);
|
@@ -1226,9 +1227,8 @@ async function scrapeHAnimeDetails(url) {
|
|
1226 |
};
|
1227 |
|
1228 |
const getGenre = () => {
|
1229 |
-
return [...document.querySelectorAll("body > main > article > aside.anime-cn.clb > div.genres.mgt.df.fww.por > a")]
|
1230 |
-
(genre) => genre.textContent.trim()
|
1231 |
-
);
|
1232 |
};
|
1233 |
|
1234 |
return {
|
@@ -1242,7 +1242,7 @@ async function scrapeHAnimeDetails(url) {
|
|
1242 |
};
|
1243 |
});
|
1244 |
|
1245 |
-
console.log("
|
1246 |
|
1247 |
// Tunggu iframe muncul
|
1248 |
await page.waitForSelector(
|
@@ -1258,61 +1258,51 @@ async function scrapeHAnimeDetails(url) {
|
|
1258 |
return iframe ? iframe.src : null;
|
1259 |
});
|
1260 |
|
1261 |
-
|
1262 |
-
|
1263 |
-
// Tutup tab utama
|
1264 |
-
await page.close();
|
1265 |
|
1266 |
-
|
1267 |
-
|
1268 |
-
if (iframeSrc) {
|
1269 |
-
const responseA = await axios.get(`https://arashicode-api.hf.space/html?url=${iframeSrc}`);
|
1270 |
-
// Ambil HTML dari halaman iframe
|
1271 |
-
console.log("Iframe HTML:", responseA.data);
|
1272 |
|
1273 |
-
|
1274 |
-
|
|
|
|
|
1275 |
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
|
|
|
1283 |
console.log("Data-ID URL:", dataId);
|
1284 |
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
}
|
1299 |
-
}
|
1300 |
-
}
|
1301 |
}
|
1302 |
|
1303 |
-
// Tambahkan video ke hasil metadata
|
1304 |
-
result.video = video;
|
1305 |
-
|
1306 |
-
// Tutup browser
|
1307 |
await browser.close();
|
1308 |
-
|
1309 |
return result;
|
1310 |
} catch (error) {
|
1311 |
-
console.
|
1312 |
|
1313 |
-
// Tutup browser jika terjadi
|
1314 |
await browser.close();
|
1315 |
-
return { error:
|
1316 |
}
|
1317 |
}
|
1318 |
|
|
|
1203 |
}
|
1204 |
}
|
1205 |
|
1206 |
+
|
1207 |
async function scrapeHAnimeDetails(url) {
|
1208 |
const browser = await puppeteer.launch({
|
1209 |
+
headless: true,
|
1210 |
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
1211 |
});
|
1212 |
|
|
|
1219 |
// Buka halaman utama
|
1220 |
await page.goto(url, { waitUntil: "domcontentloaded" });
|
1221 |
|
1222 |
+
// Ambil metadata
|
1223 |
const result = await page.evaluate(() => {
|
1224 |
const getText = (selector) => {
|
1225 |
const element = document.querySelector(selector);
|
|
|
1227 |
};
|
1228 |
|
1229 |
const getGenre = () => {
|
1230 |
+
return [...document.querySelectorAll("body > main > article > aside.anime-cn.clb > div.genres.mgt.df.fww.por > a")]
|
1231 |
+
.map((genre) => genre.textContent.trim());
|
|
|
1232 |
};
|
1233 |
|
1234 |
return {
|
|
|
1242 |
};
|
1243 |
});
|
1244 |
|
1245 |
+
//console.log("Metadata:", result);
|
1246 |
|
1247 |
// Tunggu iframe muncul
|
1248 |
await page.waitForSelector(
|
|
|
1258 |
return iframe ? iframe.src : null;
|
1259 |
});
|
1260 |
|
1261 |
+
if (!iframeSrc) throw new Error("Iframe tidak ditemukan!");
|
|
|
|
|
|
|
1262 |
|
1263 |
+
console.log("Iframe Source:", iframeSrc);
|
|
|
|
|
|
|
|
|
|
|
1264 |
|
1265 |
+
// Gunakan API HTML untuk mengambil data iframe
|
1266 |
+
const responseA = await axios.get(`https://arashicode-api.hf.space/html?url=${iframeSrc}`);
|
1267 |
+
const iframeHTML = responseA.data;
|
1268 |
+
result.iframeHTML = iframeHTML;
|
1269 |
|
1270 |
+
// Ambil data-id dari HTML iframe
|
1271 |
+
const $ = cheerio.load(iframeHTML);
|
1272 |
+
const dataIdElement = $("div.servers > ul > li");
|
1273 |
+
const dataId = dataIdElement.length
|
1274 |
+
? "https://nhplayer.com" + dataIdElement.attr("data-id")
|
1275 |
+
: null;
|
1276 |
|
1277 |
+
if (dataId) {
|
1278 |
console.log("Data-ID URL:", dataId);
|
1279 |
|
1280 |
+
// Ambil konten dari data-id
|
1281 |
+
const responseB = await axios.get(`https://arashicode-api.hf.space/html?url=${dataId}`);
|
1282 |
+
const newPageHTML = responseB.data;
|
1283 |
+
console.log("Data-ID URL:", newPageHTML);
|
1284 |
+
|
1285 |
+
// Cari video URL
|
1286 |
+
const newPageCheerio = cheerio.load(newPageHTML);
|
1287 |
+
newPageCheerio("script").each((i, script) => {
|
1288 |
+
const scriptContent = newPageCheerio(script).html();
|
1289 |
+
if (scriptContent && scriptContent.includes("jwplayer.setup")) {
|
1290 |
+
const match = scriptContent.match(/file:\s*"(https?:\/\/[^"]+\.mp4)"/);
|
1291 |
+
if (match && match[1]) {
|
1292 |
+
result.video = match[1];
|
1293 |
}
|
1294 |
+
}
|
1295 |
+
});
|
1296 |
}
|
1297 |
|
|
|
|
|
|
|
|
|
1298 |
await browser.close();
|
|
|
1299 |
return result;
|
1300 |
} catch (error) {
|
1301 |
+
console.log("Error scraping details:", error);
|
1302 |
|
1303 |
+
// Tutup browser jika terjadi error
|
1304 |
await browser.close();
|
1305 |
+
return { error: error.message };
|
1306 |
}
|
1307 |
}
|
1308 |
|