Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'hpricot'
- require 'cgi'
- class Track
- attr_accessor :name
- attr_accessor :album
- attr_accessor :artist
- attr_accessor :location
- ITUNES_ROOT = %r[(.*iTunes2|.*iTunes Music)]
- XBOX_ROOT = 'smb://xbox:xbox@10.0.1.65/media/Audio/iTunes'
- def initialize(hpr_doc)
- parse_xml hpr_doc.to_s
- end
- def to_m3u(index)
- return nil unless location
- rtn = "#EXTINF:0,%02d. %s\n" % [ index, name ]
- rtn << remap_location
- rtn
- end
- private
- def parse_xml(xml)
- lines = xml.split(/\n/)
- lines.each do |line|
- case line
- when />Name</ then @name = get_string line
- when />Album</ then @album = get_string line
- when />Artist</ then @artist = get_string line
- when />Location</ then @location = get_string line
- end
- end
- end
- def get_string(xml_string)
- xml_string.match(/string>(.*)<.string/)[1]
- end
- def remap_location
- location.sub! ITUNES_ROOT, XBOX_ROOT
- CGI.unescape location
- end
- end
- doc = Hpricot File.read(ARGV[0])
- tracks = doc/"//dict/dict"
- puts '#EXTM3U'
- tracks.each_with_index do |track, i|
- t = Track.new(track)
- if line = t.to_m3u(i)
- puts line
- end
- end
Add Comment
Please, Sign In to add comment