Skip to content

Instantly share code, notes, and snippets.

@seedifferently
Created December 23, 2011 00:31
Show Gist options
  • Save seedifferently/1512496 to your computer and use it in GitHub Desktop.
Save seedifferently/1512496 to your computer and use it in GitHub Desktop.
Read ID3 info over SSH via Ruby
require 'net/sftp'
require 'mp3info'
require 'stringio'
io = StringIO.new
Net::SFTP.start('host.com', 'username', :password => 'password', :port => 22) do |sftp|
f = sftp.file.open("/path/to/file.mp3", "r")
begin
# Read in 1024byte chunks
io << f.read(1024)
# Mp3Info.open will throw an error if it hasn't read enough data
id3 = Mp3Info.open(io)
break
rescue
# Rescue from the error and repeat the loop
next
end while io.size < 2097152 # Don't ever read more than 2MB of data
f.close()
puts id3.tag
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment