File: get_playlist.rb

package info (click to toggle)
libxmms-ruby 0.1.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 524 kB
  • ctags: 266
  • sloc: ansic: 687; ruby: 99; makefile: 44
file content (38 lines) | stat: -rwxr-xr-x 1,026 bytes parent folder | 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
#!/usr/bin/env ruby

########################################################################
# get_playlist.rb - create an XML playlist from the XMMS playlist      #
# by Paul Duncan <pabs@pablotron.org>                                  #
########################################################################

# load XMMS bindings
require 'xmms'

# create a new Xmms::Remote object
r = Xmms::Remote.new

# add String#xml_escape! (used below to escape values)
class String
  def xml_escape!
    gsub '&', '&amp;'
    gsub '<', '&lt;'
    gsub '>', '&gt;'
  end
end

# start the XML output 
puts '<?xml version="1.0" encoding="ISO-8859-1">',
     '<XmmsPlaylist>'

# step through each element in the playlist and print it's information
# in XML form
r.playlist do |title, file, time|
  puts '  <entry>',
       "    <title>#{title.xml_escape!}</title>",
       "    <filename>#{file.xml_escape!}</filename>",
       "    <duration>#{time}</duration>",
       '  </entry>',
end

# close the XML output
puts '</XmmsPlaylist>'