Converting wpl playlists to m3u playlists

Simple XML in, simple text out, but no good search results for wpl2m3u? Write a little XSLT.

After taking a closer look at the WPL format I realized that an XSLT stylesheet to convert it to M3U would be very simple.

I’ve switched around between music-playing programs over the last few years. I suppose I should call them “media players”, but I only use them to play music, which is part of the reason I ended up using Songbird, an open source Windows/Linux/Mac music front end that doesn’t pretend to be anything else. It looks a bit like iTunes, without all the ads in your face; how great is that?

Before that I used MediaMonkey, and before that, the Windows Media Player. Guess which of these uses the most standardized, XML-based format for playlists? Surprise: the Microsoft one.

Windows Media Player can create WPL files, which seem to conform to the W3C SMIL standard, and it can export M3U files, which MediaMonkey uses. To convert WPL files to m3u for Songbird, reading them individually into Windows Media Player and exporting them one at a time was annoying. I did some web searches for wpl2m3u and only found one script that I couldn’t quite follow, and after taking a closer look at the WPL format I realized that an XSLT stylesheet to convert it to M3U would be very simple. So here it is:

<xsl:stylesheet version="1.0" xmlns:xsl="">

  <xsl:strip-space elements="*"/>
  <xsl:output method="text"/>

  <xsl:template name="textAfterLastSlash"><!-- but actually backslash -->
    <xsl:param name="string">dummy string</xsl:param>
      <xsl:when test="not(contains($string,'\'))">
        <xsl:value-of select="$string"/>
        <xsl:call-template name="textAfterLastSlash">
          <xsl:with-param name="string" select="substring-after($string,'\')"/>

  <xsl:template match="smil">

  <xsl:template match="media">
    <xsl:call-template name="textAfterLastSlash">
      <xsl:with-param name="string" select="@src"/>
    <xsl:value-of select="@src"/>

  <xsl:template match="title"/>


It’s not very long, but if you want fancy XSLT, I have a recursive named template, which I wrote for something else but modified here to look for the text after the last backslash. The &#10; is a trick I’ve used more lately to get XSLT to output a carriage return, because if I put an actual carriage return inside of an xsl:text element like I always did before, telling Emacs to re-indent the whole thing tends to screw that up.

With a long plane ride tomorrow night to go to Oxford for the XML Summer School, I want to load up the MP3 player with something conducive to sleeping, so I just converted my playlist of Lata Mangeshkar ballads so that I can put that on. (If you like classic Bollywood soundtracks, check out Music from the Third Floor; if you’re new to it and interested, start with the compilations there.)


By V1AN1 on May 13, 2011 7:08 PM

This was very helpful!

Here are some instructions to use this sucker:

Download the Saxon HE XSLT converter:

Now create a folder called wpltom3u (or of your choosing) and go into that folder.
Create two additional folders, one titled wpl and another titled m3u.
Now, put the .jar of Saxon XSLT into the default (wpltom3u) folder. MAKE SURE YOU HAVE JAVA INSTALLED!
Now create a text file in the default (wpltom3u) directory and rename it to style.xsl, then edit it with notepad and paste in the XSLT code posted above.
Create another file and rename it to convert.bat.
Now edit convert.bat and put in this following code:

for %%a in (wpl/*.wpl) do java -jar saxon9he.jar “wpl/%%a” “style.xsl” >“m3u/%%~na.m3u”

Save it and exit. Now put all your .wpl playlist files into the wpl folder, and hit Convert! PRESTO! You now have all your wpl playlists converted to m3u. :D

It will take a while to convert it automatically and to rename them correctly but you wont have to do anything but double click and wait. :)

Hope this helps people..

Ah, and a side note:
some playlists fail to convert due to their names. If they do, write down their names and then rename them and put them back into the wpl folder. Don’t reconvert all your playlists again, this code isn’t that smart. Just single out those playlists that didn’t convert and leave them in the wpl folder, then rename them to have no symbols in them, and convert!