Last active
February 15, 2018 16:20
-
-
Save Mekajiki/e0e7e522df8b99ec301e to your computer and use it in GitHub Desktop.
fix "iTunes Music Library.xml" which has album ratings for non-rated tracks
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
#!/usr/bin/env ruby | |
out = File.open('/tmp/iTunes Music Library.xml', 'w') | |
in_path = 'iTunes/iTunes Music Library.xml' | |
regex_rating = /<key>Album Rating<\/key><integer>\d+<\/integer>/ | |
regex_rating_computed_true = /<key>Album Rating Computed<\/key><true\/>/ | |
regex_rating_computed_false = /<key>Album Rating Computed<\/key><false\/>/ | |
regex_last_line = /<\/plist>/ | |
rate_computed = " <key>Album Rating Computed</key><true/>\n" | |
line = File.open(in_path).each_cons(2) do |lines| | |
out << lines.first unless lines.first =~ regex_rating_computed_false | |
if regex_rating =~ lines.first && | |
regex_rating_computed_true !~ lines.last | |
out << rate_computed | |
end | |
out << lines.last if lines.last =~ regex_last_line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to apple, any changes to the file wont be reflected in iTunes. They say the xml is only a read-only copy.