Playlist generator in Bash
This bash script generates an *.m3u file in every directory it finds that hasn't got one yet.
#!/bin/bash
# Generates .m3u for many Audio Formats
#
# Put this file in your top mp3 directory and run it.
# It generates an *.m3u file in every mp3 directory.
#
IFS=$'\n'
m3u_exists=0
m3u_not_exists=0
#
#
indexCurrDir ()
{
FileList="" # initialize empty variable FileList
for FileTypes in "ogg" "mp3" "flac" "wav" "m4a" "wma" "wv" "swa" "aac" "ac3"
#
do
FindFiles=$(find $(pwd) -type f -iname "*.$FileTypes" -printf %f'\n' | sort)
FileList=$FileList$FindFiles
#
done
#
if [ "${#FileList}" != "0" ] ; then
CurrDir=$(pwd)
echo "$CurrDir"
echo "No m3u found, Generating one..."
m3uName=$(basename $CurrDir)
#
echo "Writing m3u playlist."
echo "$FileList" > "${m3uName}.m3u"
#
fi
}
AllDirs=$(find $(pwd) -mindepth 1 -type d | sort)
for Directory in $AllDirs
do
cd "$Directory"
FindList=$(find -type f -iname "*.m3u" -printf %f'\n')
if [ "${#FindList}" = "0" ] ; then
let m3u_not_exists=m3u_not_exists+1
indexCurrDir
else
echo "$Directory"
echo "*.m3u file found. Skipping directory."
let m3u_exists=m3u_exists+1
fi
echo "..."
done
echo "$m3u_exists m3u files found."
echo "$m3u_not_exists m3u files generated."
exit 0



Comments
Post new comment