xspf 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/xspf2html.xsl ADDED
@@ -0,0 +1,212 @@
1
+ <!--
2
+ Convert XSPF to HTML.
3
+ Author: Lucas Gonze <lucas@gonze.com>
4
+ Copyright 2004 Lucas Gonze.
5
+ Licensed under version 2.0 of the Gnu General Public License.
6
+ -->
7
+ <xsl:stylesheet version = '1.0'
8
+ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
9
+ xmlns:xspf="http://xspf.org/ns/0/"
10
+ >
11
+
12
+ <xsl:output method="html" indent="yes"/>
13
+
14
+ <xsl:template match="/">
15
+ <html>
16
+ <head>
17
+
18
+ <xsl:if test="string(//xspf:title)">
19
+ <title>
20
+ <xsl:value-of select="//xspf:title"/>
21
+ </title>
22
+ </xsl:if>
23
+
24
+ <link rel='stylesheet' type='text/css' media='screen' href='http://www.w3.org/StyleSheets/Core/Modernist' />
25
+ <style type="text/css">
26
+ dl {
27
+ margin-bottom: 5px;
28
+ }
29
+
30
+ .track {
31
+ }
32
+
33
+ .location {
34
+ }
35
+
36
+ .creator {
37
+ }
38
+
39
+ .top {
40
+ }
41
+
42
+ .duration {
43
+ }
44
+
45
+ .trackList {
46
+ }
47
+
48
+ .info {
49
+ }
50
+
51
+ .annotation {
52
+ }
53
+
54
+ .attribution {
55
+ }
56
+
57
+ .image {
58
+ }
59
+
60
+ .meta {
61
+ }
62
+
63
+ .license {
64
+ }
65
+
66
+ .trackNum {
67
+ }
68
+
69
+ .date {
70
+ }
71
+
72
+ .identifier {
73
+ }
74
+
75
+ .link {
76
+ }
77
+
78
+
79
+ </style>
80
+
81
+ </head>
82
+
83
+ <body>
84
+
85
+ <xsl:if test="string(//xspf:title)">
86
+ <h1>
87
+ <xsl:value-of select="//xspf:title"/>
88
+ </h1>
89
+ </xsl:if>
90
+
91
+ <dl class="top">
92
+ <xsl:apply-templates select="*" />
93
+ </dl>
94
+
95
+ </body>
96
+ </html>
97
+ </xsl:template>
98
+
99
+ <!-- all href elements -->
100
+ <xsl:template match="xspf:location|xspf:info|xspf:license|xspf:link|xspf:meta">
101
+ <xsl:if test="string(.)">
102
+ <dt>
103
+ <xsl:attribute name="class">
104
+ <xsl:value-of select="name(.)"/>
105
+ </xsl:attribute>
106
+ <xsl:value-of select="name(.)"/>
107
+ </dt>
108
+ <dd>
109
+ <xsl:attribute name="class">
110
+ <xsl:value-of select="name(.)"/>
111
+ </xsl:attribute>
112
+
113
+ <!-- fixme: if there is a @rel or @property attribute, display
114
+ and link to it. We'll get an @rel if the current item is
115
+ xspf:link and @property if current item is xspf:meta. -->
116
+
117
+ <a>
118
+ <xsl:attribute name="href">
119
+ <xsl:value-of select="." />
120
+ </xsl:attribute>
121
+ <xsl:value-of select="." />
122
+ </a>
123
+
124
+ </dd>
125
+ </xsl:if>
126
+ </xsl:template>
127
+
128
+ <!-- all image elements -->
129
+ <xsl:template match="xspf:image">
130
+ <xsl:if test="string(.)">
131
+ <dt>
132
+ <xsl:attribute name="class">
133
+ <xsl:value-of select="name(.)"/>
134
+ </xsl:attribute>
135
+ <xsl:value-of select="name(.)"/>
136
+ </dt>
137
+ <dd>
138
+ <xsl:attribute name="class">
139
+ <xsl:value-of select="name(.)"/>
140
+ </xsl:attribute>
141
+ <img>
142
+ <xsl:attribute name="src">
143
+ <xsl:value-of select="." />
144
+ </xsl:attribute>
145
+ </img>
146
+ </dd>
147
+ </xsl:if>
148
+ </xsl:template>
149
+
150
+ <!-- all text elements -->
151
+ <xsl:template match="xspf:annotation|xspf:trackNum|xspf:creator|xspf:identifier|xspf:date|xspf:duration|xspf:title">
152
+ <xsl:if test="string(.)">
153
+ <dt>
154
+ <xsl:attribute name="class">
155
+ <xsl:value-of select="name(.)"/>
156
+ </xsl:attribute>
157
+ <xsl:value-of select="name(.)"/>
158
+ </dt>
159
+ <dd>
160
+ <xsl:attribute name="class">
161
+ <xsl:value-of select="name(.)"/>
162
+ </xsl:attribute>
163
+ <xsl:value-of select="." />
164
+ </dd>
165
+ </xsl:if>
166
+ </xsl:template>
167
+
168
+ <!-- ordered lists -->
169
+ <xsl:template match="xspf:trackList|xspf:attribution">
170
+ <xsl:if test="string(.)">
171
+ <dt>
172
+ <xsl:attribute name="class">
173
+ <xsl:value-of select="name(.)"/>
174
+ </xsl:attribute>
175
+ <xsl:value-of select="name(.)"/>
176
+ </dt>
177
+ <dd>
178
+ <xsl:attribute name="class">
179
+ <xsl:value-of select="name(.)"/>
180
+ </xsl:attribute>
181
+
182
+ <ol>
183
+ <xsl:for-each select="*">
184
+ <li>
185
+ <xsl:apply-templates select="." />
186
+ </li>
187
+ </xsl:for-each>
188
+ </ol>
189
+
190
+ </dd>
191
+ </xsl:if>
192
+ </xsl:template>
193
+
194
+ <!-- track element is an oddball that needs its own template -->
195
+ <xsl:template match="xspf:track">
196
+ <dl>
197
+ <xsl:attribute name="class">
198
+ <xsl:value-of select="name(.)"/>
199
+ </xsl:attribute>
200
+ <xsl:apply-templates select="*"/>
201
+ </dl>
202
+ </xsl:template>
203
+
204
+ <!-- top-level title element is an oddball that needs its own template -->
205
+ <xsl:template match="//xspf:title"/>
206
+
207
+ <!-- Suppress items not accounted for in templates. Disable during debugging, enable in production.
208
+ -->
209
+ <xsl:template match="text()" />
210
+
211
+ </xsl:stylesheet>
212
+
data/lib/xspf2m3u.xsl ADDED
@@ -0,0 +1,20 @@
1
+ <!--
2
+ xspf2m3u.xsl: transform XSPF to M3U
3
+ author: Lucas Gonze <lucas@webjay.org>
4
+ -->
5
+ <xsl:stylesheet version = '1.0'
6
+ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
7
+ xmlns:xspf="http://xspf.org/ns/0/">
8
+
9
+ <xsl:output method="text"/>
10
+ <xsl:template match="/">
11
+
12
+ <xsl:for-each select="//xspf:trackList/xspf:track/xspf:location">
13
+ <xsl:value-of select="."/>
14
+ <xsl:text>
15
+ </xsl:text>
16
+ </xsl:for-each>
17
+
18
+ </xsl:template>
19
+
20
+ </xsl:stylesheet>
data/lib/xspf2smil.xsl ADDED
@@ -0,0 +1,76 @@
1
+ <!--
2
+ Convert XSPF to SMIL.
3
+ Author: Lucas Gonze <lucas@gonze.com>
4
+
5
+ Copyright 2004 Lucas Gonze. Licensed under version 2.0 of the Gnu
6
+ General Public License.
7
+ -->
8
+ <xsl:stylesheet version = '1.0'
9
+ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
10
+ xmlns:xspf="http://xspf.org/ns/0/"
11
+ >
12
+
13
+ <xsl:output method="xml" indent="yes"/>
14
+
15
+ <xsl:template match="/">
16
+ <smil>
17
+ <body>
18
+ <seq>
19
+ <xsl:apply-templates select="*" />
20
+ </seq>
21
+ </body>
22
+ </smil>
23
+ </xsl:template>
24
+
25
+ <xsl:template match="//xspf:annotation" ></xsl:template>
26
+ <xsl:template match="//xspf:creator" ></xsl:template>
27
+ <xsl:template match="//xspf:info" ></xsl:template>
28
+ <xsl:template match="//xspf:location" ></xsl:template>
29
+ <xsl:template match="//xspf:identifier" ></xsl:template>
30
+ <xsl:template match="//xspf:image" ></xsl:template>
31
+ <xsl:template match="//xspf:link" ></xsl:template>
32
+ <xsl:template match="//xspf:meta" ></xsl:template>
33
+ <xsl:template match="//xspf:date" ></xsl:template>
34
+ <xsl:template match="//xspf:attribution" ></xsl:template>
35
+ <xsl:template match="//xspf:license" ></xsl:template>
36
+
37
+ <xsl:template match="//xspf:trackList">
38
+ <xsl:apply-templates select="*" />
39
+ </xsl:template>
40
+
41
+ <xsl:template match="//xspf:trackList/xspf:track">
42
+ <xsl:apply-templates select="xspf:location"/>
43
+ </xsl:template>
44
+
45
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:location" >
46
+ <audio>
47
+ <xsl:attribute name="src">
48
+ <xsl:value-of select="." />
49
+ </xsl:attribute>
50
+
51
+ <xsl:if test="string(../xspf:annotation)">
52
+ <xsl:attribute name="title">
53
+ <xsl:value-of select="../xspf:annotation"/>
54
+ </xsl:attribute>
55
+ </xsl:if>
56
+
57
+ </audio>
58
+ </xsl:template>
59
+
60
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:image" ></xsl:template>
61
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:annotation" ></xsl:template>
62
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:creator" ></xsl:template>
63
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:title" ></xsl:template>
64
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:album" ></xsl:template>
65
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:trackNum" ></xsl:template>
66
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:duration" ></xsl:template>
67
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:identifier" ></xsl:template>
68
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:info" ></xsl:template>
69
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:meta" ></xsl:template>
70
+
71
+ <!-- Suppress items not accounted for in templates. Disable during debugging, enable in production.
72
+ -->
73
+ <xsl:template match="text()" />
74
+
75
+ </xsl:stylesheet>
76
+
@@ -0,0 +1,65 @@
1
+ <!--
2
+ Convert XSPF to Soundblox data format.
3
+ Author: Lucas Gonze <lucas@gonze.com>
4
+ Copyright 2004 Lucas Gonze.
5
+ Licensed under version 2.0 of the Gnu General Public License.
6
+
7
+ A proof of concept, not robust yet. Needs work by someone more
8
+ familiar with Soundblox than I am.
9
+ -->
10
+ <xsl:stylesheet version = '1.0'
11
+ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
12
+ xmlns:xspf="http://xspf.org/ns/0/">
13
+
14
+ <xsl:output method="xml" indent="yes"/>
15
+
16
+ <xsl:template match="/">
17
+
18
+ <soundbloxdata>
19
+ <customize autostart="false" startopen="true"/>
20
+ <playlist>
21
+
22
+ <xsl:if test="string(//xspf:title)">
23
+ <xsl:attribute name="name">
24
+ <xsl:value-of select="//xspf:title"/>
25
+ </xsl:attribute>
26
+ </xsl:if>
27
+
28
+ <xsl:apply-templates select="*"/>
29
+
30
+ </playlist>
31
+ </soundbloxdata>
32
+
33
+ </xsl:template>
34
+
35
+ <xsl:template match="//xspf:trackList/xspf:track">
36
+ <track>
37
+ <xsl:apply-templates select="*"/>
38
+ </track>
39
+ </xsl:template>
40
+
41
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:location">
42
+ <xsl:if test="string(.)">
43
+ <!-- fixme: test extension to confirm it is an mp3 -->
44
+ <mp3url><xsl:value-of select="."/></mp3url>
45
+ <downloadurl><xsl:value-of select="."/></downloadurl>
46
+ </xsl:if>
47
+ </xsl:template>
48
+
49
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:image">
50
+ <xsl:if test="string(.)">
51
+ <imageurl><xsl:value-of select="."/></imageurl>
52
+ </xsl:if>
53
+ </xsl:template>
54
+
55
+ <xsl:template match="//xspf:trackList/xspf:track/xspf:annotation">
56
+ <xsl:if test="string(.)">
57
+ <comments><xsl:value-of select="."/></comments>
58
+ </xsl:if>
59
+ </xsl:template>
60
+
61
+ <!-- Suppress items not accounted for in templates. Disable during
62
+ debugging, enable in production. -->
63
+ <xsl:template match="text()"/>
64
+
65
+ </xsl:stylesheet>
@@ -0,0 +1,205 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'xspf'
4
+ require 'test/unit'
5
+
6
+ class TestXSPF < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @playlist_document = <<END_OF_PLAYLIST
10
+ <?xml version="1.0" encoding="UTF-8"?>
11
+ <playlist version="0" xmlns="http://xspf.org/ns/0/">
12
+ <title>XSPlF it up!</title>
13
+ <creator>Mayhem &amp; Chaos Coordinator</creator>
14
+ <annotation>Just a few songs to enjoy while you XSPlF it up!</annotation>
15
+ <info>http://mayhem-chaos.net/xspf/xspf_it_up.html</info>
16
+ <identifier>http://mayhem-chaos.net/xspf/xspf_it_up/1.0</identifier>
17
+ <attribution>
18
+ <location>http://mayhem-chaos.net/xspf/xspf_it_up.html</location>
19
+ </attribution>
20
+ <trackList>
21
+ <track>
22
+ <identifier>http://musicbrainz.org/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</identifier>
23
+ <title>I Wanna Get High</title>
24
+ <creator>Cypress Hill</creator>
25
+ <duration>174613</duration>
26
+ <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</meta>
27
+ </track>
28
+ <track>
29
+ <identifier>bdc846e7-6c26-4193-82a6-8d1b5a4d3429</identifier>
30
+ <title>Smoke Two Joints</title>
31
+ <creator>Sublime</creator>
32
+ <duration>175466</duration>
33
+ <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/bdc846e7-6c26-4193-82a6-8d1b5a4d3429</meta>
34
+ </track>
35
+ <track>
36
+ <identifier>http://musicbrainz.org/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</identifier>
37
+ <title>Hash Pipe</title>
38
+ <creator>Weezer</creator>
39
+ <duration>186533</duration>
40
+ <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</meta>
41
+ </track>
42
+ </trackList>
43
+ </playlist>
44
+ END_OF_PLAYLIST
45
+
46
+ @expected_smil_output = <<END_OF_SMIL
47
+ <?xml version="1.0"?>
48
+ <smil xmlns:xspf="http://xspf.org/ns/0/">
49
+ <body>
50
+ <seq/>
51
+ </body>
52
+ </smil>
53
+ END_OF_SMIL
54
+
55
+ @expected_html_ouput = <<END_OF_HTML
56
+ <html xmlns:xspf="http://xspf.org/ns/0/">
57
+ <head>
58
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
59
+ <title>XSPlF it up!</title>
60
+ <link href="http://www.w3.org/StyleSheets/Core/Modernist" rel="stylesheet" type="text/css" media="screen">
61
+ <style type="text/css">
62
+ dl {
63
+ margin-bottom: 5px;
64
+ }
65
+
66
+ .track {
67
+ }
68
+
69
+ .location {
70
+ }
71
+
72
+ .creator {
73
+ }
74
+
75
+ .top {
76
+ }
77
+
78
+ .duration {
79
+ }
80
+
81
+ .trackList {
82
+ }
83
+
84
+ .info {
85
+ }
86
+
87
+ .annotation {
88
+ }
89
+
90
+ .attribution {
91
+ }
92
+
93
+ .image {
94
+ }
95
+
96
+ .meta {
97
+ }
98
+
99
+ .license {
100
+ }
101
+
102
+ .trackNum {
103
+ }
104
+
105
+ .date {
106
+ }
107
+
108
+ .identifier {
109
+ }
110
+
111
+ .link {
112
+ }
113
+
114
+
115
+ </style>
116
+ </head>
117
+ <body>
118
+ <h1>XSPlF it up!</h1>
119
+ <dl class="top">
120
+ <dt class="creator">creator</dt>
121
+ <dd class="creator">Mayhem &amp; Chaos Coordinator</dd>
122
+ <dt class="annotation">annotation</dt>
123
+ <dd class="annotation">Just a few songs to enjoy while you XSPlF it up!</dd>
124
+ <dt class="info">info</dt>
125
+ <dd class="info"><a href="http://mayhem-chaos.net/xspf/xspf_it_up.html">http://mayhem-chaos.net/xspf/xspf_it_up.html</a></dd>
126
+ <dt class="identifier">identifier</dt>
127
+ <dd class="identifier">http://mayhem-chaos.net/xspf/xspf_it_up/1.0</dd>
128
+ <dt class="attribution">attribution</dt>
129
+ <dd class="attribution"><ol><li>
130
+ <dt class="location">location</dt>
131
+ <dd class="location"><a href="http://mayhem-chaos.net/xspf/xspf_it_up.html">http://mayhem-chaos.net/xspf/xspf_it_up.html</a></dd>
132
+ </li></ol></dd>
133
+ <dt class="trackList">trackList</dt>
134
+ <dd class="trackList"><ol>
135
+ <li><dl class="track">
136
+ <dt class="identifier">identifier</dt>
137
+ <dd class="identifier">http://musicbrainz.org/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</dd>
138
+ <dt class="creator">creator</dt>
139
+ <dd class="creator">Cypress Hill</dd>
140
+ <dt class="duration">duration</dt>
141
+ <dd class="duration">174613</dd>
142
+ <dt class="meta">meta</dt>
143
+ <dd class="meta"><a href="http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793">http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</a></dd>
144
+ </dl></li>
145
+ <li><dl class="track">
146
+ <dt class="identifier">identifier</dt>
147
+ <dd class="identifier">bdc846e7-6c26-4193-82a6-8d1b5a4d3429</dd>
148
+ <dt class="creator">creator</dt>
149
+ <dd class="creator">Sublime</dd>
150
+ <dt class="duration">duration</dt>
151
+ <dd class="duration">175466</dd>
152
+ <dt class="meta">meta</dt>
153
+ <dd class="meta"><a href="http://musicbrainz.org/mm-2.1/track/bdc846e7-6c26-4193-82a6-8d1b5a4d3429">http://musicbrainz.org/mm-2.1/track/bdc846e7-6c26-4193-82a6-8d1b5a4d3429</a></dd>
154
+ </dl></li>
155
+ <li><dl class="track">
156
+ <dt class="identifier">identifier</dt>
157
+ <dd class="identifier">http://musicbrainz.org/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</dd>
158
+ <dt class="creator">creator</dt>
159
+ <dd class="creator">Weezer</dd>
160
+ <dt class="duration">duration</dt>
161
+ <dd class="duration">186533</dd>
162
+ <dt class="meta">meta</dt>
163
+ <dd class="meta"><a href="http://musicbrainz.org/mm-2.1/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58">http://musicbrainz.org/mm-2.1/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</a></dd>
164
+ </dl></li>
165
+ </ol></dd>
166
+ </dl>
167
+ </body>
168
+ </html>
169
+ END_OF_HTML
170
+
171
+ @expected_soundblox_ouput = <<END_OF_SOUNDBLOX
172
+ <?xml version="1.0"?>
173
+ <soundbloxdata xmlns:xspf="http://xspf.org/ns/0/">
174
+ <customize autostart="false" startopen="true"/>
175
+ <playlist name="XSPlF it up!">
176
+ <track/>
177
+ <track/>
178
+ <track/>
179
+ </playlist>
180
+ </soundbloxdata>
181
+ END_OF_SOUNDBLOX
182
+
183
+ @xspf = XSPF.new(@playlist_document)
184
+ end
185
+
186
+ def test_m3u
187
+ assert_nil(@xspf.to_m3u)
188
+ end
189
+
190
+ def test_smil
191
+ assert_equal(@xspf.to_smil, @expected_smil_output)
192
+ end
193
+
194
+ def test_html
195
+ assert_equal(@xspf.to_html, @expected_html_ouput)
196
+ end
197
+
198
+ def test_soundblox
199
+ assert_equal(@xspf.to_soundblox, @expected_soundblox_ouput)
200
+ end
201
+
202
+ def test_error
203
+ assert_raise(NoMethodError) {@xspf.to_other_format }
204
+ end
205
+ end