Skip to content

Instantly share code, notes, and snippets.

@savikko
Last active June 18, 2020 20:36
Show Gist options
  • Save savikko/eaa10259c095a4ceb9906568328379cc to your computer and use it in GitHub Desktop.
Save savikko/eaa10259c095a4ceb9906568328379cc to your computer and use it in GitHub Desktop.

Fetch albums by artist

First install httpie and jq (pip install httpie, pip install jq).

Save mass-fetch.cmd and get-albums.cmd to one directory.

Then create inputfile.txt in the same directory which could be:

Metallica
"Dream Theater"
Leprous

Then run:

mass-fetch.cmd inputfile.txt

It will read inputfile.txt and process every line with get-albums.cmd and outputs to output.txt file:

Metallica;"Kill ’em All" 
Metallica;"Ride the Lightning" 
Metallica;"Master of Puppets" 
Metallica;"The $9.98 C.D. Garage Days Re-Revisited + B Side & Demos" 
Metallica;"…and Justice for All" 
...
Metallica;"Covering 'em" 
Metallica;"Do You Like Our Sound?" 
"Dream Theater";"When Dream and Day Unite" 
...
"Dream Theater";"The Covers" 
"Dream Theater";"When Demos and Singles Unite" 
"Dream Theater";"The Covers 2" 
Leprous;"Tall Poppy Syndrome" 
...
Leprous;"Silent Waters" 
Leprous;"Aeolia"
@echo off
REM Usage: get-albums.cmd "artist name"
REM Example: get-albums.cmd "Dream Theater"
REM Outputs artist;album name to output.txt
set artist=%1
del /q %TEMP%\artist.id
echo Getting artist id for artist %artist%
http https://musicbrainz.org/ws/2/artist?query=%artist%^&fmt=json |jq .artists^[0^].id > %TEMP%\artist.id
for /f "delims=" %%x in (%TEMP%\artist.id) do set artistid=%%x
echo Remote double quotes
set artistid=%artistid:"=%
echo Artist id for %artist%: %artistid%
http https://musicbrainz.org/ws/2/artist/%artistid%?inc=release-groups^&fmt=json |jq --arg a "release-groups" .[$a][].title > %TEMP%\recordings.lst
for /f "delims=" %%x in (%TEMP%\recordings.lst) do echo %artist%;%%x >> output.txt
@echo off
REM Usage: mass-fetch.cmd inputfile.txt
REM Inputfile.txt should include artist names (if contains spaces, surrounded with double quotes ")
for /f "delims=" %%x in (%1) do call get-albums.cmd %%x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment