-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (75 loc) · 2.38 KB
/
index.js
File metadata and controls
86 lines (75 loc) · 2.38 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { play } from "./utils/player.js";
import { search } from "@inquirer/prompts";
// import { input, confirm } from "@inquirer/prompts"
import { select, Separator } from "@inquirer/prompts";
import yts from "yt-search";
import ytdl from "@distube/ytdl-core";
import colors from "ansi-colors";
import { queue } from "./utils/queue.js";
console.log(
colors.cyan(`
_/_/_/_/ _/ _/_/_/ _/_/_/_/_/ _/ _/ _/_/_/ _/_/_/_/
_/ _/ _/ _/ _/ _/ _/ _/ _/
_/_/_/ _/ _/ _/ _/ _/ _/_/_/ _/_/_/
_/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/_/_/_/ _/_/_/ _/ _/_/ _/_/_/ _/_/_/_/
`)
);
var state = true;
while (state) {
const answer = await search({
message: "Search for music/playlist",
source: async (input, { signal }) => {
if (!input) {
return [];
}
const data = await yts(input);
return data.videos.map((pkg, i) => ({
name: `${i + 1}. ${colors.cyan(pkg.title)} ${colors.magenta(
pkg.timestamp
)}`,
value: { url: pkg.url, duration: pkg.seconds },
description: `${colors.bgMagentaBright(`By ${pkg.author.name}`)}`,
}));
},
});
queue.push(answer.url);
const user_mood = await select({
message: "Select a option to proceed",
choices: [
{
name: "add",
value: "add",
description: "add music to the queue",
},
{
name: "status",
value: "status",
description: "shows the player status",
},
new Separator(),
{
name: "exit",
value: "exit",
description: "exit the interface (player still keeps running)",
},
{
name: "terminate",
value: "terminate",
description: "kills the speaker process (to stop music)",
},
],
});
switch (user_mood) {
case "exit":
state = false;
break;
case "add":
continue;
case "status":
console.log(colors.cyan(JSON.stringify(queue.getStats())));
continue;
case "terminate":
process.exit();
}
}