doom'd net

still mucking around with the ol'computer


Creating m3u Playlist Files for the MZD Connect Systems in My Mazda 3

One of the cool things about the 3rd Gen Mazda 3’s is the Connect infotainment system.  One of it’s capabilities is to play MP3 files off of a thumb drive inserted into one of it’s USB ports.

So, I took an empty thumb drive I had sitting around, and loaded up a bunch of MP3 files on it. And sure enough, it can play the songs.  It will let you select by song, album, artist, etc.  And for the most part, as long as your ID3 tags are in order, it works pretty good. But, it has a problem with properly ordering the songs in an album for some reason.  

Here is the list from Black Sabbath’s Live Evil when selected in the album list:

mixed up live evil

As you can see, it’s rather annoyingly out of order.  I’ll come back this in a bit.

But first, what if you wanted to make custom song lists?  Well, it turns out to be rather easy.  This system will recognize m3u files and list them under the playlist option.  m3u files are literally a list of files with relative paths.

NOTE: I’m assuming you are working on a modern Linux system that has the eyeD3 program installed.

NOTE: I’m assuming you have at least a basic understanding of Bash Shell scripting.

Lets say that the thumb drive is plugged into your computer, is your $PWD, and has music files organized as <artist>/<album>/<song>.mp3

Some entries in an m3u file might then look like:

Black Sabbath/Live Evil/01 - E5150.mp3
Black Sabbath/Live Evil/02 - Neon Knights.mp3
Black Sabbath/Live Evil/03 - N.I.B..mp3
Black Sabbath/Live Evil/04 - Children Of The Sea.mp3

And so forth.

You could easily make a play list of what ever songs you wanted by hand using your favorite text editor, but working on a Linux system, that’s just not very fun.

But, if you wanted make an m3u file of every mp3 file under $PWD, it would be a simple mater with the find program:

#.find \* -name '*.mp3' -print \| sort > everything.m3u

If you wanted to make an m3u file for each of the bands on your list, you could do something like:

for i in \*
do 
   echo processing $i ...
   cd "$i" 
   find \* -name '*.mp3' -print \| sort > "$i".m3u
   cd ..
done

This would create a <band_name>.m3u file in each directory of the band ( at the same level as the albums ).

Now, remember when I said for some reason the individual songs of each album was out of order when you selected artist->album?

This can help with that too!  By extending the album loop, using a tool like eyeD3 to read the ID3 tags to get the track information.  Being clever, you can even properly handle albums with multiple CD’s:

for band in \*
do
  cd "$band"

  for album in \*
  do
    unset list
    declare -a list

    cd "$album"
    echo processing $band - $album ...

    for song in \*.mp3
    do
      track=$( eyeD3 --no-color "$song" 2>/dev/null \| grep -oP '^track: Kd+' )
      disc=$( eyeD3 --no-color "$song" 2>/dev/null \| grep -oP '^disc: Kd+' )
      if [ -z $disc ]; then disc=1 ; fi # no disc information

      index=$(( disc*100 + track )) # handle more multi-disc albums
      list[$index]="$song"
    done

    for i in $( echo ${!list[@]} \| sort -n )
    do
      echo "${list[$i]}" >> "$album".m3u
    done

    cd .. # back to album list

  done
  cd .. # back to band list
done

And now, when selecting the Live Evil the play list menu ...

live evil all in order

The songs are in the correct order, just as they should be!

Some sample scripts, which are more complete, and better commented, then the examples presented here, as well as other ones, can be found in the Github Repository:

https://github.com/lorddoomicus/mazda-m3u