hi all,
Please could some on help me with a code to download an audio file in
ruby.
the code below does not work;;
url = "http://stream.esvmedia.org/mp3-play/hw/19023001-19023006.mp3"
res = Net::HTTP.get_response(URI.parse(url))
puts res.body
hi all,
Please could some on help me with a code to download an audio file in
ruby.
the code below does not work;;
url = "http://stream.esvmedia.org/mp3-play/hw/19023001-19023006.mp3"
res = Net::HTTP.get_response(URI.parse(url))
puts res.body
hi all,
Please could some on help me with a code to download an audio file in
ruby.
the code below does not work;;
Are you trying to stream a MP3 or are you trying to download it no
differently than any other binary format?
Andrew McElroy
On Wed, Jun 30, 2010 at 12:50 PM, kevid <alumsimportant@yahoo.ca> wrote:
url = "http://stream.esvmedia.org/mp3-play/hw/19023001-19023006.mp3"
res = Net::HTTP.get_response(URI.parse(url))
puts res.body
hi, tanks for your response.
I am trying to download it and save it locally. the file is in mp3
format.
Regards
Kevid
the console. Since it's all binary data, this is not very useful.
What you need to do is open a file and write the download contents to it.
One way to do this is:
require 'net/http'
url = "http://stream.esvmedia.org/mp3-play/hw/19023001-19023006.mp3"
res = Net::HTTP.get_response(URI.parse(url))
File.open('output.mp3','w') do |f|
f.write(res.body)
end
For more information on writing to files, see
http://ruby-doc.org/core/classes/File.html
-Jonathan Nielsen
On Thu, Jul 1, 2010 at 10:05 AM, kevid <alumsimportant@yahoo.ca> wrote:
I am trying to download it and save it locally. the file is in mp3
format.What your current code would do is print the contents of the mp3 file to
And this is probably a more useful tutorial on files in ruby:
http://www.tutorialspoint.com/ruby/ruby_input_output.htm
-Jonathan Nielsen
hi,
Thanks.
I just tried the code you gave me but I can't play the output file
(output.mp3)
i can't figure out why
kevid wrote:
hi,
Thanks.
I just tried the code you gave me but I can't play the output file
(output.mp3)i can't figure out why
Make sure you open the file with "wb" instead of "w" to use binary mode?
require 'net/http'
url = "http://stream.esvmedia.org/mp3-play/hw/19023001-19023006.mp3"
res = Net::HTTP.get_response(URI.parse(url))
File.open('out.mp3','wb') do |f|
f.print(res.body)
end
i tried the code above but did not get it work.
require 'open-uri'
File.open 'hannity_and_hitchens.mov' , 'wb' do |file|
file.print open('
onegoodmovemedia.org).read
end
On Thu, Jul 1, 2010 at 12:25 PM, kevid <alumsimportant@yahoo.ca> wrote:
require 'net/http'
url = "http://stream.esvmedia.org/mp3-play/hw/19023001-19023006.mp3"
res = Net::HTTP.get_response(URI.parse(url))
File.open('out.mp3','wb') do |f|
f.print(res.body)
endi tried the code above but did not get it work.
the url is redirected.
try change the url with http://audio.esvonline.org/hw/19023001-19023006.mp3
On Fri, Jul 2, 2010 at 12:25 AM, kevid <alumsimportant@yahoo.ca> wrote:
require 'net/http'
url = "http://stream.esvmedia.org/mp3-play/hw/19023001-19023006.mp3"
res = Net::HTTP.get_response(URI.parse(url))
File.open('out.mp3','wb') do |f|
f.print(res.body)
endi tried the code above but did not get it work.
Thanks bro,
I worked perfectly.