Created
September 10, 2024 23:04
-
-
Save muaddib1971/6e984c49a5bde74c7ee36308616bbbd8 to your computer and use it in GitHub Desktop.
shell script to unpack a bandcamp zip file into the appropriate folder structure
This file contains hidden or 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 | |
#extracts a bandcamp zip file into the appropriate band / album directories | |
#paths to executables - modify these according to their location on your system | |
CUT=/usr/bin/cut | |
SED=/usr/bin/sed | |
BASENAME=/usr/bin/basename | |
MKDIR=/usr/bin/mkdir | |
UNZIP=/usr/bin/unzip | |
RM=/usr/bin/rm | |
for file in *.zip ; do | |
#extract band and album names | |
BAND=$(echo "$file" | $CUT -d- -f1 | $SED s/\ $//) | |
ALBUM=$($BASENAME "$file" .zip|$CUT -d- -f2|$SED s/^\ //) | |
echo $BAND/$ALBUM | |
#create directory to store the music files | |
$MKDIR -p "$BAND/$ALBUM" | |
#unzip the file into the appropriate location | |
$UNZIP -o -d "$BAND/$ALBUM" "$file" | |
#check that the unzipping failed and if it did exit the script with failure | |
if [[ $? -ne 0 ]] ; then | |
exit 1 | |
fi; | |
#unzipping succeeded so we can safely delete the zip file | |
$RM "$file" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment