Skip to content

Instantly share code, notes, and snippets.

@wgmyers
Last active August 24, 2018 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgmyers/be64d22494c302f8a9675c5c4205a381 to your computer and use it in GitHub Desktop.
Save wgmyers/be64d22494c302f8a9675c5c4205a381 to your computer and use it in GitHub Desktop.
#!/bin/bash
# fix-beriah-flac.sh
# Bash shell script to fix tags in Book of Beriah flac zip
############
# WARNING! #
############
#
# USE OF THIS SCRIPT IS ENTIRELY AT YOUR OWN RISK!
# IT HAS BEEN TESTED ON PRECISELY ONE MACHINE ONLY.
# IT WORKS FOR ME. I HOPE IT WORKS FOR YOU. I DON'T KNOW.
# Instructions:
# Copy this script into the same directory as your humungous zip file of John Zorn goodness (HZFOJZG)
# Unzip the HZFOJZG
# Make the script executable and run it.
METAFLAC=metaflac
COVER_FILE=cover.jpg
# Enter the correct directory or abort if not found
cd 'The Book Beriah' || (echo "Can't find the 'Beriah' directory." && exit 1)
# Munge field separator so we can read directories with spaces in their names
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
ARTISTS=(
"Sofia Rei and J.C. Maillard"
"Cleric"
"Spike Orchestra"
"Julian Lage and Gyan Riley"
"Abraxas"
"Klezmerson"
"Gnostic Trio"
"Zion80"
"Banquet Of The Spirits"
"Secret Chiefs 3"
"Craig Taborn and Vadim Neselovskyi"
)
ALBUMS=(
"Book Beri’ah 1 Keter"
"Book Beri’ah 2 Chokhma"
"Book Beri’ah 3 Binah"
"Book Beri’ah 4 Chesed"
"Book Beri’ah 5 Gevurah"
"Book Beri’ah 6 Tiferet"
"Book Beri’ah 7 Netzach"
"Book Beri’ah 8 Hod"
"Book Beri’ah 9 Yesod"
"Book Beri’ah 10 Malkhut"
"Book Beri’ah 11 Da’at"
)
# Iterate over every directory
COUNT=0
for dir in */; do
cd $dir
echo `pwd`
echo "Extracting cover image"
# Extract cover image from first file in directory
FIRST=01*
$METAFLAC --export-picture-to=$COVER_FILE $FIRST
# Fix ARTIST, ALBUMARTIST and ALBUM tags
echo "Fixing artist and album tags"
ARTIST=${ARTISTS[$COUNT]}
ALBUM=${ALBUMS[$COUNT]}
$METAFLAC --remove-tag="ARTIST" *.flac
$METAFLAC --set-tag="ARTIST=$ARTIST" *.flac
$METAFLAC --remove-tag="ALBUMARTIST" *.flac
$METAFLAC --set-tag="ALBUMARTIST=$ARTIST" *.flac
$METAFLAC --remove-tag="ALBUM" *.flac
$METAFLAC --set-tag="ALBUM=$ALBUM" *.flac
cd ..
COUNT=$((COUNT + 1))
done
# Restore field separator
IFS=$SAVEIFS
echo "All done."
@wgmyers
Copy link
Author

wgmyers commented Aug 24, 2018

Revision #1:

  • Instead of allowing you to run the script anywhere and potentially batch retag a bunch of stuff wrongly, script now requires you to run it from the parent directory of Beriah and only goes ahead if it has successfully cd'ed into a directory with a sensible sounding name.

Revision #2:

  • 'Field' separator, not 'file' separator. Fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment