class Spfy
Constants
- USAGE
- VERSION
Public Class Methods
generate_xml()
click to toggle source
# File lib/spfy.rb, line 73 def self.generate_xml @tracks_processed = 0 if @options.output.any? puts "Generating XML..." capture_stdout end puts @xml_tags[:header] @options.dirs.each do |dir| catch :MaxTracksReached do begin Find.find(dir) do |path| xml_for_path(path) end rescue Interrupt abort("\nCancelled, exiting..") end end end puts @xml_tags[:footer] $stdout = STDOUT if @options.output.any? end
parse_args()
click to toggle source
# File lib/spfy.rb, line 54 def self.parse_args begin if ARGV.empty? then exit_with_banner end # parse command-line arguments @options = OptionReader.parse(ARGV) # test for zero source paths if @options.dirs.empty? exit_with_message("No source path(s) specified.") end rescue OptionParser::InvalidOption, OptionParser::MissingArgument => error exit_with_message(error.to_s.capitalize) end end
Private Class Methods
capture_stdout()
click to toggle source
# File lib/spfy.rb, line 148 def self.capture_stdout $stdout = File.open(@options.output[0], "w") end
exit_with_message(message)
click to toggle source
# File lib/spfy.rb, line 138 def self.exit_with_message(message) puts message if message exit_with_banner end
parse_location(path)
click to toggle source
# File lib/spfy.rb, line 117 def self.parse_location(path) if !@options.hide_location encoded_path = URI.escape(path).sub("%5C", "/") # percent encode string for local path puts "#{@xml_tags[:location_start]}#{encoded_path}#{@xml_tags[:location_end]}" end end
parse_tag(tag, suppress_output, start_xml, end_xml)
click to toggle source
# File lib/spfy.rb, line 124 def self.parse_tag(tag, suppress_output, start_xml, end_xml) if !tag.nil? and !suppress_output puts "#{start_xml}#{tag}#{end_xml}" end end
parse_track_num(track_num)
click to toggle source
# File lib/spfy.rb, line 130 def self.parse_track_num(track_num) if !@options.hide_tracknum and !track_num.nil? if track_num > 0 puts "#{@xml_tags[:track_num_start]}#{track_num}#{@xml_tags[:track_num_end]}" end end end
xml_for_path(path)
click to toggle source
# File lib/spfy.rb, line 98 def self.xml_for_path(path) TagLib::FileRef.open(path) do |fileref| tags = fileref.tag next if tags.nil? # skip files with no tags puts "#{@xml_tags[:track_start]}" parse_location(path) parse_tag(tags.title, @options.hide_title, @xml_tags[:title_start], @xml_tags[:title_end]) parse_tag(tags.artist, @options.hide_artist, @xml_tags[:artist_start], @xml_tags[:artist_end]) parse_tag(tags.album, @options.hide_album, @xml_tags[:album_start], @xml_tags[:album_end]) parse_track_num(tags.track) puts "#{@xml_tags[:track_end]}" @tracks_processed += 1 throw :MaxTracksReached if @options.tracks_to_process[0].to_i > 0 and @tracks_processed == @options.tracks_to_process[0].to_i end end