Several days ago, a cousin asked me for a playlist. I thought of several forms for me to share it with her, until I found XSPF (http://xspf.org/), a perfect solution for my requirements, with a ton of available applications. However, there was a problem, my whole Music Collection is in iTunes.

Gladly, I made the playlist, without taking into account the lack of converters available. After I finished it, it hit me; so I dedicated a few hours into making iTunesXSPF, an XSLT converter between iTunes’ XML playlist format to XSPF.

To use it, just export your playlist to XML on iTunes, then download (and unzip) the file on the same folder, and modify the first lines to:

 <?xml version="1.0" encoding="UTF-8"?>
 <?xml-stylesheet type="text/xsl" href="itunes.xsl"?>
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

Also you can use xsltproc if you have it available:

xsltproc playlist.xml itunes.xsl lista.xspf

Full code and Download:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?xml version="1.0"?>
<!-- iTunesXSPF, by Sebastian Oliva (tian@sebastianoliva.com) [http://sebastianoliva.com]
Copyright (C) 2009,2010 Sebastian Oliva
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.
 
You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
	<xsl:template match="/">
		<playlist xmlns="http://xspf.org/ns/0/" version="1">
		  <!-- Add your Own Info Here -->
			<title>Playlist</title>
			<creator>Me</creator>
			<info>http://example.com/</info>
			<!-- Editing Further is unsafe -->
			<trackList>
				<xsl:for-each select="plist/dict/array/dict/array/dict">
					<xsl:variable name="Traki"><xsl:apply-templates select="key[. = 'Track ID']" mode="content"/></xsl:variable>
					<xsl:for-each select="/plist/dict/dict/dict">
						<xsl:if test="key[. = 'Track ID']/following-sibling::*/text() = $Traki">
							<track>
								<title><xsl:apply-templates select="key[. = 'Name']" mode="content"/></title>
								<creator><xsl:apply-templates select="key[. = 'Artist']" mode="content"/></creator>
								<album><xsl:apply-templates select="key[. = 'Album']" mode="content"/></album>
								<location><xsl:apply-templates select="key[. = 'Location']" mode="content"/></location>
								<annotation><xsl:apply-templates select="key[. = 'Comments']" mode="content"/></annotation>
								<duration><xsl:apply-templates select="key[. = 'Total Time']" mode="content"/></duration>
							</track>
						</xsl:if>
					</xsl:for-each>
				</xsl:for-each>
			</trackList>
		</playlist>
	</xsl:template>
 
	<xsl:template match="key" mode="content">
		<xsl:value-of select="following-sibling::*/text()"/>
	</xsl:template>
	<xsl:template match="trim" mode="content">
		<xsl:value-of select="following-sibling::*/text()"/>
	</xsl:template>
</xsl:stylesheet>

Download: github.com/tian2992/iTunesXSPF

This post is also available in: Spanish