Simple M3U exporter help needed - 1 track per .m3u


I am trying to write a relatively simple .m3u exporter but I'm having trouble grasping the export syntax.

I am attempting to:

-load a folder of mp3s (and subfolders) into mp3tag (i got that part :wink: )
-export an .m3u file for each file into the same folder as the track itself. Each m3u file will contain only one item.

The URL in the M3U will be a combined path of a URL prefix+subfolder+filename.ext

For example, suppose I edit the .mte and specify that my URL prefix is:

and mp3tag is showing the contents and subfolders of:

C:\Documents and Settings\User\Desktop<!--coloro:#CC6600-->samples

and I use my M3U exporter on the files:

C:\Documents and Settings\User\Desktop<!--coloro:#CC6600-->samples\album_one\01-The_Good_Song.mp3
C:\Documents and Settings\User\Desktop<!--coloro:#CC6600-->samples\album_one\02-The_Bad_Song.mp3

then these m3u files should be the result:

#EXTINF:0,%artist% - %track%

#EXTINF:0,%artist% - %track%

A simple naming for the .m3u files is fine such as %_filename%.m3u, I don't mind the double extension that will result.

The reason for this exporter is I want to link some audio samples in mp3 format to .m3u files rather than directly link to the mp3s. In some browser configurations, when users click the mp3 it just downloads in the background without letting the user know the progress and they seem to give up after a while. This will ensure it opens outside the browser.

If there is anything that I could do to make the code simpler, such as ensuring that the subfolders and filenames could be accurately generated using the tags I would be happy to do so.

Thanks for any help you can provide. My .mte files seem to either create only a single .m3u or crash mp3tag.


Mp3tag can only make one file per directory, but not one file per audio file.


Thanks for the quick reply. Any idea how to achieve this? I thought I could just use the mail merge function of MS Word + a CSV file but it doesn't allow you to export the results as files, you must print them or email them. Otherwise it would work great.


One way to achieve this is with something like python.
Download and install a python interpreter (just go to
Copy/paste the code I've appended below into a python file, call it, say "". Change the string that's currently '\BLAH\BLAH\BLAH' to the url you need.
Use Mp3Tag to create mp3tag.m3u (default Mp3Tag name for a m3u file).
on the command line, type m3u mp3tag.m3u - then press [enter].
Have fun!

PS: you could have done exactly the same thing with a sed script, but sed's a PITA ...

import sys
import re
import os

rM3uTuneInfo = re.compile(r"""
  """, re.VERBOSE)
rFilename = re.compile(r"""
  """, re.VERBOSE)
sPrefix = 'BLAH\BLAH\BLAH\'

def main():

  if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
    fn = os.path.abspath(sys.argv[1])
    s = os.path.split(fn)
    sPath = s[0]
    fIn=PrivoxyWindowOpen(fn, 'r')
    sBuf =
    for m in rM3uTuneInfo.finditer(sBuf):
      title =
      length =
      filename =
      f = rFilename.match(
      if f:
        name = # filenanme
        ext = # extension
        fOut = PrivoxyWindowOpen(sPath +'\\\\' + name, 'w')
        sTmp = '#EXTINF:' + length + ',' + title + '\n'
        sTmp = sPrefix + filename + '\n'

if __name__ == "__main__":