yt-forager/test.js

84 lines
3.1 KiB
JavaScript

const lib = require("./lib");
test();
async function test() {
console.log(`Testing for video metadata archive...`);
let page;
let closestArchive = await lib.fetchArchive(`https://www.youtube.com/watch?v=jNQXAC9IVRw`, {year: 2015});
let parsedArchive = lib.handleArchiveUrl(closestArchive);
if (!parsedArchive.parser) console.log(`Incompatible archive for:`, parsedArchive);
else {
page = await parsedArchive.parser.parse(parsedArchive.direct);
console.log(page);
}
console.log(`Testing for video file archive...`);
let vidArchive = await lib.isArchived(`https://www.youtube.com/watch?v=jNQXAC9IVRw`);
console.log(vidArchive);
console.log(`Testing thumbnail finding...`);
let thumbArchive = await lib.findThumbnail(`https://www.youtube.com/watch?v=jNQXAC9IVRw`);
console.log(thumbArchive);
console.log(`Testing channel pages for YouTube channel: "https://www.youtube.com/c/GibiASMR"`)
let dates = lib.getCompatibleDates();
let allIds = [];
let previouslyParsed;
for (let i in dates) {
let closestArchive = await lib.fetchArchive(`https://www.youtube.com/c/GibiASMR`, dates[i]);
let parsedArchive = lib.handleArchiveUrl(closestArchive);
if (parsedArchive?.parser !== null) {
if (previouslyParsed == parsedArchive.direct) continue;
console.log(`Parsing archive for "https://www.youtube.com/c/GibiASMR" at`, parsedArchive.date);
let metadata = await parsedArchive.parser.parse(parsedArchive.direct);
console.log(metadata);
if (!metadata) continue;
for (let a in metadata?.videos) {
// pushing videos to allIds to be checked later.
allIds.push(metadata.videos[a]);
}
previouslyParsed = parsedArchive.direct;
}
}
console.log(`Fetching alternative URL for "https://www.youtube.com/c/GibiASMR"...`);
let altUrl = await lib.altUrl(`https://www.youtube.com/c/GibiASMR`);
if (altUrl !== `https://www.youtube.com/c/GibiASMR`) {
for (let i in dates) {
let closestArchive = await lib.fetchArchive(altUrl, dates[i]);
let parsedArchive = lib.handleArchiveUrl(closestArchive);
if (parsedArchive?.parser !== null) {
if (previouslyParsed == parsedArchive.direct) continue;
console.log(`Parsing archive for "${altUrl}" at`, parsedArchive.date);
let metadata = await parsedArchive.parser.parse(parsedArchive.direct);
if (!metadata) continue;
console.log(metadata);
for (let a in metadata?.videos) {
// pushing videos to allIds to be checked later.
let exist = allIds.find(e => e.id == metadata.videos[a].id);
if (exist == null) allIds.push(metadata.videos[a]);
}
previouslyParsed = parsedArchive.direct;
}
}
}
console.log(`Found ${allIds.length} videos. Checking if they are archived.`);
for (let i in allIds) {
let alive = await lib.isAlive(allIds[i].id);
console.log(`alive:`, alive, allIds[i].id);
if (alive == false) {
let archived = await lib.isArchived(allIds[i].id, allIds[i].title);
console.log(`archived:`, archived, allIds[i].id);
console.log(allIds[i]);
}
}
}