ariaa
Version:
A CLI for music lovers
70 lines • 2.63 kB
JavaScript
import { Command, logger } from "#lib/structures";
import { getAlbum, getClosestYoutubeTrack, getConfig, saveAlbum, searchSpotify } from "#utils";
import { blue, blueBright, greenBright, redBright } from "colorette";
import inquirer from "inquirer";
import ora from "ora";
var album_default = new Command({
description: "Save albums with ease! [Needs Spotify Credentials]",
args: [{ name: "name", description: "Name of album" }],
flags: [
{
longFlags: "mp3",
description: "save in .mp3 file"
},
{
longFlags: "flac",
description: "save in .flac file"
}
],
async run(args, flags) {
const { clientId, clientSecret } = getConfig(true);
if (!clientId.length || !clientSecret.length)
throw new Error(`${greenBright("Spotify")} credentials are ${redBright("required")} for this command!`);
const format = flags.mp3 ? "mp3" : flags.flac ? "flac" : void 0;
let albumName;
if (args) albumName = args;
else {
logger.debug("Album name was not provided!");
albumName = (await inquirer.prompt([
{
message: "Please enter name of the song to save:",
name: "albumName",
type: "input"
}
])).albumName;
}
if (!albumName.length) throw new Error("Album Name is mandatory");
if (albumName.match(/https:\/\/open\.spotify\.com\/album\/[a-zA-Z0-9]+/)) {
logger.debug("Detected Spotify URI");
const id2 = albumName.split("/").pop().split("?")[0];
const album2 = await getAlbum(id2);
const ytTracks2 = album2.tracks.items.map((r) => getClosestYoutubeTrack(r));
await saveAlbum(await Promise.all(ytTracks2), album2, format);
return;
}
const spinner = ora("Searching...").start();
const searches = await searchSpotify(albumName, "album", 5);
spinner.stop();
logger.debug(`Found ${blueBright(searches.albums.items.length)} results`);
if (!searches.albums.items.length) throw new Error(`No albums found!`);
const { id } = await inquirer.prompt([
{
name: "id",
message: "Results found",
type: "list",
loop: true,
choices: searches.albums.items.map((a) => ({
name: `${a.name} [${blue(a.artists.map((at) => at.name).join(", "))}] (${greenBright(`${a.total_tracks} tracks`)})`,
value: a.id
}))
}
]);
const album = await getAlbum(id);
const ytTracks = album.tracks.items.map((r) => getClosestYoutubeTrack(r));
await saveAlbum(await Promise.all(ytTracks), album, format);
}
});
export {
album_default as default
};
//# sourceMappingURL=album.js.map