Windows Media Player-Abspiellisten mit XSLT ins Winamp-Format konvertieren

Solange sich die Musiksammlung sortiert auf dem PC befindet, ist alles in Ordnung. Die beste Struktur aus dem Media Player bricht aber schnell zusammen, wenn man versucht, eine hierarchische Dateiorganisation auf den MP3-Player zu kopieren, wenn der eine Winamp-Abspielliste erwartet.

So mancher besitzt Alben oder CD-Boxen mit mehreren Scheiben, etwa von Led Zeppelin, Creedence Clearwater Revival, Jethro Tull, The Grateful Dead, Pink Floyd, The Moody Blues oder Emerson, Lake & Palmer et cetera in seinem CD-Regal. Wer einen Computer hat, kann mit dem Windows Media Player diese CDs rippen und dann Abspiellisten für die gesamte CD-Box erstellen. Das alles wird dann sehr ordentlich in Verzeichnissen organisiert. Jede Gruppe hat ihr eigenes Verzeichnis, und alle dazu gehörenden CDs befinden sich in einem eigenen Unterordner.

Allerdings bricht diese Struktur schnell zusammen, wenn man versucht, diese hierarchische Dateiorganisation auf seinen MP3-Player zu kopieren. Die Verzeichnisse und Dateien lassen sich problemlos per Drag & Drop auf den MP3-Player kopieren, doch weiß dieser nicht, was er mit einer Windows Media Player-Abspielliste anfangen soll, weil er eine Winamp-Abspielliste erwartet.

Es gibt drei Möglichkeiten, um dieses Problem zu lösen:

  • Winamp herunterladen und einen großen Teil einer Woche damit verbringen, die Abspiellisten neu zu erstellen.
  • Aufgeben und damit leben, dass jede CD von den dazugehörigen anderen CDs getrennt ist.
  • Da in diesem Fall die meiste Musik aus den 60er und 70er Jahren stammt, eine zu dieser Ära passende Lösung verwenden, die den Benutzervorlieben entspricht.

Die erste Lösung kommt für viele nicht in Frage, denn sie ist zu aufwendig. Die zweite Lösung kommt auch nicht unbedingt Frage, außer man will nun wirklich jeglichen Aufwand vermeiden. Die dritte Lösung ist dagegen perfekt für all jene geeignet, die in ihrem Innersten Rebellen sind.

Der Beginn der Rebellion

Die Rebellion kann damit beginnen, dass man die .wpl-Datei (Windows Playlist) etwa für die Led Zeppelin-Box mit Notepad öffnet und schockiert von dem ist, was man dort erblickt (Liste A).

Liste A

Contents of Led Zeppelin – Box Set.wpl

