2025-06-23 22:23:52 +02:00
#!/usr/bin/bash
# This script helped me download back my own albums from deab.bandcamp.com
2025-06-24 06:25:25 +02:00
#
# It takes the first positional argument : a folder with youtube-dl downloaded audio-only tracks from bandcamp with their associated pictures and json metadata
2025-06-23 22:23:52 +02:00
# And it parses the json to extract track name and number, album name, cover and number of tracks, and uses eyeD3 to updates the ID3 tags, rename and move the files
files = " $1 *.mp3 "
for f in $files ;
do
2025-06-24 06:25:25 +02:00
# collects metadata from json file
2025-06-23 22:23:52 +02:00
track = $( jq ".track" " ${ f %.* } .info.json " | tr -d '"' ) ;
track_number = $( jq ".track_number" " ${ f %.* } .info.json " | tr -d '"' ) ;
n_entries = $( jq ".n_entries" " ${ f %.* } .info.json " | tr -d '"' ) ;
artist = $( jq ".artist" " ${ f %.* } .info.json " | tr -d '"' ) ;
album = $( jq ".album" " ${ f %.* } .info.json " | tr -d '"' ) ;
2025-06-24 06:25:25 +02:00
year = $( jq ".release_year" " ${ f %.* } .info.json " | tr -d '"' ) ;
2025-06-23 22:23:52 +02:00
cover = " ${ f %.* } .jpg " ;
2025-06-24 06:25:25 +02:00
# updates the ID3 tags on the mp3 file
eyeD3 --title " $track " \
--track " $track_number " \
--track-total " $n_entries " \
--artist " $artist " \
--album " $album " \
--release-year " $year " \
--add-image " $cover " :FRONT_COVER: \
" $f "
# moves the files to a correct name into an artist/album/ folder
2025-06-24 06:34:02 +02:00
new_name = $( printf '%02d - %s.mp3' " $track_number " " $track " )
2025-06-23 22:23:52 +02:00
mkdir -p " $artist "
mkdir -p " $artist / $album "
2025-06-24 06:35:37 +02:00
mv " $f " " $artist / $album / $new_name "
2025-06-23 22:23:52 +02:00
done
2025-06-24 06:47:23 +02:00
# removes the original folder asking confirmation
rm -R " $1 "