Last active
January 14, 2025 18:51
-
-
Save niclashoyer/10426194 to your computer and use it in GitHub Desktop.
Download a jamendo album as flac using the new v3.0 API (remember to insert your own application client id)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# deps: bash, curl, sed, metaflac, jq | |
# remember to insert your own application client id (see CLIENTID below) | |
# to get an application client id register at http://developer.jamendo.com | |
set -e | |
set -u | |
function filtername() { | |
tr -cs "[:alnum:] \-&\(\)\?!" _ | |
} | |
function j() { | |
echo -n "$1" | jq -r "$2" | |
} | |
CLIENTID="YOUR_CLIENT_ID" | |
ALBUMID=$(echo "$1" | sed -e 's/.\+\/album\/\([0-9]\+\)\/.\+$/\1/') | |
BASEURL="http://api.jamendo.com/v3.0" | |
JSON=$(curl -s "$BASEURL/albums/tracks?client_id=$CLIENTID&format=json&limit=1&id=$ALBUMID&imagesize=500&audioformat=flac") | |
DATA=$(j "$JSON" '.results[0]') | |
IMGURL=$(j "$DATA" '.image') | |
ARTIST=$(j "$DATA" '.artist_name') | |
ALBUM=$(j "$DATA" '.name') | |
RELEASEDATE=$(j "$DATA" '.releasedate') | |
ALBUMDIR=$(echo -n "$ARTIST - $ALBUM" | filtername) | |
TRACKS=$(j "$JSON" '.results[0].tracks') | |
LENGTH=$(j "$TRACKS" '.|length') | |
PADLENGTH=$(printf %02d $LENGTH) | |
echo "$ARTIST - $ALBUM" | |
echo "Creating directory..." | |
mkdir -p "$ALBUMDIR" | |
cd "$ALBUMDIR" | |
echo "Saving album cover..." | |
curl -s -z folder.jpg -o folder.jpg "$IMGURL" | |
for ((i=0; i<$LENGTH; i++)); do | |
TRACK=$(j "$TRACKS" ".[$i]") | |
NAME=$(j "$TRACK" '.name') | |
POS=$(printf "%02d\n" $(j "$TRACK" '.position')) | |
FILENAME=$(echo -n "$POS - $ARTIST - $NAME" | filtername)".flac" | |
FILEURL=$(j "$TRACK" '.audiodownload') | |
LICENSEURL=$(j "$TRACK" '.license_ccurl') | |
echo "Downloading \"$NAME\"..." | |
curl --http1.1 --progress-bar -o "$FILENAME" "$FILEURL" # FIXME: workaround for Jamendo HTTP/2 support | |
echo -ne "\r\033[1A\033[0K\r" | |
metaflac --remove-all-tags \ | |
--set-tag="ARTIST=$ARTIST" \ | |
--set-tag="TITLE=$NAME" \ | |
--set-tag="ALBUM=$ALBUM" \ | |
--set-tag="LICENSE=$LICENSEURL" \ | |
--set-tag="COPYRIGHT=$LICENSEURL" \ | |
--set-tag="TRACKNUMBER=$POS" \ | |
--set-tag="TRACKTOTAL=$PADLENGTH" \ | |
--set-tag="DATE=$RELEASEDATE" \ | |
--set-tag="DISCNUMBER=1" \ | |
--set-tag="CONTACT=$1" \ | |
--import-picture-from="folder.jpg" \ | |
"$FILENAME" | |
done |
@vitrif thanks! It has been a while since I used this script. I added your fix. Glad to see it being useful 🎈
It certainly is, thanks for the fast 'merge' 👍 I'm gonna enjoy some high-quality EDM now 😅
Viele Grüße aus Bremen
I was getting the following error: parse error: Invalid numeric literal at line 1, column 6
Replacing the API URL to the HTTPS one (https://api.jamendo.com/v3.0
) fixed it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @niclashoyer , thanks for the nice script!
I encountered an error with curl ('curl: (92) HTTP/2 stream 0 was not closed cleanly: Unknown error code (err 1)').
I think it is a problem with the HTTP/2 support of jamendo's servers, this workaround fixed it for me:
curl --http1.1 --progress-bar -o "$FILENAME" "$FILEURL"
Best Regards