diff options
author | RaindropsSys <raindrops@equestria.dev> | 2023-10-27 22:29:56 +0200 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2023-10-27 22:29:56 +0200 |
commit | 4d4308c46d4f7801c657cc79d2243e1a81831334 (patch) | |
tree | a2e392e0af92b9a3ca3d1b5afb841640276e2294 /includes | |
parent | 9f9d66afebc59c6c265c4424f7b8fb36d8876541 (diff) | |
download | mist-4d4308c46d4f7801c657cc79d2243e1a81831334.tar.gz mist-4d4308c46d4f7801c657cc79d2243e1a81831334.tar.bz2 mist-4d4308c46d4f7801c657cc79d2243e1a81831334.zip |
Updated 32 files, added 279 files, deleted 3 files and renamed 14 files (automated)
Diffstat (limited to 'includes')
-rw-r--r-- | includes/.DS_Store | bin | 6148 -> 6148 bytes | |||
-rw-r--r-- | includes/editor.js | 193 | ||||
-rw-r--r-- | includes/node_modules/.DS_Store | bin | 0 -> 8196 bytes | |||
-rw-r--r-- | includes/process.js | 24 | ||||
-rw-r--r-- | includes/restore.js | 22 | ||||
-rw-r--r-- | includes/watcher.js | 2 |
6 files changed, 42 insertions, 199 deletions
diff --git a/includes/.DS_Store b/includes/.DS_Store Binary files differindex d91aeee..ab60279 100644 --- a/includes/.DS_Store +++ b/includes/.DS_Store diff --git a/includes/editor.js b/includes/editor.js deleted file mode 100644 index df0baf3..0000000 --- a/includes/editor.js +++ /dev/null @@ -1,193 +0,0 @@ -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();
\ No newline at end of file diff --git a/includes/node_modules/.DS_Store b/includes/node_modules/.DS_Store Binary files differnew file mode 100644 index 0000000..c5a68c3 --- /dev/null +++ b/includes/node_modules/.DS_Store diff --git a/includes/process.js b/includes/process.js index 88a477b..0c34f94 100644 --- a/includes/process.js +++ b/includes/process.js @@ -16,9 +16,11 @@ const substitutes = [ if (!fs.existsSync("../assets/content/_")) fs.mkdirSync("../assets/content/_"); if (!fs.existsSync("../assets/content/songs.json")) fs.writeFileSync("../assets/content/songs.json", "{}"); if (!fs.existsSync("../assets/content/albums.json")) fs.writeFileSync("../assets/content/albums.json", "{}"); +if (!fs.existsSync("../assets/content/archive.json")) fs.writeFileSync("../assets/content/archive.json", "{}"); const songs = require('../assets/content/songs.json'); const albums = require('../assets/content/albums.json'); +const archive = require('../assets/content/archive.json'); function scandir(dir) { let count = 0; @@ -111,9 +113,9 @@ function timeToString(time) { function updateETA() { if (timePerOp.length > 5) { - process.stdout.write("(" + timeToString((list.length - index) * (timePerOp.reduce((a, b) => a + b) / timePerOp.length)) + ")"); + process.stdout.write("(" + timeToString((list.length - index) * (timePerOp.reduce((a, b) => a + b) / timePerOp.length)) + " remaining | " + index + "/" + list.length + " processed | " + ((index / list.length) * 100).toFixed(1) + "% complete)"); } else { - process.stdout.write(""); + process.stdout.write("(" + index + "/" + list.length + " processed | " + ((index / list.length) * 100).toFixed(1) + "% complete)"); } } @@ -163,12 +165,22 @@ function timeToString(time) { process.stdout.clearLine(null); process.stdout.cursorTo(0); console.log(" Encoding FLAC version..."); updateETA(); - cp.execFileSync("ffmpeg", ["-i", file, "-map", "0", "-map", "-0:v?", "-c:a", "copy", "/opt/mist/flac/" + id + ".flac"], { stdio: "ignore" }); + archive[id] = file; + fs.writeFileSync("../assets/content/archive.json", JSON.stringify(archive)); + fs.copyFileSync(file, "/opt/mist/flac/" + id + ".flac"); process.stdout.clearLine(null); process.stdout.cursorTo(0); console.log(" Extracting album art..."); updateETA(); - cp.execFileSync("ffmpeg", ["-i", file, "-an", "/opt/mist/jpeg/" + id + ".jpg"], { stdio: "ignore" }); + + try { + cp.execFileSync("ffmpeg", ["-i", file, "-an", "/opt/mist/jpeg/" + id + ".jpg"], { stdio: "ignore" }); + } catch (e) { + process.stdout.clearLine(null); process.stdout.cursorTo(0); + console.error(e); + updateETA(); + fs.copyFileSync("../assets/default.jpg", "/opt/mist/jpeg/" + id + ".jpg"); + } } else { process.stdout.clearLine(null); process.stdout.cursorTo(0); console.log(" Encoding AAC version..."); @@ -178,7 +190,9 @@ function timeToString(time) { process.stdout.clearLine(null); process.stdout.cursorTo(0); console.log(" Encoding FLAC version..."); updateETA(); - cp.execFileSync("ffmpeg", ["-i", file, "-map", "0", "-map", "-0:v?", "-c:a", "copy", "../assets/content/" + id + ".flac"], { stdio: "ignore" }); + archive[id] = file; + fs.writeFileSync("../assets/content/archive.json", JSON.stringify(archive)); + fs.copyFileSync(file, "../assets/content/" + id + ".flac"); process.stdout.clearLine(null); process.stdout.cursorTo(0); console.log(" Extracting album art..."); diff --git a/includes/restore.js b/includes/restore.js new file mode 100644 index 0000000..3edeb2a --- /dev/null +++ b/includes/restore.js @@ -0,0 +1,22 @@ +console.log("Reading archive..."); +const archive = require('../assets/content/archive.json'); +const fs = require('fs'); +const path = require('path'); + +let i = 1; + +for (let id of Object.keys(archive)) { + console.log("Restoring " + id + " to " + archive[id] + " (" + i + "/" + Object.keys(archive).length + ")"); + if (!fs.existsSync(path.dirname(archive[id]))) fs.mkdirSync(path.dirname(archive[id]), { recursive: true }); + fs.renameSync("../assets/content/" + id + ".flac", archive[id]); + i++; +} + +console.log("Cleaning up..."); +for (let file of fs.readdirSync("../assets/content")) { + if (!file.startsWith(".") && file !== "_") { + fs.rmSync("../assets/content/" + file, { recursive: true }); + } +} + +console.log("Done. Run the process.js script again to reprocess the data.");
\ No newline at end of file diff --git a/includes/watcher.js b/includes/watcher.js index 33f614a..b96c93d 100644 --- a/includes/watcher.js +++ b/includes/watcher.js @@ -3,7 +3,7 @@ const fs = require('fs'); let lastUpdate = 0; watch('..', { recursive: true }, function(evt, name) { - if (name.includes("includes/users") || name.includes("includes/tokens")) return; + if (name.includes("includes/users") || name.includes("includes/tokens") || name.includes("assets/content")) return; if (new Date().getTime() - lastUpdate > 60000) { let buildFile = fs.readFileSync("/opt/spotify/build.txt").toString().trim(); |