-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (51 loc) · 1.85 KB
/
index.js
File metadata and controls
59 lines (51 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// I don't know what I'm doing rn, please send help it doesn't work AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// Require third party modules
const chalk = require('chalk'),
drawBanner = require("./scripts/banner.js"),
fs = require('graceful-fs'),
pause = require("press-any-key"),
setTitle = require("node-bash-title"),
search = require('yt-search');
// Load Configuration
chalk.level = 1;
const queries = fs.readFileSync('./data/queries.txt', "utf8").split("\n");
let progress = 0;
const currentTime = new Date().toISOString().match(/(\d{0}:){0}\d{0}/)[0];
// Define Functions
function sleep(ms) {
return new Promise(res => setTimeout(res, ms));
}
function getLine(filename, lineNum) {
const lines = fs.readFileSync(filename, "utf8").split("\n");
return lines[lineNum];
}
async function startup() {
drawBanner();
console.log("You can close this window at any time to stop the process\n");
await pause("Press any key to begin . . .");
drawBanner();
}
// Set the terminal window's title
setTitle("yt-resolve");
// Clean up the previous data
fs.appendFileSync('./data/results.txt', `\n${currentTime}\n`, 'utf8');
// Execute code
(async () => {
await startup();
while (progress < queries.length) {
const query = getLine("./data/queries.txt", progress);
console.log(chalk.yellow(`Searching: ${query}`));
const res = await search(query);
if (res && res.videos[0]) {
const videos = res.videos;
console.log(chalk.green(`Found video: ${videos[0].title}`));
fs.appendFileSync("./data/results.txt", `${videos[0].url}\n`);
progress++;
} else {
console.log(chalk.red('Could not find video! Ratelimit? Retrying . . .'));
}
await sleep(250);
}
console.log(chalk.green('\nTask finished, or no search queries in "./data/queries.txt"'));
await pause("Press any key to close this program . . .");
})()