<?wpl version=”1.0″?>
<smil>
<head>
<meta name=”Generator” content=”Microsoft Windows Media Player — 11.0.5721.5268″/>
<meta name=”AverageRating” content=”5″/>
<meta name=”TotalDuration” content=”17416″/>
<meta name=”ItemCount” content=”54″/>
<meta name=”ContentPartnerListID”/>
<meta name=”ContentPartnerNameType”/>
<meta name=”ContentPartnerName”/>
<meta name=”Subtitle”/>
<author/>
<title>Led Zeppelin – Box Set</title>
</head>
<body>
<seq>
<media src=”C:Documents and SettingswoychowskyMy DocumentsMy MusicLed ZeppelinLed Zeppelin [Box Set] Disc 11 Whole Lotta Love.mp3″ cid=”{B74906CA-72F9-4351-97BF-A6CE6747699D}” tid=”{301C14C6-055A-4A01-B473-BE13A64E01C2}”/>
<media src=”C:Documents and SettingswoychowskyMy DocumentsMy MusicLed ZeppelinLed Zeppelin [Box Set] Disc 12 Heartbreaker.mp3″ cid=”{A78808F0-F943-48C4-885F-14B5393F41AC}” tid=”{0AE5F094-3CC9-4CE6-99EB-EC2624D3BCCA}”/>
<media src=”C:Documents and SettingswoychowskyMy DocumentsMy MusicLed ZeppelinLed Zeppelin [Box Set] Disc 13 Communication Breakdown.mp3″ cid=”{B0DC58CF-48C5-448C-B61C-9CF1398E99BF}” tid=”{9937B18F-B0DE-4B30-99AE-B0218EE72052}”/>
<media src=”C:Documents and SettingswoychowskyMy DocumentsMy MusicLed ZeppelinLed Zeppelin [Box Set] Disc 14 Babe I&apos;m Gonna Leave You.mp3″ cid=”{36C5B60D-8122-4907-9BE6-C33F83B4A07E}” tid=”{E5DD7D8F-3BC6-4881-9FA7-6F72EF9DF4EC}”/>
<media src=”C:Documents and SettingswoychowskyMy DocumentsMy MusicLed ZeppelinLed Zeppelin [Box Set] Disc 15 What Is and What Should Never Be.mp3″ cid=”{8C5CA370-34E8-49FE-9275-16F813D0E3CA}” tid=”{16EC3078-B602-4D92-8DA8-699CAF639DFA}”/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 16 Thank You.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 17 I Can&apos;t Quit You Baby.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 18 Dazed and Confused.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 19 Your Time Is Gonna Come.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 110 Ramble On.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 111 Travelling Riverside Blues [#].mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 112 Friends.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 113 Celebration Day.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 114 Hey Hey What Can I Do.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 115 White Summer-Black Mountain Side [#].mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 21 Black Dog.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 22 Over the Hills and Far Away.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 23 Immigrant Song.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 24 The Battle of Evermore.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 25 Bron-Y-Aur Stomp.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 26 Tangerine.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 27 Going to California.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 28 Since I&apos;ve Been Loving You.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 29 D&apos;Yer Mak&apos;er.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 210 Gallows Pole.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 211 Custard Pie.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 212 Misty Mountain Hop.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 213 Rock and Roll.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 214 The Rain Song.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 215 Stairway to Heaven.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 31 Kashmir.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 32 Trampled Under Foot.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 33 For Your Life.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 34 No Quarter.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 35 Dancing Days.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 36 When the Levee Breaks.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 37 Achilles Last Stand.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 38 The Song Remains the Same.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 39 Ten Years Gone.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 310 In My Time of Dying.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 41 In the Evening.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 42 Candy Store Rock.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 43 The Ocean.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 44 Ozone Baby.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 45 Houses of the Holy.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 46 Wearing and Tearing.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 47 Poor Tom.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 48 Nobody&apos;s Fault But Mine.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 49 Fool in the Rain.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 410 In the Light.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 411 The Wanton Song.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 412 Moby Dick-Bonzo&apos;s Montreux.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 413 I&apos;m Gonna Crawl.mp3″/>
<media src=”..Led ZeppelinLed Zeppelin [Box Set] Disc 414 All My Love.mp3″/>
</seq>
</body>
</smil>

Das sieht überraschend ähnlich wie XML aus, denn der Windows Media Player verwendet den XML-Dialekt Synchronized Multimedia Integration Language (SMIL) zum Speichern von Abspiellisten.

Wenn man nun nicht alle Hoffnungen aufgeben will, schaut man etwa in Wikipedia nach, welches Format die Winamp-Abspiellisten (.m3u) haben. Da erfährt man, dass .m3u-Dateien reine Textdateien sind, mit #EXTM3U beginnen und entweder absolute oder relative Pfadnamen oder einen URI enthalten. Darüber hinaus gibt es auch #EXTINFO, womit die MP3-Datei näher beschrieben wird, doch sind die optional und sollen deshalb hier ignoriert werden.

Diesen Informationen zufolge und angenommen, die Abspielliste befände sich im CD-Ordner, würde die .m3u-Abspielliste für Jethro Tulls Aqualung aussehen wie in Liste B dargestellt.

Liste B

Jethro Tull’s Aqualung as a .m3u playlist

#EXTM3U
01 Aqualung.mp3
02 Cross-Eyed Mary.mp3
03 Cheap Day Return.mp3
04 Mother Goose.mp3
05 Wond’ring Aloud.mp3
06 Up to Me.mp3
07 My God.mp3
08 Hymn 43.mp3
09 Slipstream.mp3
10 Locomotive Breath.mp3
11 Wind Up.mp3

Bei Alben mit mehreren CDs würde die Abspielliste auf der Ebene der Gruppe gespeichert und daher würde das Verzeichnis der CD in der Pfadangabe erscheinen. Von der Ebene der Gruppe ausgehend, würde die Aqualung-Abspielliste daher aussehen wie Liste C.

Liste C

Jethro Tull’s Aqualung as a .m3u playlist

#EXTM3U
Aqualung1 Aqualung.mp3
Aqualung2 Cross-Eyed Mary.mp3
Aqualung3 Cheap Day Return.mp3
Aqualung4 Mother Goose.mp3
Aqualung5 Wond’ring Aloud.mp3
Aqualung6 Up to Me.mp3
Aqualung7 My God.mp3
Aqualung8 Hymn 43.mp3
Aqualung9 Slipstream.mp3
Aqualung10 Locomotive Breath.mp3
Aqualung11 Wind Up.mp3

Wenn man erst einmal weiß, wie die Eingabe und die Ausgabe aussehen, muss man nur noch den Code schreiben, der die Umwandlung vornehmen soll. Da das Eingabeformat XML ist, bietet es sich an, XSLT zu verwenden. Das mag etwas seltsam klingen, insbesondere da die Ausgabe eine Textdatei sein wird, aber es funktioniert. Dann erhält man XSL wie in Liste D.

Liste D

The .wpl to .m3u conversion XSLT

<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:output method=”text” encoding=”utf-8″/>
<xsl:template match=”/”>
<xsl:text>#EXTM3U</xsl:text>
<xsl:call-template name=”crlf”/>
<xsl:apply-templates select=”./descendant::media”/>
</xsl:template>
<xsl:template match=”media”>
<xsl:call-template name=”folder”>
<xsl:with-param name=”path” select=”./@src”/>
</xsl:call-template>
</xsl:template>
<!– Only output the disc folder and file name –>
<xsl:template name=”folder”>
<xsl:param name=”path”/>
<xsl:choose>
<xsl:when test=”contains(substring-after($path,’‘),’‘)”>
<xsl:call-template name=”folder”>
<xsl:with-param name=”path” select=”substring-after($path,’‘)”/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=”$path”/>
<xsl:call-template name=”crlf”/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!– Carriage Return/Line Feed –>
<xsl:template name=”crlf”>
<xsl:text>&#x0D;&#x0A;</xsl:text>
</xsl:template>
</xsl:stylesheet>

Der Code schreibt lediglich #EXTM3U gefolgt von Zeilenumschaltung/Zeilenvorschub und schreibt dann den Text für das src-Attribut jedes Medienelements jeweils nach dem letzten Backslash (). Dies wird anhand der Vorlage erreicht, die den Namen des Verzeichnisses hat und die rekursiv mit dem Wert des src-Attributs aufgerufen wird. Mit jedem Aufruf wird ein Backslash entfernt, bis entweder einer oder weniger übrig bleibt.

Zur Information: &#x0D; ist der Escape-Code für Zeilenumschaltung und &#x0A; ist der Escape-Code für Zeilenvorschub.

Daneben ist das xsl:output-Element extrem wichtig; es legt fest, dass die Ausgabe als Text mit der Codierung UTF-8 erfolgen soll. Wenn man keine Codierung angibt, funktioniert die Abspielliste nicht, auch wenn sie völlig in Ordnung aussieht.

Am Ende kann man XSLT von Liste D auf die Windows Media Player-Abspielliste Liste A anwenden, um die Winamp-Abspielliste Liste E zu erzeugen.

Liste E

Contents of Led Zeppelin – Box Set.m3u

#EXTM3U
Led Zeppelin [Box Set] Disc 11 Whole Lotta Love.mp3
Led Zeppelin [Box Set] Disc 12 Heartbreaker.mp3
Led Zeppelin [Box Set] Disc 13 Communication Breakdown.mp3
Led Zeppelin [Box Set] Disc 14 Babe I’m Gonna Leave You.mp3
Led Zeppelin [Box Set] Disc 15 What Is and What Should Never Be.mp3
Led Zeppelin [Box Set] Disc 16 Thank You.mp3
Led Zeppelin [Box Set] Disc 17 I Can’t Quit You Baby.mp3
Led Zeppelin [Box Set] Disc 18 Dazed and Confused.mp3
Led Zeppelin [Box Set] Disc 19 Your Time Is Gonna Come.mp3
Led Zeppelin [Box Set] Disc 110 Ramble On.mp3
Led Zeppelin [Box Set] Disc 111 Travelling Riverside Blues [#].mp3
Led Zeppelin [Box Set] Disc 112 Friends.mp3
Led Zeppelin [Box Set] Disc 113 Celebration Day.mp3
Led Zeppelin [Box Set] Disc 114 Hey Hey What Can I Do.mp3
Led Zeppelin [Box Set] Disc 115 White Summer-Black Mountain Side [#].mp3
Led Zeppelin [Box Set] Disc 21 Black Dog.mp3
Led Zeppelin [Box Set] Disc 22 Over the Hills and Far Away.mp3
Led Zeppelin [Box Set] Disc 23 Immigrant Song.mp3
Led Zeppelin [Box Set] Disc 24 The Battle of Evermore.mp3
Led Zeppelin [Box Set] Disc 25 Bron-Y-Aur Stomp.mp3
Led Zeppelin [Box Set] Disc 26 Tangerine.mp3
Led Zeppelin [Box Set] Disc 27 Going to California.mp3
Led Zeppelin [Box Set] Disc 28 Since I’ve Been Loving You.mp3
Led Zeppelin [Box Set] Disc 29 D’Yer Mak’er.mp3
Led Zeppelin [Box Set] Disc 210 Gallows Pole.mp3
Led Zeppelin [Box Set] Disc 211 Custard Pie.mp3
Led Zeppelin [Box Set] Disc 212 Misty Mountain Hop.mp3
Led Zeppelin [Box Set] Disc 213 Rock and Roll.mp3
Led Zeppelin [Box Set] Disc 214 The Rain Song.mp3
Led Zeppelin [Box Set] Disc 215 Stairway to Heaven.mp3
Led Zeppelin [Box Set] Disc 31 Kashmir.mp3
Led Zeppelin [Box Set] Disc 32 Trampled Under Foot.mp3
Led Zeppelin [Box Set] Disc 33 For Your Life.mp3
Led Zeppelin [Box Set] Disc 34 No Quarter.mp3
Led Zeppelin [Box Set] Disc 35 Dancing Days.mp3
Led Zeppelin [Box Set] Disc 36 When the Levee Breaks.mp3
Led Zeppelin [Box Set] Disc 37 Achilles Last Stand.mp3
Led Zeppelin [Box Set] Disc 38 The Song Remains the Same.mp3
Led Zeppelin [Box Set] Disc 39 Ten Years Gone.mp3
Led Zeppelin [Box Set] Disc 310 In My Time of Dying.mp3
Led Zeppelin [Box Set] Disc 41 In the Evening.mp3
Led Zeppelin [Box Set] Disc 42 Candy Store Rock.mp3
Led Zeppelin [Box Set] Disc 43 The Ocean.mp3
Led Zeppelin [Box Set] Disc 44 Ozone Baby.mp3
Led Zeppelin [Box Set] Disc 45 Houses of the Holy.mp3
Led Zeppelin [Box Set] Disc 46 Wearing and Tearing.mp3
Led Zeppelin [Box Set] Disc 47 Poor Tom.mp3
Led Zeppelin [Box Set] Disc 48 Nobody’s Fault But Mine.mp3
Led Zeppelin [Box Set] Disc 49 Fool in the Rain.mp3
Led Zeppelin [Box Set] Disc 410 In the Light.mp3
Led Zeppelin [Box Set] Disc 411 The Wanton Song.mp3
Led Zeppelin [Box Set] Disc 412 Moby Dick-Bonzo’s Montreux.mp3
Led Zeppelin [Box Set] Disc 413 I’m Gonna Crawl.mp3
Led Zeppelin [Box Set] Disc 414 All My Love.mp3

Fazit

Dies ist hoffentlich nützlich, um zumindest den musikalischen Teil seines Lebens zu organisieren. In jedem Fall lernt man so einen weiteren Bereich kennen, an dem man XML finden kann. Und wer sich selbst nun für einen Rebellen hält, der hört sich nun am besten „Dazed and Confused“ von Led Zepplin an.

Themenseiten: Anwendungsentwicklung, Big Data, Datenbank, Software

Fanden Sie diesen Artikel nützlich?
Content Loading ...
Whitepaper

Artikel empfehlen:

Neueste Kommentare 

Noch keine Kommentare zu Windows Media Player-Abspiellisten mit XSLT ins Winamp-Format konvertieren

Kommentar hinzufügen

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *