Skip to content

Instantly share code, notes, and snippets.

@deseven
Created October 19, 2017 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deseven/96f9ca820c04afcfafe49050f017fc41 to your computer and use it in GitHub Desktop.
Save deseven/96f9ca820c04afcfafe49050f017fc41 to your computer and use it in GitHub Desktop.
Simple script to convert all audio files in current directory to mp3
#!/bin/bash
BLUE='\033[1;34m'
NC='\033[0m'
total=0
current=0
ext=""
read -p "Please enter the extension to convert from [flac]: " ext
if [ -z "$ext" ]; then ext=flac; fi
for file in *.${ext}; do
if [ "$file" != "*.$ext" ]; then
total=$((total+1))
echo -e "$BLUE$file$NC"
fi
done
if [ "$total" == "0" ]; then echo -e "Not found any files with extension $BLUE$ext$NC in current directory, exiting..." && exit 1; fi
read -p "Found $total files to convert, is this ok? (y/n): " -n 1 confirm
echo
if [ "$confirm" == "y" ]; then
for file in *.${ext}; do
current=$((current+1))
echo -ne "${BLUE}converting file ($current/$total)...$NC"
ffmpeg -i "$file" -ab 320k -map_metadata 0 -id3v2_version 3 "${file%.$ext}.mp3" 2>/dev/null || { echo -e "\nError! The command was:\n$BLUEffmpeg -i \"$file\" -ab 320k -map_metadata 0 -id3v2_version 3 \""${file%.$ext}.mp3"\"$NC"; exit 2; }
echo
done
read -p "All done! Delete original files? (y/n): " -n 1 delete
echo
if [ "$delete" == "y" ]; then
rm -f *.${ext}
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment