Script to convert recursively m4a files to mp3
find . -type f -name '*.m4a' -exec sh -c '
name="${1%.*}"
if [ -f "${name}.mp3" ]; then
echo "${name}.mp3 already exists, skipping..."
else
echo " converting $name"
~/ffmpeg -i "$1" -c:a mp3 -b:a 192k "${name}.mp3"
fi
' find-sh {} ;
Delete m4a files already converted to mp3
find . -type f -name '*.mp3' -exec sh -c '
name="${1%.*}"
if [ -f "${name}.m4a" ]; then
echo "${name}.mp3 already exists, deleting m4a..."
rm -f "${name}.m4a"
fi
' find-sh {} ;
move files in subdirectories to a single (flat) directory
find "." -name "*.mp3" -exec mv -t /volume1/DATA/MEDIA/MUSIC/FLAT/ {} +
create artist/album struture and move mp3 files
#!/bin/sh
find "." -name "*.mp3" -print | sed -r 's/^.+\///' >files.txt
while read p; do
artist=$(echo "$p"| awk 'BEGIN {FS = " - "} ;{print $1}')
album=$(echo "$p"| awk 'BEGIN {FS = " - "} ;{print $2}')
if [ -z "$album" ]
then
album="unknown album"
fi
if [ -z "$artist" ]
then
album="unknown artist"
fi
echo "$artist:$album"
mkdir --parents ../RESTRUCTURED/"$artist"/"$album"/
mkdir -p ../RESTRUCTURED/"$artist"/"$album"/
mv "$p" ../RESTRUCTURED/"$artist"/"$album"/
done <files.txt