-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
47 lines (43 loc) · 1.4 KB
/
cli.js
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
#!/usr/bin/env node
const ytp = require('./src/index');
const query = require('./src/query');
const yargs = require('yargs');
const sanitize = (input) =>{
return String(input);
}
const builder = (cmd) =>{
cmd
.positional("playlist_id", {
describe: "youtube playlist id",
coerce: sanitize,
})
.option("quality", {
describe: "quality: highest | lowest | highestaudio | lowestaudio | highestvideo | lowestvideo",
coerce: sanitize,
})
.option("filter", {
describe: "video | videoonly | audio | audioonly",
coerce: sanitize,
})
}
const handler = (args) => {
// console.log(args);
query.get_playlist_data(args.quality && args.quality.includes("video") ? "mp4" : "mp3", args.playlist_id, { limit: Infinity }, playlist_data=>{
// console.log(playlist_data);
let i = 1;
Object.keys(playlist_data).forEach(video_id=>{
// console.log(playlist_data[video_id].dl.path);
setTimeout(()=>{
const yt_opts = {
quality: args.quality,
};
args.filter ? yt_opts.filter = args.filter : console.log("no filter provided");
query.dl(true, playlist_data[video_id].info, playlist_data[video_id].dl, yt_opts, dl_data=>{
ytp.log(query.dfix(dl_data));
});
}, 1000 * i);
i++;
})
});
}
yargs.command("* <playlist_id>", false, builder, handler).parse();