Skip to content

Instantly share code, notes, and snippets.

@shaunhey
Last active March 29, 2019 13:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunhey/7500f6a11818950df2bf to your computer and use it in GitHub Desktop.
Save shaunhey/7500f6a11818950df2bf to your computer and use it in GitHub Desktop.
Quick script to scan FLAC files and convert those to MP3 that don't exist
#!/bin/bash
# Quick script to scan FLAC files and convert those to MP3 that don't exist
queuefile="/tmp/flac2mp3queue.txt"
echo "****************************************************************"
echo "Begin process at `date`"
if [ -f "$queuefile" ]
then
rm "$queuefile"
fi
find "/mnt/music/FLAC/" -type f -name "*.flac" -print0 | while read -d $'\0' flacfile; do
mp3file="${flacfile[@]/%flac/mp3}"
mp3file="${mp3file/FLAC/MP3}"
mp3dir="$(dirname "$mp3file")"
if [ ! -d "$mp3dir" ]
then
echo "Creating directory $mp3dir"
mkdir -p "$mp3dir"
fi
if [ ! -f "$mp3file" ]
then
echo "ffmpeg -i \"$flacfile\" -ab 320k \"$mp3file\"" >> "$queuefile"
fi
done
if [ -f "$queuefile" ]
then
echo "Begin encoding `wc -l < $queuefile` files..."
parallel :::: "$queuefile"
rm "$queuefile"
else
echo "No files to convert..."
fi
echo "End process at `date`"
echo "****************************************************************"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment