Skip to content

Instantly share code, notes, and snippets.

@bplaat
Created November 19, 2021 14:00
Show Gist options
  • Save bplaat/67fc4c7f8cec85ae3626eb474d8919e2 to your computer and use it in GitHub Desktop.
Save bplaat/67fc4c7f8cec85ae3626eb474d8919e2 to your computer and use it in GitHub Desktop.
Simple Deno application that list Deezer album information
#!/usr/bin/env deno run --allow-net
import { parse } from "https://deno.land/std/flags/mod.ts";
const httpGetJson = async (url) => await (await fetch(url)).json();
const args = parse(Deno.args);
if (args._.length == 0) {
console.log('Give an album name!');
Deno.exit();
}
const albums = (await httpGetJson(`https://api.deezer.com/search/album?q=${encodeURIComponent(Deno.args[0])}`)).data;
if (albums.length == 0) {
console.log('No album found!');
Deno.exit();
}
const album = await httpGetJson('https://api.deezer.com/album/' + albums[0].id);
if ('l' in args || 'list' in args) {
const albumArtists = album.contributors.map(artist => artist.name);
console.log(`# ${album.title} by ${albumArtists.join(', ')}`);
let index = 1;
for (let track of album.tracks.data) {
track = await httpGetJson('https://api.deezer.com/track/' + track.id);
const trackArtists = albumArtists.concat(track.contributors.map(artist => artist.name)
.filter(name => albumArtists.indexOf(name) == -1));
console.log(
`${index.toString().padStart(album.nb_tracks.toString().length)}. ${track.title} ` +
`(${Math.floor(track.duration / 60).toString().padStart(2, '0')}:` +
`${(track.duration % 60).toString().padStart(2, '0')}) ` +
`by ${trackArtists.join(', ')}`
);
index += 1;
}
} else {
console.log('TODO');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment