File: pls.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 (30 lines) | stat: -rwxr-xr-x 833 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
#!/usr/bin/env ruby

########################################################################
# m3u.rb - save current XMMS playlist to PLS file.                     #
# by Paul Duncan <pabs@pablotron.org>                                  #
########################################################################

require 'xmms'

module Xmms
  class Remote
    #
    # get playlist contents as pls-encoded string
    #
    def to_pls
      pls = playlist
      ret = "[playlist]\nNumberOfEntries=#{pls.size}\n"
      pls.each_with_index { |ary, i| ret << "File#{i + 1}=#{ary[1]}\n" }
      ret
    end
  end
end

# connect to XMMS and get output filename
xmms = Xmms::Remote.new
path = ARGV[0] || 'playlist.pls'

# save playlist to pls file
puts "Saving playlist to \"#{path}\"."
File::open(path, 'w') { |out| out.puts xmms.to_pls }