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

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

require 'xmms'

module Xmms
  class Remote
    #
    # get playlist contents as m3u-encoded string
    #
    def to_m3u
      "#EXTM3U\n" + playlist.map { |title, file, time| 
        "#EXTINF:#{time / 1000},#{title}\n#{file}"
      }.join("\n")
    end
  end
end

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

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