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

Your rating: None Average: 4 (1 vote)

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <img> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.