Created
July 2, 2015 16:49
-
-
Save aurelian/1e6364e02333bebda0cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri-plist' | |
require 'pry' | |
olddoc = Nokogiri::PList(File.read("old.xml")) | |
newdoc = Nokogiri::PList(File.read("new.xml")) | |
oldtracks = olddoc["Tracks"].map{|id, track| track} | |
newdoc["Tracks"].each do | id, track | | |
print "-- #{track['Artist']} / #{track['Album']} -- #{track['Name']}" | |
found = oldtracks.find{ |e| | |
e["Artist"] && e["Album"] && | |
e["Artist"].downcase == track["Artist"].downcase && | |
e["Album"].downcase == track["Album"].downcase && | |
e["Name"].downcase == track["Name"].downcase && | |
e["Track Type"] == "File" && | |
!e["Play Count"].nil? | |
# e["Size"] == track["Size"] | |
} | |
if found.nil? | |
print " -- NOT FOUND>\n" | |
next | |
else | |
print " -- [OK]\n" | |
end | |
if track['Play Count'].nil? | |
track['Play Date'] = found['Play Date'] | |
track['Play Date UTC'] = found['Play Date UTC'] | |
track['Play Count'] = found['Play Count'] | |
else | |
track['Play Count'] += found['Play Count'].to_i | |
end | |
track['Rating'] = found['Rating'] if found['Rating'] | |
#puts track.to_plist_xml | |
end | |
File.open("foo.xml", "w") { |f| f << newdoc.to_plist_xml } | |
#binding.pry | |
#newdoc.xpath("//plist/dict/dict").each do | k | | |
# binding.pry | |
#end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment