Skip to content

Instantly share code, notes, and snippets.

@todgru
Forked from eveevans/StreamSave.rb
Created February 12, 2013 05:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save todgru/4760525 to your computer and use it in GitHub Desktop.
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