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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
const prompts = require('prompts');
const songs = require('../assets/content/songs.json');
const albums = require('../assets/content/albums.json');
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
const Fuse = require("fuse.js");
function reload() {
for (let songID of Object.keys(songs)) {
if (fs.existsSync("/opt/mist")) {
if (!fs.existsSync("/opt/mist/flac/" + songID + ".flac") || !fs.existsSync("/opt/mist/aac/" + songID + ".m4a") || !fs.existsSync("/opt/mist/jpeg/" + songID + ".jpg")) {
delete songs[songID];
}
} else {
if (!fs.existsSync("../assets/content/" + songID + ".flac") || !fs.existsSync("../assets/content/" + songID + ".m4a") || !fs.existsSync("../assets/content/" + songID + ".jpg")) {
delete songs[songID];
}
}
}
let idList = [...Object.keys(songs), ...Object.keys(albums)];
if (fs.existsSync("/opt/mist")) {
for (let file of fs.readdirSync("/opt/mist/flac")) {
if (fs.lstatSync("/opt/mist/flac/" + file).isFile()) {
let id = path.basename(file, path.extname(file));
if (!idList.includes(id) && !file.endsWith(".json")) {
fs.unlinkSync("/opt/mist/flac/" + file);
if (fs.existsSync("../assets/content/" + file)) fs.unlinkSync("../assets/content/" + file);
} else {
if (!fs.existsSync("../assets/content/" + file)) fs.symlinkSync("/opt/mist/flac/" + file, "../assets/content/" + file);
}
}
}
for (let file of fs.readdirSync("/opt/mist/aac")) {
if (fs.lstatSync("/opt/mist/aac/" + file).isFile()) {
let id = path.basename(file, path.extname(file));
if (!idList.includes(id) && !file.endsWith(".json")) {
fs.unlinkSync("/opt/mist/aac/" + file);
if (fs.existsSync("../assets/content/" + file)) fs.unlinkSync("../assets/content/" + file);
} else {
if (!fs.existsSync("../assets/content/" + file)) fs.symlinkSync("/opt/mist/aac/" + file, "../assets/content/" + file);
}
}
}
for (let file of fs.readdirSync("/opt/mist/jpeg")) {
if (fs.lstatSync("/opt/mist/jpeg/" + file).isFile()) {
let id = path.basename(file, path.extname(file));
if (!idList.includes(id) && !file.endsWith(".json")) {
fs.unlinkSync("/opt/mist/jpeg/" + file);
if (fs.existsSync("../assets/content/" + file)) fs.unlinkSync("../assets/content/" + file);
} else {
if (!fs.existsSync("../assets/content/" + file)) fs.symlinkSync("/opt/mist/jpeg/" + file, "../assets/content/" + file);
}
}
}
} else {
for (let file of fs.readdirSync("../assets/content")) {
if (fs.lstatSync("../assets/content/" + file).isFile()) {
let id = path.basename(file, path.extname(file));
if (!idList.includes(id) && !file.endsWith(".json")) {
fs.unlinkSync("../assets/content/" + file);
}
}
}
}
for (let albumID of Object.keys(albums)) {
let album = albums[albumID];
album["tracks"] = [...new Set(album["tracks"])].sort((a, b) => {
return songs[a]['track'] - songs[b]['track'];
});
}
fs.writeFileSync("../assets/content/songs.json", JSON.stringify(songs));
fs.writeFileSync("../assets/content/albums.json", JSON.stringify(albums));
}
reload();
console.log(chalk.bold("Mist metadata editor") + "\n");
const fuse = new Fuse([...Object.entries(songs).map(i => {
j = i[1];
j['_type'] = "song";
j['_id'] = i[0];
return j;
}), ...Object.entries(albums).map(i => {
j = i[1];
j['_type'] = "album";
j['_id'] = i[0];
return j;
})], {
keys: ['title', 'artist']
});
async function main() {
console.clear();
const response = await prompts({
type: 'text',
name: 'search',
message: 'Enter the name of a song or album:'
});
if (!response['search']) {
return;
}
let query = response['search'];
let results = fuse.search(query);
let items = [];
for (let result of results) {
items.push({
title: chalk.cyan(result.item._type === "song" ? "Song: " : "Album: ") + result.item.artist + " - " + result.item.title,
value: result.item._type + ":" + result.item._id
})
}
const select = await prompts({
type: 'select',
name: 'choice',
message: 'Select a song or album in the list.',
choices: items
});
if (!select['choice']) {
return;
}
await item(select['choice']);
}
async function item(meta) {
console.clear();
let id = meta.split(":")[1];
let type = meta.split(":")[0];
let item;
if (type === "song") item = songs[id];
if (type === "album") item = albums[id];
let options = [
{ title: "ID: " + id, value: "", disabled: true },
{ title: chalk.gray("Back"), value: "back" },
];
options.push({ title: chalk.red("Delete"), value: "delete" });
const select = await prompts({
type: 'select',
name: 'choice',
message: chalk.cyan(type === "song" ? "Song: " : "Album: ") + item.artist + " - " + item.title,
choices: options
});
if (!select['choice']) {
return;
}
if (select['choice'] === "back") {
main();
return;
}
if (select['choice'] === "delete") {
let confirm = await prompts({
type: 'confirm',
name: 'confirm',
message: 'Are you sure you want to delete this ' + type + '? This is permanent and will affect users.'
});
if (typeof confirm['confirm'] !== "boolean") {
return;
} else {
if (confirm['confirm']) {
// TODO: Delete
main();
} else {
}
}
}
}
main();
|