Skip to content

Instantly share code, notes, and snippets.

@Dubhead
Created March 4, 2016 23:16
Show Gist options
  • Save Dubhead/551c049b3351e3faca6f to your computer and use it in GitHub Desktop.
Save Dubhead/551c049b3351e3faca6f to your computer and use it in GitHub Desktop.
#!/bin/sh
#!/bin/zsh -x
# flac_renamer.sh - Renames FLAC files by tracknumbers.
#
# usage:
# $ ./flac_renamer.sh *.flac
# : e.g. MyArtist-MyTitle.flac is renamed to 01.flac
FLAC_FILES="$@"
for f in $FLAC_FILES; do
TRACKNUMBER=$(metaflac --show-tag=TRACKNUMBER $f | \
sed -e 's/^TRACKNUMBER=//')
ZERO_PADDED_TN=$(echo -n "00${TRACKNUMBER}" | \
grep --only-matching '..$')
if [ $f = ${ZERO_PADDED_TN}.flac ]; then
echo "skipping $f"
continue
fi
mv -i $f ${ZERO_PADDED_TN}.flac
done
# eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment