Created
December 6, 2012 08:49
-
-
Save dkordik/4222925 to your computer and use it in GitHub Desktop.
Sniff network for iTunes #nowplaying mDNS announces via ngrep. Requires Ruby 1.9 for the awesome named-group regexes. Expand to do interesting things based on what you're playing.
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
match = 'nowplaying' | |
ngrep_command = "ngrep -W byline '#{match}' port 5353" | |
puts "Watching network for iTunes mDNS #nowplaying announces..." | |
IO.popen(ngrep_command).each do |line| | |
if line.match(/\##{match}/) | |
pattern = /nowplaying-title=(?<title>[\w ]+).+nowplaying-artist=(?<artist>[\w ]+).+nowplaying-album=(?<album>[\w ]+)/ | |
nowplaying = pattern.match(line) | |
puts | |
puts "Artist: #{nowplaying[:artist]}" | |
puts "Album: #{nowplaying[:album]}" | |
puts "Title: #{nowplaying[:title]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
true story