Skip to content

Instantly share code, notes, and snippets.

@bertomartin
Created April 13, 2014 04:36
Show Gist options
  • Save bertomartin/10569381 to your computer and use it in GitHub Desktop.
Save bertomartin/10569381 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'tempfile'
require 'taglib'
if ARGV[0].nil?
$stderr.puts "Syntax: #{$0} <uri>"
exit 1
end
uri = URI(ARGV[0])
ext = uri.path.split('.').last
file = Tempfile.new(['foo', ".#{ext}"])
Net::HTTP.start(uri.host, uri.port) do |http|
req = Net::HTTP::Get.new uri
http.request(req) do |res|
res.read_body do |chunk|
file.write(chunk)
end
end
end
file.close
TagLib::FileRef.open(file.path, false) do |fileref|
if fileref.null?
puts "No tags found."
else
tag = fileref.tag
puts "Title: #{tag.title}"
puts "Artist: #{tag.artist}"
puts "Album: #{tag.album}"
puts "Year: #{tag.year}"
puts "Track: #{tag.track}"
puts "Genre: #{tag.genre}"
puts "Comment: #{tag.comment}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment