Skip to content

Instantly share code, notes, and snippets.

@aurelian
Created July 2, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aurelian/1e6364e02333bebda0cd to your computer and use it in GitHub Desktop.
Save aurelian/1e6364e02333bebda0cd to your computer and use it in GitHub Desktop.
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