xspf 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/doc/created.rid ADDED
@@ -0,0 +1 @@
1
+ Fri Oct 20 16:51:35 CEST 2006
@@ -0,0 +1,30 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/XSPF.html">XSPF</a><br />
24
+ <a href="classes/XSPF/Playlist.html">XSPF::Playlist</a><br />
25
+ <a href="classes/XSPF/Track.html">XSPF::Track</a><br />
26
+ <a href="classes/XSPF/Tracklist.html">XSPF::Tracklist</a><br />
27
+ </div>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,28 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Files
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Files</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Files</h1>
22
+ <div id="index-entries">
23
+ <a href="files/lib/xspf_rb.html">lib/xspf.rb</a><br />
24
+ <a href="files/xspf-expanded_rb.html">xspf-expanded.rb</a><br />
25
+ </div>
26
+ </div>
27
+ </body>
28
+ </html>
@@ -0,0 +1,71 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Methods
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Methods</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Methods</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/XSPF/Track.html#M000016">album (XSPF::Track)</a><br />
24
+ <a href="classes/XSPF/Track.html#M000013">annotation (XSPF::Track)</a><br />
25
+ <a href="classes/XSPF/Playlist.html#M000029">annotation (XSPF::Playlist)</a><br />
26
+ <a href="classes/XSPF/Playlist.html#M000036">attribution (XSPF::Playlist)</a><br />
27
+ <a href="classes/XSPF/Track.html#M000012">creator (XSPF::Track)</a><br />
28
+ <a href="classes/XSPF/Playlist.html#M000028">creator (XSPF::Playlist)</a><br />
29
+ <a href="classes/XSPF/Playlist.html#M000034">date (XSPF::Playlist)</a><br />
30
+ <a href="classes/XSPF/Track.html#M000018">duration (XSPF::Track)</a><br />
31
+ <a href="classes/XSPF.html#M000002">encoding (XSPF)</a><br />
32
+ <a href="classes/XSPF/Track.html#M000019">extension (XSPF::Track)</a><br />
33
+ <a href="classes/XSPF/Playlist.html#M000037">extension (XSPF::Playlist)</a><br />
34
+ <a href="classes/XSPF/Track.html#M000010">identifier (XSPF::Track)</a><br />
35
+ <a href="classes/XSPF/Playlist.html#M000032">identifier (XSPF::Playlist)</a><br />
36
+ <a href="classes/XSPF/Track.html#M000015">image (XSPF::Track)</a><br />
37
+ <a href="classes/XSPF/Playlist.html#M000033">image (XSPF::Playlist)</a><br />
38
+ <a href="classes/XSPF/Playlist.html#M000030">info (XSPF::Playlist)</a><br />
39
+ <a href="classes/XSPF/Track.html#M000014">info (XSPF::Track)</a><br />
40
+ <a href="classes/XSPF/Playlist.html#M000035">license (XSPF::Playlist)</a><br />
41
+ <a href="classes/XSPF/Playlist.html#M000038">link_content (XSPF::Playlist)</a><br />
42
+ <a href="classes/XSPF/Track.html#M000020">link_content (XSPF::Track)</a><br />
43
+ <a href="classes/XSPF/Track.html#M000021">link_rel (XSPF::Track)</a><br />
44
+ <a href="classes/XSPF/Playlist.html#M000039">link_rel (XSPF::Playlist)</a><br />
45
+ <a href="classes/XSPF/Playlist.html#M000031">location (XSPF::Playlist)</a><br />
46
+ <a href="classes/XSPF/Track.html#M000009">location (XSPF::Track)</a><br />
47
+ <a href="classes/XSPF/Playlist.html#M000040">meta_content (XSPF::Playlist)</a><br />
48
+ <a href="classes/XSPF/Track.html#M000022">meta_content (XSPF::Track)</a><br />
49
+ <a href="classes/XSPF/Track.html#M000023">meta_rel (XSPF::Track)</a><br />
50
+ <a href="classes/XSPF/Playlist.html#M000041">meta_rel (XSPF::Playlist)</a><br />
51
+ <a href="classes/XSPF/Track.html#M000024">new (XSPF::Track)</a><br />
52
+ <a href="classes/XSPF/Tracklist.html#M000044">new (XSPF::Tracklist)</a><br />
53
+ <a href="classes/XSPF/Playlist.html#M000042">new (XSPF::Playlist)</a><br />
54
+ <a href="classes/XSPF.html#M000007">new (XSPF)</a><br />
55
+ <a href="classes/XSPF.html#M000008">playlist (XSPF)</a><br />
56
+ <a href="classes/XSPF/Track.html#M000011">title (XSPF::Track)</a><br />
57
+ <a href="classes/XSPF/Playlist.html#M000027">title (XSPF::Playlist)</a><br />
58
+ <a href="classes/XSPF.html#M000004">to_html (XSPF)</a><br />
59
+ <a href="classes/XSPF.html#M000003">to_m3u (XSPF)</a><br />
60
+ <a href="classes/XSPF.html#M000005">to_smil (XSPF)</a><br />
61
+ <a href="classes/XSPF.html#M000006">to_soundblox (XSPF)</a><br />
62
+ <a href="classes/XSPF/Playlist.html#M000043">tracklist (XSPF::Playlist)</a><br />
63
+ <a href="classes/XSPF/Track.html#M000017">tracknum (XSPF::Track)</a><br />
64
+ <a href="classes/XSPF/Tracklist.html#M000045">tracks (XSPF::Tracklist)</a><br />
65
+ <a href="classes/XSPF/Playlist.html#M000026">version (XSPF::Playlist)</a><br />
66
+ <a href="classes/XSPF.html#M000001">version (XSPF)</a><br />
67
+ <a href="classes/XSPF/Playlist.html#M000025">xmlns (XSPF::Playlist)</a><br />
68
+ </div>
69
+ </div>
70
+ </body>
71
+ </html>
data/doc/index.html ADDED
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="classes/XSPF.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,36 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'xspf'
4
+
5
+ f = File.new("playlist.xspf")
6
+
7
+ x = XSPF.new(f)
8
+ puts "XML version: #{x.version}"
9
+ puts "XML encoding: #{ x.encoding}"
10
+ puts "-"*20
11
+
12
+ pl = XSPF::Playlist.new(x)
13
+ puts "XSPF version: #{pl.version}"
14
+ puts "Namespace: #{pl.xmlns}"
15
+ puts "Playlist title: #{pl.title}"
16
+ puts "Playlist creator: #{pl.creator}"
17
+ puts "Playlist annotation: #{pl.annotation}"
18
+ puts "Playlist info: #{pl.info}"
19
+ puts "Playlist identifier: #{pl.identifier}"
20
+ puts "Playlist attribution: #{pl.attribution}"
21
+ puts "Tracklist: #{pl.tracklist}"
22
+ puts "-"*20
23
+
24
+ tl = XSPF::Tracklist.new(pl)
25
+ tl.tracks.each do |t|
26
+ puts "Track identifier: #{t.identifier}"
27
+ puts "Track title: #{t.title}"
28
+ puts "Track creator: #{t.creator}"
29
+ puts "Track duration: #{t.duration}"
30
+ puts "Track metainformation: link=#{t.meta_rel} content=#{t.meta_content}"
31
+ end
32
+
33
+ x.to_m3u
34
+ x.to_smil
35
+ x.to_html
36
+ x.to_soundblox
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <playlist version="0"
3
+ xmlns="http://xspf.org/ns/0/"
4
+ xmlns:sh="http://xspf.org/ext/sh/0/"
5
+ xmlns:cl="http://xspf.org/ext/cl/0/">
6
+ <title>XSPlF it up!</title>
7
+ <creator>Mayhem &amp; Chaos Coordinator</creator>
8
+ <annotation>Just a few songs to enjoy while you XSPlF it up!</annotation>
9
+ <info>http://mayhem-chaos.net/xspf/xspf_it_up.html</info>
10
+ <identifier>http://mayhem-chaos.net/xspf/xspf_it_up/1.0</identifier>
11
+ <attribution>
12
+ <location>http://mayhem-chaos.net/xspf/xspf_it_up.html</location>
13
+ </attribution>
14
+ <extension>
15
+ <sh:shuffle order="random"/>
16
+ </extension>
17
+ <trackList>
18
+ <track>
19
+ <identifier>http://musicbrainz.org/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</identifier>
20
+ <title>I Wanna Get High</title>
21
+ <creator>Cypress Hill</creator>
22
+ <duration>174613</duration>
23
+ <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</meta>
24
+ <extension>
25
+ <cl:clip start="25000" end="34500"/>
26
+ </extension>
27
+ </track>
28
+ <track>
29
+ <identifier>http://musicbrainz.org/track/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>
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <playlist version="0" xmlns="http://xspf.org/ns/0/">
3
+ <title>XSPlF it up!</title>
4
+ <creator>Mayhem &amp; Chaos Coordinator</creator>
5
+ <annotation>Just a few songs to enjoy while you XSPlF it up!</annotation>
6
+ <info>http://mayhem-chaos.net/xspf/xspf_it_up.html</info>
7
+ <identifier>http://mayhem-chaos.net/xspf/xspf_it_up/1.0</identifier>
8
+ <attribution>
9
+ <location>http://mayhem-chaos.net/xspf/xspf_it_up.html</location>
10
+ </attribution>
11
+ <trackList>
12
+ <track>
13
+ <identifier>http://musicbrainz.org/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</identifier>
14
+ <title>I Wanna Get High</title>
15
+ <creator>Cypress Hill</creator>
16
+ <duration>174613</duration>
17
+ <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</meta>
18
+ </track>
19
+ <track>
20
+ <identifier>bdc846e7-6c26-4193-82a6-8d1b5a4d3429</identifier>
21
+ <title>Smoke Two Joints</title>
22
+ <creator>Sublime</creator>
23
+ <duration>175466</duration>
24
+ <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/bdc846e7-6c26-4193-82a6-8d1b5a4d3429</meta>
25
+ </track>
26
+ <track>
27
+ <identifier>http://musicbrainz.org/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</identifier>
28
+ <title>Hash Pipe</title>
29
+ <creator>Weezer</creator>
30
+ <duration>186533</duration>
31
+ <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</meta>
32
+ </track>
33
+ </trackList>
34
+ </playlist>
data/lib/xspf.rb ADDED
@@ -0,0 +1,319 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2006 Pau Garcia i Quiles (pgquiles@elpauer.org)
4
+ # All rights reserved.
5
+ #
6
+ # This library may be used only as allowed by either the Ruby license (or, by
7
+ # association with the Ruby license, the GPL). See the "doc" subdirectory of
8
+ # the XSPF distribution for the texts of these licenses.
9
+ # -----------------------------------------------------------------------------
10
+ # XSPF for Ruby website : http://www.elpauer.org/xspf
11
+ # =============================================================================
12
+ #++
13
+
14
+ require 'rexml/document'
15
+ require 'xml/xslt'
16
+
17
+ # :main: XSPF
18
+
19
+ module MetaGen #:nodoc:
20
+
21
+ # define the method
22
+ def self.add_method(klass, meth_name, body, meth_rdoc)
23
+ code = "# #{meth_rdoc}\n def #{meth_name.downcase}; begin; #{body}; rescue NoMethodError; return nil; end; end"
24
+
25
+ klass.module_eval(code)
26
+
27
+ # hook to write klass + name attrib to a file
28
+ if $META_RDOC
29
+ open($META_RDOC, 'a+') do |f|
30
+ f.puts("class #{klass}\n #{code}\n end")
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ # output in different formats
37
+ def self.add_output_format(klass, format, xspf, meth_rdoc)
38
+ xslt_path = "'#{File.join( File.dirname(__FILE__), %Q{xspf2#{format}.xsl} )}'"
39
+ code = "# #{meth_rdoc}\n def to_#{format}; xslt = XML::XSLT.new; xslt.xml = xspf; xslt.xsl = REXML::Document.new( File.new( #{xslt_path} ) ); xslt.serve; end"
40
+
41
+ klass.module_eval(code)
42
+
43
+ if $META_RDOC
44
+ open($META_RDOC, 'a+') do |f|
45
+ f.puts("class #{klass}\n #{code}\n end")
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ # XML Shareable Playlist Format (XSPF[http://www.xspf.org]) parser for Ruby
54
+ #
55
+ # When parsing, if a XSPF attribute or element is not set, the corresponding method will return _nil_.
56
+ #
57
+ # === Examples
58
+ # ==== Parse from file
59
+ # require 'xspf'
60
+ #
61
+ # f = File.new("playlist.xspf")
62
+ # x = XSPF.new(f)
63
+ # pl = XSPF::Playlist.new(x)
64
+ # tl = XSPF::Tracklist.new(pl)
65
+ #
66
+ # puts "XML version: #{x.version}"
67
+ # puts "XML encoding: #{ x.encoding}"
68
+ # puts "XSPF version: #{pl.version}"
69
+ # puts "Namespace: #{pl.xmlns}"
70
+ # puts "Playlist title: #{pl.title}"
71
+ # puts "Playlist creator: #{pl.creator}"
72
+ # puts "Playlist annotation: #{pl.annotation}"
73
+ # puts "Playlist info: #{pl.info}"
74
+ # puts "Playlist identifier: #{pl.identifier}"
75
+ # puts "Playlist attribution: #{pl.attribution}"
76
+ # puts "Tracklist: #{pl.tracklist}"
77
+ # tl.tracks.each do |t|
78
+ # puts "Track identifier: #{t.identifier}"
79
+ # puts "Track title: #{t.title}"
80
+ # puts "Track creator: #{t.creator}"
81
+ # puts "Track duration: #{t.duration}"
82
+ # puts "Track metainformation: link=#{t.meta_rel} content=#{t.meta_content}"
83
+ # end
84
+ #
85
+ # # Convert the XSPF document to SMIL
86
+ # x.to_smil
87
+ #
88
+ # # Convert the XSPF document to HTML
89
+ # x.to_html
90
+ #
91
+ # # Convert the XSPF document in a M3U playlist
92
+ # x.to_m3u
93
+ #
94
+ # ==== Parse from string
95
+ # playlist_document = <<-END_OF_PLAYLIST
96
+ # <?xml version="1.0" encoding="UTF-8"?>
97
+ # <playlist version="0" xmlns="http://xspf.org/ns/0/">
98
+ # <title>XSPlF it up!</title>
99
+ # <creator>Mayhem &amp; Chaos Coordinator</creator>
100
+ # <annotation>Just a few songs to enjoy while you XSPlF it up!</annotation>
101
+ # <info>http://mayhem-chaos.net/xspf/xspf_it_up.html</info>
102
+ # <identifier>http://mayhem-chaos.net/xspf/xspf_it_up/1.0</identifier>
103
+ # <attribution>
104
+ # <location>ihttp://mayhem-chaos.net/xspf/xspf_it_up.html</location>
105
+ # </attribution>
106
+ # <trackList>
107
+ # <track>
108
+ # <identifier>http://musicbrainz.org/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</identifier>
109
+ # <title>I Wanna Get High</title>
110
+ # <creator>Cypress Hill</creator>
111
+ # <duration>174613</duration>
112
+ # <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</meta>
113
+ # </track>
114
+ # <track>
115
+ # <identifier>bdc846e7-6c26-4193-82a6-8d1b5a4d3429</identifier>
116
+ # <title>Smoke Two Joints</title>
117
+ # <creator>Sublime</creator>
118
+ # <duration>175466</duration>
119
+ # <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/bdc846e7-6c26-4193-82a6-8d1b5a4d3429</meta>
120
+ # </track>
121
+ # <track>
122
+ # <identifier>http://musicbrainz.org/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</identifier>
123
+ # <title>Hash Pipe</title>
124
+ # <creator>Weezer</creator>
125
+ # <duration>186533</duration>
126
+ # <meta rel="http://musicbrainz.org/track">http://musicbrainz.org/mm-2.1/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</meta>
127
+ # </track>
128
+ # </trackList>
129
+ # </playlist>
130
+ # END_OF_PLAYLIST
131
+ #
132
+ # x = XSPF.new(playlist_document)
133
+ # pl = XSPF::Playlist.new(x)
134
+ # tl = XSPF::Tracklist.new(pl)
135
+ #
136
+ # puts "XML version: #{x.version}"
137
+ # puts "XML encoding: #{ x.encoding}"
138
+ # puts "XSPF version: #{pl.version}"
139
+ # puts "Namespace: #{pl.xmlns}"
140
+ # puts "Playlist title: #{pl.title}"
141
+ # puts "Playlist creator: #{pl.creator}"
142
+ # puts "Playlist annotation: #{pl.annotation}"
143
+ # puts "Playlist info: #{pl.info}"
144
+ # puts "Playlist identifier: #{pl.identifier}"
145
+ # puts "Playlist attribution: #{pl.attribution}"
146
+ # puts "Tracklist: #{pl.tracklist}"
147
+ # tl.tracks.each do |t|
148
+ # puts "Track identifier: #{t.identifier}"
149
+ # puts "Track title: #{t.title}"
150
+ # puts "Track creator: #{t.creator}"
151
+ # puts "Track duration: #{t.duration}"
152
+ # puts "Track metainformation: link=#{t.meta_rel} content=#{t.meta_content}"
153
+ # end
154
+ #
155
+ # # Convert the XSPF document to SMIL
156
+ # x.to_smil
157
+ #
158
+ # # Convert the XSPF document to HTML
159
+ # x.to_html
160
+ #
161
+ # # Convert the XSPF document in a M3U playlist
162
+ # x.to_m3u
163
+ #
164
+
165
+ class XSPF
166
+
167
+ attr_reader :xspf
168
+
169
+ #:stopdoc:
170
+ ATTRIBUTES = %w{ version encoding }
171
+ VERSION_RDOC = "Version for the XML document or _nil_ if not defined"
172
+ ENCODING_RDOC = "Encoding of the XML document or _nil_ if not defined"
173
+
174
+ OUTPUT_FORMATS = %w{ m3u html smil soundblox }
175
+ M3U_RDOC = "Creates a .m3u playlist from the XSPF document. This method makes use of the official XSPF to M3U XSLT transformation by Lucas Gonze."
176
+ HTML_RDOC = "Outputs the playlist as an HTML page. This method makes use of the official XSPF to HTML XSLT transformation by Lucas Gonze."
177
+ SMIL_RDOC = "Creates a .smil playlist from the XSPF document. This method makes use of the official XSPF to SMIL XSLT transformation by Lucas Gonze."
178
+ SOUNDBLOX_RDOC = "Creates a SoundBlox playlist from the XSPF document. This method makes use of the official XSPF to SoundBlox XSLT tranformation by Lucas Gonze."
179
+
180
+ ATTRIBUTES.each do |attrib|
181
+ MetaGen.add_method(self, attrib, "@xspf.#{attrib}", eval(attrib.upcase + '_RDOC').to_s )
182
+ end
183
+
184
+ OUTPUT_FORMATS.each do |format|
185
+ MetaGen.add_output_format(self, format, @xspf, eval(format.upcase + '_RDOC').to_s )
186
+ end
187
+
188
+ #:startdoc:
189
+
190
+ # Creates a XSPF object from a file or string
191
+ def initialize(source = nil)
192
+ @xspf = REXML::Document.new(source)
193
+ end
194
+
195
+ # The <playlist> section of the XSPF document
196
+ def playlist
197
+ @xspf.root
198
+ end
199
+
200
+ end
201
+
202
+ class XSPF::Playlist < XSPF
203
+
204
+ attr_reader :playlist
205
+
206
+ #:stopdoc:
207
+ ATTRIBUTES = %w{ xmlns version }
208
+ ELEMENTS = %w{ title creator annotation info location identifier image date license attribution extension }
209
+ ATTRIBUTE_AND_ELEMENT = %w{ link meta }
210
+ attribution_subelements = %w{ location identifier }
211
+ extension_subelements = %w{ application content }
212
+ XMLNS_RDOC = "The XML namespace. It must be http://xspf.org/ns/0/ for a valid XSPF document."
213
+ VERSION_RDOC = "The XSPF version. It may be 0 or 1, although 1 is strongly advised."
214
+ TITLE_RDOC = "A human-readable title for the playlist. xspf:playlist elements MAY contain exactly one."
215
+ CREATOR_RDOC = "Human-readable name of the entity (author, authors, group, company, etc) that authored the playlist. XSPF::Playlist objects MAY contain exactly one."
216
+ ANNOTATION_RDOC = "A human-readable comment on the playlist. This is character data, not HTML, and it may not contain markup. XSPF::Playlist objects elements MAY contain exactly one."
217
+ INFO_RDOC = "URL of a web page to find out more about this playlist. Likely to be homepage of the author, and would be used to find out more about the author and to find more playlists by the author. XSPF::Playlist objects MAY contain exactly one."
218
+ LOCATION_RDOC = "Source URL for this playlist. XSPF::Playlist objects MAY contain exactly one."
219
+ IDENTIFIER_RDOC = "Canonical ID for this playlist. Likely to be a hash or other location-independent name. MUST be a legal URN. XSPF::Playlist objects MAY contain exactly one."
220
+ IMAGE_RDOC = "URL of an image to display if XSPF::Playlist#image return nil. XSPF::Playlist objects MAY contain exactly one."
221
+ DATE_RDOC = "Creation date (not last-modified date) of the playlist, formatted as a XML schema dateTime. XSPF::Playlist objects MAY contain exactly one."
222
+ LICENSE_RDOC = "URL of a resource that describes the license under which this playlist was released. XSPF::Playlist objects MAY contain zero or one license element."
223
+ ATTRIBUTION_RDOC = "An ordered list of URIs. The purpose is to satisfy licenses allowing modification but requiring attribution. If you modify such a playlist, move its XSPF::Playlist#location or XSPF::Playlist#identifier element to the top of the items in the XSPF::Playlist#attribution element. XSPF::Playlist objects MAY contain exactly one attribution element. Please note that currently XSPF for Ruby does not parse the contents of XSPF::Playlist#attribution."
224
+ EXTENSION_RDOC = "The extension element allows non-XSPF XML to be included in XSPF documents without breaking XSPF validation. The purpose is to allow nested XML, which the meta and link elements do not. XSPF::Playlist objects MAY contain zero or more extension elements but currently XSPF for Ruby returns only the first one."
225
+ LINK_REL_RDOC = "The link element allows non-XSPF web resources to be included in XSPF documents without breaking XSPF validation. A valid 'link' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Playlist#link_rel and XSPF::Playlist#link_content respectively. XSPF::Playlist objects MAY contain zero or more link elements, but currently XSPF for Ruby returns only the first one."
226
+ LINK_CONTENT_RDOC = "The link element allows non-XSPF web resources to be included in XSPF documents without breaking XSPF validation. A valid 'link' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Playlist#link_rel and XSPF::Playlist#link_content respectively. XSPF::Playlist objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one."
227
+ META_REL_RDOC = "The meta element allows non-XSPF metadata to be included in XSPF documents without breaking XSPF validation. A valid 'meta' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Playlist#meta_rel and XSPF::Playlist#meta_content respectively. XSPF::Playlist objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one."
228
+ META_CONTENT_RDOC = "The meta element allows non-XSPF metadata to be included in XSPF documents without breaking XSPF validation. A valid 'meta' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Playlist#meta_rel and XSPF::Playlist#meta_content respectively. XSPF::Playlist objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one."
229
+
230
+ # FIXME Currently we only return the first "link"
231
+ # FIXME Currently we only return the first "meta"
232
+ # FIXME Currently we only return the first "extension"
233
+ # TODO Parse "attribution"
234
+ # TODO Parse "extension"
235
+
236
+ # Returns the value of the attribute or nil if the attribute is not present
237
+ ATTRIBUTES.each do |attrib|
238
+ MetaGen.add_method( self, attrib, "@playlist.root.attributes['#{attrib}']", eval(attrib.upcase + '_RDOC').to_s )
239
+ end
240
+
241
+ ELEMENTS.each do |element|
242
+ MetaGen.add_method( self, element, "@playlist.elements['#{element}'].text", eval(element.upcase + '_RDOC').to_s )
243
+ end
244
+
245
+ ATTRIBUTE_AND_ELEMENT.each do |ae|
246
+ MetaGen.add_method( self, "#{ae}_content", "@playlist.elements['#{ae}'].text", eval(ae.upcase + '_CONTENT_RDOC').to_s )
247
+ MetaGen.add_method( self, "#{ae}_rel", "@playlist.elements['#{ae}'].attributes['rel']", eval(ae.upcase + '_REL_RDOC').to_s )
248
+ end
249
+
250
+ #:startdoc:
251
+
252
+ # Creates a XSPF::Playlist from a XSPF document
253
+ def initialize(source)
254
+ @playlist = source.playlist
255
+ end
256
+
257
+ # The <trackList> section of the XSPF document
258
+ def tracklist
259
+ @playlist.elements['trackList'] || nil
260
+ end
261
+
262
+ end
263
+
264
+ class XSPF::Tracklist < XSPF::Playlist
265
+
266
+ attr_reader :tracklist
267
+
268
+ # Creates a XSPF::Tracklist from a XSPF::Playlist
269
+ def initialize(playlist)
270
+ @tracklist = playlist.tracklist
271
+ end
272
+
273
+ # An array XSPF::Track objects, one for each track returned by XSPF::Playlist#tracklist
274
+ def tracks
275
+ @tracklist.elements.collect { |track| XSPF::Track.new(track) }
276
+ end
277
+
278
+ end
279
+
280
+ class XSPF::Track
281
+
282
+ attr_reader :track
283
+
284
+ #:stopdoc:
285
+ ELEMENTS = %w{ location identifier title creator annotation info image album trackNum duration extension }
286
+ ATTRIBUTE_AND_ELEMENT = %w{ link meta }
287
+ LOCATION_RDOC = "URL of resource to be rendered. Probably an audio resource, but MAY be any type of resource with a well-known duration, such as video, a SMIL document, or an XSPF document. The duration of the resource defined in this element defines the duration of rendering. XSPF::Track objects MAY contain zero or more location elements, but a user-agent MUST NOT render more than one of the named resources. Currently, XSPF for Ruby returns only the first location."
288
+ IDENTIFIER_RDOC = "Canonical ID for this resource. Likely to be a hash or other location-independent name, such as a MusicBrainz identifier or isbn URN (if there existed isbn numbers for audio). MUST be a legal URN. XSPF::Track objects elements MAY contain zero or more identifier elements, but currently XSPF for Ruby returns only the first one."
289
+ TITLE_RDOC = "Human-readable name of the track that authored the resource which defines the duration of track rendering. This value is primarily for fuzzy lookups, though a user-agent may display it. XSPF::Track objects MAY contain exactly one."
290
+ CREATOR_RDOC = "Human-readable name of the entity (author, authors, group, company, etc) that authored the resource which defines the duration of track rendering. This value is primarily for fuzzy lookups, though a user-agent may display it. XSPF::Track objects MAY contain exactly one."
291
+ ANNOTATION_RDOC = "A human-readable comment on the track. This is character data, not HTML, and it may not contain markup. XSPF::Track objects MAY contain exactly one."
292
+ INFO_RDOC = "URL of a place where this resource can be bought or more info can be found."
293
+ IMAGE_RDOC = "URL of an image to display for the duration of the track. XSPF::Track objects MAY contain exactly one."
294
+ ALBUM_RDOC = "Human-readable name of the collection from which the resource which defines the duration of track rendering comes. For a song originally published as a part of a CD or LP, this would be the title of the original release. This value is primarily for fuzzy lookups, though a user-agent may display it. XSPF::Track objects MAY contain exactly one."
295
+ TRACKNUM_RDOC = "Integer with value greater than zero giving the ordinal position of the media on the XSPF::Track#album. This value is primarily for fuzzy lookups, though a user-agent may display it. XSPF::Track objects MAY contain exactly one. It MUST be a valid XML Schema nonNegativeInteger."
296
+ DURATION_RDOC = "The time to render a resource, in milliseconds. It MUST be a valid XML Schema nonNegativeInteger. This value is only a hint -- different XSPF generators will generate slightly different values. A user-agent MUST NOT use this value to determine the rendering duration, since the data will likely be low quality. XSPF::Track objects MAY contain exactly one duration element."
297
+ EXTENSION_RDOC = "The extension element allows non-XSPF XML to be included in XSPF documents without breaking XSPF validation. The purpose is to allow nested XML, which the meta and link elements do not. XSPF::Track objects MAY contain zero or more extension elements, but currently XSPF for Ruby returns only the first one."
298
+ LINK_REL_RDOC = "The link element allows non-XSPF web resources to be included in XSPF documents without breaking XSPF validation. A valid 'link' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Track#link_rel and XSPF::Track#link_content respectively. XSPF::Track objects MAY contain zero or more link elements, but currently XSPF for Ruby returns only the first one."
299
+ LINK_CONTENT_RDOC = "The link element allows non-XSPF web resources to be included in XSPF documents without breaking XSPF validation. A valid 'link' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Track#link_rel and XSPF::Track#link_content respectively. XSPF::Track objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one."
300
+ META_REL_RDOC = "The meta element allows non-XSPF metadata to be included in XSPF documents without breaking XSPF validation. A valid 'meta' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Track#meta_rel and XSPF::Track#meta_content respectively. XSPF::Track objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one."
301
+ META_CONTENT_RDOC = "The meta element allows non-XSPF metadata to be included in XSPF documents without breaking XSPF validation. A valid 'meta' element has a 'rel' attribute and a 'content' element, obtained with XSPF::Track#meta_rel and XSPF::Track#meta_content respectively. XSPF::Track objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one."
302
+
303
+ ELEMENTS.each do |element|
304
+ MetaGen.add_method( self, element, "@track.elements['#{element}'].text", eval(element.upcase + '_RDOC').to_s )
305
+ end
306
+
307
+ ATTRIBUTE_AND_ELEMENT.each do |ae|
308
+ MetaGen.add_method( self, "#{ae}_content", "@track.elements['#{ae}'].text", eval(ae.upcase + '_CONTENT_RDOC').to_s )
309
+ MetaGen.add_method( self, "#{ae}_rel", "@track.elements['#{ae}'].attributes['rel']", eval(ae.upcase + '_REL_RDOC').to_s )
310
+ end
311
+
312
+ # :startdoc:
313
+
314
+ # Creates a XSPF::Track object from a <track> section of the XSPF document
315
+ def initialize(tr)
316
+ @track = tr
317
+ end
318
+
319
+ end