Skip to content

Instantly share code, notes, and snippets.

@dkordik
Created December 6, 2012 09:12
Show Gist options
  • Save dkordik/4223157 to your computer and use it in GitHub Desktop.
Save dkordik/4223157 to your computer and use it in GitHub Desktop.
Sniff network for iTunes Store updateNowPlaying requests via ngrep. Expand to do interesting things based on what you're playing.
require 'cgi'
match = 'track.updateNowPlaying'
ngrep_command = "ngrep -W byline '#{match}'"
puts "Watching network for iTunes Store now playing previews..."
IO.popen(ngrep_command).each do |line|
if line.match(/\=#{match}/)
nowplaying = CGI::parse(line)
puts
puts "Artist: #{nowplaying["artist"][0]}"
puts "Album: #{nowplaying["album"][0]}"
puts "Title: #{nowplaying["track"][0]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment