Using Linux BASH environment I needed to find a way to create m3u playlists.
I first trawled the Internet looking a program to automate this for me — none!
So I then decided to find the m3u file syntax to create my own by hand — none!
Reverse engineering an existing m3u (and speaking with an Apple creative genius) I found that m3u files are simply text files which point to mp3 files.
Simple I thought — just use a loop to write file names to an m3u file.
Therefore, current working directory ($CWD) /your/music, within $CWD we have many directories, listed by artist name i.e. /your/music/abba.
Furthermore, within artist directories we have albums i.e. /your/music/abba/album1; /your/music/abba/album2.
This procedure requires entering each album artist i.e. cd /your/music/abba == present working directory.
Now for the script:
for x in */*.mp3; do echo "$x" >> "${PWD##*/}.m3u"; done
Result
We have a file with the name of the artist i.e. abba.m3u which contains a list of all mp3’s within the albums !!
Voila – Amend as necessary
**UPDATED**
I created a new script file below that allows you to pass directories into – not 100% for everyone but its a good start.
1 – Copy the code into the script m3uplaylist.sh
#!/bin/bash
m3u="${1##*/}.m3u"
echo "m3u= $m3u"
for x in “$1″/*/*.mp3; do echo “$x” >> “/your/music/M3u/$m3u”; done
2 – add execute permissions chmod +x m3uplaylist.sh
3 – run sh m3uplaylist.sh /your/music
!! do not add trailing ‘/’ !!
4 – [optional] run a for loop to recurse your main music folder for M in /your/music/*; do /bin/sh m3u-playlist.sh $M; done
Done I hope – let me know if you have trouble or can suggest improvements please
Enjoy !
** latest **
finished perfecting the script after many attempts and here is the final code
for i in /your/music/*; do find "$i" -maxdepth 3 -iname "*.mp3" > "$i/${i##'/your/music/'}.m3u";done