// @ts-check const fs = require("fs") const os = require("os") const {tag} = require("@cloudrac3r/html-template-tag") const collection = JSON.parse(fs.readFileSync("scripts/collection.json", "utf8")) const table = collection.items.map(item => { const artist = item.band_name.replace(/[:,/[\]]/g, "-") const title = item.item_title.replace(/[:/|[\]]/g, "-").replace(/^[-.]+|-+$/g, "").replace(/--+/g, "-").replaceAll("\u3000", " ") const file = `${artist} - ${title}` const exists = fs.existsSync(`/var/home/cadence/Music/${file}`) || fs.existsSync(`/var/home/cadence/Music/${artist}/${file}.mp3`) const saleID = `${item.sale_item_type}${item.sale_item_id}` const url = collection.redownload_urls[saleID] return { subdomain: item.url_hints.subdomain, exists: exists ? "✅ " : "", file: file, url } }) table.sort((a, b) => { if (a.file < b.file) return -1 else if (a.file === b.file) return 0 else return 1 }) const labels = Object.groupBy(table, x => x.subdomain) const file = process.cwd() + "/download-selector.html" const o = fs.createWriteStream(file, "utf8") o.write(tag``) o.write(tag``) o.close() console.log(`Wrote: file://${file}`)