Skip to content

Instantly share code, notes, and snippets.

@chrislloyd
Forked from lachie/gist:15694
Created October 9, 2008 05:07
Show Gist options
  • Save chrislloyd/15698 to your computer and use it in GitHub Desktop.
Save chrislloyd/15698 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Just splits up the queries into 20 tracks at a time, so I don't inundate the service, and so I can see what's happening.
# Its pretty slow on average.
# I'll need to parse the XML and reapply to the tags.
#
# get a MusicDNS key + genpuid & friends at http://www.musicip.com/
require 'rubygems'
require 'escape' # gem install escape
MUSICDNS_KEY = 'you have to sign up and get a key, blah. http://www.musicip.com/'
ITUNES_DIR = ENV['ITUNES_DIR'] || "#{ENV['HOME']}/Music/iTunes/iTunes Music"
$stdout.sync = false
open("#{ENV['HOME']}/tracksfound.xml",'w') do |f|
trx = []
Dir[File.join(ITUNES_DIR, '**/**/*.mp3')].each_with_index do |track, i|
trx << track
if i % 20 == 0
trx_cmd = Escape.shell_command(trx)
puts "asking mdns about #{trx_cmd}"
f.puts %x! genpuid #{MUSICDNS_KEY} -rmd=2 -r -xml #{trx_cmd}!
f.flush
trx = []
puts "OK MOAR!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment