Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_relative "dependencies.rb"
- require 'active_support/core_ext'
- $started = false;
- $collection = []
- $artists = []
- $albums = []
- def getTrackInfoNumeric(line)
- inicio = line.index("<integer>") + 9
- fim = line.index("</i")
- line[inicio..fim].to_i
- end
- def getTrackInfo(line)
- inicio = line.index("<string>") + 8
- fim = line.index("</s") - 1
- line[inicio..fim]
- end
- def getLocation(arr)
- arr[0..arr.length-2].join("/") << "/"
- end
- def getFilename(arr)
- arr[arr.length-1]
- end
- def getCountry(arr)
- arr[arr.length-1].strip!
- end
- def getGrouping(arr)
- arr.each do |t|
- t.strip!
- end
- arr[0..arr.length-2].sort.join(", ")
- end
- def getTime(time)
- seconds = time / 1000
- Time.at(seconds).strftime("%M:%S")
- end
- def getTags(line)
- bkp = line.split(", ")
- retorno = Hash.new
- retorno[:acoustic] = false
- retorno[:another] = false
- retorno[:live] = false
- retorno[:cover] = false
- retorno[:medley] = false
- bkp.each do |t|
- retorno[:acoustic] = true if t == 'Acoustic'
- retorno[:another] = true if t == 'Another'
- retorno[:live] = true if t == 'Live'
- retorno[:cover] = true if t == 'Cover'
- retorno[:medley] = true if t == 'Medley'
- end
- retorno
- end
- File.open("Biblioteca.xml","r:UTF-8").each_line do |line|
- if line.include? "<key>Tracks</key>"
- $started = true;
- elsif not $started
- elsif line.include? "</dicta>"
- break
- elsif line.include? "<dict>"
- $current = Song.new
- elsif line.include? "<key>Year</key>"
- $current.year = getTrackInfoNumeric(line)
- elsif line.include? "<key>Name</key>"
- $current.title = getTrackInfo(line)
- elsif line.include? "<key>Artist</key>"
- $current.artist = getTrackInfo(line)
- elsif line.include? "<key>Album Artist</key>"
- $current.album_artist = getTrackInfo(line)
- elsif line.include? "<key>Album</key>"
- $current.album = getTrackInfo(line)
- elsif line.include? "<key>Total Time</key>"
- $current.time = getTime(getTrackInfoNumeric(line))
- elsif line.include? "<key>Track Number</key>"
- $current.track_number = getTrackInfoNumeric(line)
- elsif line.include? "<key>Track Count</key>"
- $current.track_count = getTrackInfoNumeric(line)
- elsif line.include? "<key>Location</key>"
- array = URI::decode(getTrackInfo(line)).split("/")
- $current.location = getLocation(array)
- $current.filename = getFilename(array)
- elsif line.include? "<key>Compilation</key>"
- $current.tags[:compilation] = true
- elsif line.include? "<key>Grouping</key>"
- array = getTrackInfo(line).split(",")
- $current.country = getCountry(array)
- $current.grouping = getGrouping(array)
- $current.tags = $current.tags.merge(getTags($current.grouping))
- elsif line.include? "<key>Genre</key>"
- $current.genre = getTrackInfo(line)
- elsif line.include? "<key>Size</key>"
- $current.size = getTrackInfoNumeric(line)
- elsif line.include? "<key>Bit Rate</key>"
- $current.bit_rate = getTrackInfoNumeric(line)
- elsif line.include? "<key>Sample Rate</key>"
- $current.sample_rate = getTrackInfoNumeric(line)
- elsif line.include? "<key>Comments</key>"
- $current.comments = getTrackInfo(line)
- elsif line.include? "<key>Composer</key>"
- $current.composer = getTrackInfo(line)
- elsif line.include? "</dict>"
- $collection << $current
- #break
- end
- end
- #$artists << Artist.new(true)
- $collection.each do |song|
- if song.artist == 'Helloween'
- artist = Artist.new(song)
- $artists << artist unless $artists.include? artist
- end
- end
- $collection.each do |song|
- if song.artist == 'Helloween'
- album = Album.new(song)
- puts album
- $albums << album unless $albums.include? album
- end
- end
- $collection.each do |song|
- if song.artist == 'Helloween'
- album = Album.new(song)
- track = Track.new(song)
- index = $albums.find_index(album)
- puts album.to_s
- puts track.to_s
- puts index.to_s
- $albums.at(index).trackList << track
- end
- end
- #File.open("artists.txt","w:UTF-8") do |f|
- # $artists.each do |a|
- # f.puts(a.to_json)
- # end
- #end
- File.open("albums.txt","w:UTF-8") do |f|
- f.puts($albums.to_json)
- # $albums.each do |a|
- # f.puts(a.to_json)
- # end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement