Created
April 11, 2018 11:55
-
-
Save philroche/a6b9140d63a11a446d741da8a1c34e92 to your computer and use it in GitHub Desktop.
Recursive convert m4a files to mp3
This file contains hidden or 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 | |
# | |
# | |
#set -ux | |
set +e | |
if [ -z "$1" ] ; then | |
TRANSCODEDIR="." | |
else | |
TRANSCODEDIR="$1" | |
fi | |
abs_basefolder=`realpath "$TRANSCODEDIR"` | |
folder_base=`dirname "$abs_basefolder"` | |
folder_name=`basename "$abs_basefolder"` | |
function recursive_convert { | |
find "$1" -type d -print0 | | |
while IFS= read -rd '' directory_to_convert; do | |
echo "Converting files in $directory_to_convert"; | |
output_directory=$directory_to_convert | |
echo "Converted files will be saved in $output_directory"; | |
# TODO only find video files | |
# *.mkv *.webm *.flv *.avi *.mov *.wmv *.mp4 *.mp4$ *.m4v *.flv | |
find "$directory_to_convert" -maxdepth 1 -mindepth 1 -type f -print0 | | |
while IFS= read -r -d '' file_to_convert; do | |
file_to_convert_filename=$(basename "$file_to_convert") | |
if [[ ${file_to_convert_filename: -4} == ".m4a" ]]; then | |
converted_filepath="$output_directory/${file_to_convert_filename%.*}.mp3" | |
# If the file doesn't exist then convert | |
if [ ! -e "$converted_filepath" ]; then | |
echo "Converting $file_to_convert" | |
avconv -i "$file_to_convert" "$converted_filepath" </dev/null | |
rm "$file_to_convert" | |
else | |
echo "$converted_filepath already exists" | |
fi | |
fi | |
done | |
done | |
} | |
recursive_convert "$abs_basefolder" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment