85 lines
2.3 KiB
JavaScript
Executable file
85 lines
2.3 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
const lib = require("./lib");
|
|
const fs = require("fs");
|
|
const minimist = require("minimist");
|
|
|
|
let args;
|
|
if (process.argv?.[0].includes("node")) args = minimist(process.argv.slice(2));
|
|
else args = minimist(process.argv.slice(1));
|
|
|
|
start();
|
|
|
|
async function start() {
|
|
let folders = args._;
|
|
|
|
console.log(`- Parsing folders (this may take a moment)...`);
|
|
|
|
let folder;
|
|
let ad = {
|
|
alive: [],
|
|
dead: []
|
|
}; // alive/dead object
|
|
|
|
for (let index in folders) {
|
|
folder = folders[index];
|
|
console.log(`- Scanning & parsing "${folder}"...`);
|
|
folder = await getFolder(folder);
|
|
folder = await filterFolder(folder, args);
|
|
console.log(`-- Got`, folder.length, `compatible files...`);
|
|
}
|
|
|
|
console.log(`- Beginning to test videos...`);
|
|
|
|
for (let index in folder) {
|
|
console.log(`-- Checking "${folder[index].name}"...`);
|
|
|
|
let check = await lib.check(folder[index].id);
|
|
console.log(`--- Got result:`, check);
|
|
|
|
if (check == true) ad.alive.push(folder[index]);
|
|
else ad.dead.push(folder[index]);
|
|
}
|
|
|
|
console.log(`- Done.`);
|
|
|
|
if (args.o || args.output) {
|
|
console.log(`-- Writing JSON...`);
|
|
let output = (args.o || args.output);
|
|
let json = JSON.stringify(ad, null, 2);
|
|
fs.writeFileSync(output, json);
|
|
console.log(`-- Output JSON to:`, output);
|
|
} else console.log(`-- JSON:`, ad);
|
|
}
|
|
|
|
async function getFolder(folder) {
|
|
if (folder.endsWith(`/`)) folder = folder.substring(0, folder.length - 1);
|
|
let array = [];
|
|
|
|
try {
|
|
let parsedFolder = fs.readdirSync(folder, {withFileTypes: true});
|
|
for (let index in parsedFolder) {
|
|
let isDir = parsedFolder[index].isDirectory();
|
|
if (isDir == true) {
|
|
let reFolder = await getFolder(`${folder}/${parsedFolder[index].name}`);
|
|
for (let index in reFolder) { array.push(reFolder[index]); }
|
|
} else array.push({ name: parsedFolder[index].name, parent: folder, type: "file" })
|
|
}
|
|
} catch(err) {
|
|
if (err.message.includes("permission denied")) console.log(`-- Skipping directory due to permission issues...`);
|
|
}
|
|
|
|
return array;
|
|
}
|
|
|
|
async function filterFolder(parsedFilter, args) {
|
|
let filtered = [];
|
|
|
|
for (let index in parsedFilter) {
|
|
let {name} = parsedFilter[index];
|
|
let file = lib.parseFilename(name, args);
|
|
if (file?.id) filtered.push(file);
|
|
}
|
|
|
|
return filtered;
|
|
} |