Convert Itunes Playlist to Volumio playlist

I made an xslt to convert the Itunes Playlist to Volumio playlist.
Steps:

  1. Export any ITunes playlist in xml format
  2. Modify the xsl with your data: replace the two variables source1 and target1 with he information of your source and target location
  3. Apply xsl (I’m using Notepad++ with XML Tools)
  4. Save and copy (I’m using WinSCP) to /data/playlist
  5. Enjoy!

Let me know if it works for you.

<?xml version="1.0"?>

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
	<xsl:output method="text"/>

	<xsl:template match="/">
		<xsl:text>[
</xsl:text>
		<xsl:apply-templates select="/plist/dict/array[preceding-sibling::key[1]='Playlists']/dict/array[preceding-sibling::key[1]='Playlist Items']/dict"/>
		<xsl:text>]
</xsl:text>
	</xsl:template>

	<xsl:template name="string-replace-all">
	   <xsl:param name="text"/>
	   <xsl:param name="replace"/>
	   <xsl:param name="by"/>
	   <xsl:choose>
		 <xsl:when test="contains($text,$replace)">
		   <xsl:value-of select="substring-before($text,$replace)"/>
		   <xsl:value-of select="$by"/>
		   <xsl:call-template name="string-replace-all">
			 <xsl:with-param name="text" select="substring-after($text,$replace)"/>
			 <xsl:with-param name="replace" select="$replace"/>
			 <xsl:with-param name="by" select="$by"/>
		   </xsl:call-template>
		 </xsl:when>
		 <xsl:otherwise>
		   <xsl:value-of select="$text"/>
		 </xsl:otherwise>
	   </xsl:choose>
	</xsl:template>
		
	<xsl:template match="/plist/dict/array/dict/array/dict">
		<xsl:variable name="key" as="xs:string">
			<xsl:value-of select="integer"/>
		</xsl:variable>
		<xsl:variable name="source1" select="'file://localhost/Z:/'"/>
		<xsl:variable name="target1" select="'NAS/music/'"/>
		<xsl:variable name="location" select="/plist/dict/dict/dict[preceding-sibling::key=$key][1]/string[preceding-sibling::key='Location'][1]" disable-output-escaping="yes"/>
		<xsl:variable name="artist" select="/plist/dict/dict/dict[preceding-sibling::key=$key][1]/string[preceding-sibling::key='Artist'][1]"/>
		<xsl:variable name="album" select="/plist/dict/dict/dict[preceding-sibling::key=$key][1]/string[preceding-sibling::key='Album'][1]"/>
		<xsl:variable name="title" select="/plist/dict/dict/dict[preceding-sibling::key=$key][1]/string[preceding-sibling::key='Name'][1]"/>
		<xsl:variable name="uritemp">
			<xsl:call-template name="string-replace-all">
				<xsl:with-param name="text" select="$location"/>
				<xsl:with-param name="replace" select="$source1"/>
				<xsl:with-param name="by" select="$target1"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="uri">
			<xsl:call-template name="string-replace-all">
				<xsl:with-param name="text" select="$uritemp"/>
				<xsl:with-param name="replace" select="'%20'"/>
				<xsl:with-param name="by" select="' '"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:text>  {</xsl:text>
		<xsl:text>
    "service": "mpd",</xsl:text>
		<xsl:text>	
    "uri": "</xsl:text>
	<xsl:value-of select="$uri" disable-output-escaping="yes"/>
	<xsl:text>",</xsl:text>
	
		<xsl:text>
    "title": "</xsl:text>
	<xsl:value-of select="$title"/>
	<xsl:text>",</xsl:text>
	
		<xsl:text>
    "artist": "</xsl:text>
	<xsl:value-of select="$artist"/>
	<xsl:text>",</xsl:text>
	
		<xsl:text>
    "album": "</xsl:text>
	<xsl:value-of select="$album"/>
	<xsl:text>",</xsl:text>
		<xsl:text>
    "albumart": "</xsl:text>
	<xsl:text>/albumart?web=</xsl:text>
	<xsl:value-of select= "$artist" /><xsl:text>/</xsl:text><xsl:value-of select= "$album" />
	<!--<xsl:text>'/extralarge&amp;path=%2Fmnt%2F</xsl:text>
	<xsl:call-template name="string-replace-all">
	<xsl:with-param name="text" select="$location"/>
	<xsl:with-param name="replace" select="$source1"/>
	<xsl:with-param name="by" select="$target1"/>
	</xsl:call-template>-->
	<xsl:text>"</xsl:text>	
		<xsl:text>
  }</xsl:text>
	<xsl:choose>
         <xsl:when test="position() != last()">,
</xsl:when>
         <xsl:otherwise>
</xsl:otherwise>
       </xsl:choose>
	</xsl:template>


<xsl:template match="text">
  <body>
    <xsl:value-of select="." disable-output-escaping="yes" />
  </body>
</xsl:template>
</xsl:transform>

I’m sure this will be useful to people; It would be nice if you could write a simple plugin :wink: to do this.

I do not have the latest version running (running on cubox, not in raspberry) as soon as I have a rpi to test the plugins I’ll give a try.

I’m excited to try this, but I’m a novice with xml / xsl, and pretty limited in my grasp of what is exactly going on.

I am using jEdit with an XSLT plugin on a Mac to try the operation. I exported my itunes playlist as xml, and I have been trying to get it to work, but my first tries get an error (screen shot attached) about syntax.

I’m also not exactly sure what the appropriate paths are that I should use in the ‘source1’ and ‘target1’ variables.

I’d be happy for any help or resources you could suggest,

Thanks
Screen Shot 2017-10-10 at 10.47.13 AM.png

Thanx for this response

Thank you for this XSLT, it is very helpful. Is there a way to batch process multiple iTunes XML playlists with this XSLT? I would like to be able to input a bunch of playlists and have it spit them out in the updated Volumio format with the same name. Thanks for any help.