Skip to content

Instantly share code, notes, and snippets.

@eveevans
Created May 10, 2012 23:06
Show Gist options
  • Save eveevans/2656475 to your computer and use it in GitHub Desktop.
Save eveevans/2656475 to your computer and use it in GitHub Desktop.
Ruby script for save mp3 stream
require 'rubygems'
require 'net/http'
require 'uri'
BIT_RATE = 48 #6kbxseg * 60 seg (a min) * 15min
TAMO_CORTE = (BIT_RATE/8) * 60 * 15 #en KB
url = URI.parse('http://186.1.15.253:8000/')
Net::HTTP.start(url.host, url.port) do |http|
nombre = Time.now.strftime("%Y-%m-%d-%H-%M-%S")
f = open("#{nombre}.mp3", "w")
begin
http.request_get('/lasandino.mp3') do |resp|
resp.read_body do |segment|
f.write(segment)
puts "#{File.size(f)/1024}Kb"
if ( (File.size(f)/1024) > TAMO_CORTE) then
f.close()
nombre = Time.now.strftime("%Y-%m-%d-%H-%M-%S")
f = open("#{nombre}.mp3", "w")
end
end
end
#ensure
# f.close()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment