Skip to content

Instantly share code, notes, and snippets.

@deseven deseven/tomp3
Created Oct 19, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.