Skip to content

Instantly share code, notes, and snippets.

@sorah
Created February 9, 2012 17:07
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 sorah/1781204 to your computer and use it in GitHub Desktop.
Save sorah/1781204 to your computer and use it in GitHub Desktop.
for banshee... (public domain, own your risk)
# Converts UTF-8-MAC filenames in "iTunes Music Library.xml" to UTF-8
#
# Usage: ruby itunes_nfc.rb iTunes\ Music\ Library.xml > iTunes\ Music\ Library.xml
# License: public domain
#
# own your risk.
require'uri'
xml = ARGF.readlines
r = xml.map do |line|
next line unless /(\t*)<key>Location<\/key><string>(.*?)<\/string>(\r?\n)/ =~ line
t, oufn, ret = $1, $2, $3
ofn = URI.unescape(oufn)
cfn = ofn.force_encoding("UTF-8-MAC").encode("UTF-8")
cufn = URI.escape(cfn).gsub(/&%23/,'&#')
"#{t}<key>Location</key><string>#{cufn}</string>#{ret}"
end
puts r.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment