Last active
March 29, 2019 13:49
-
-
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
This file contains 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 | |
# 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