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
On Wed, Jun 30, 2010 at 12:50 PM, kevid [email protected] wrote:
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 Thu, Jul 1, 2010 at 10:05 AM, kevid [email protected] 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
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 N.
hi, tanks for your response.
I am trying to download it and save it locally. the file is in mp3
format.
Regards
Kevid
And this is probably a more useful tutorial on files in ruby:
-Jonathan N.
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
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.
On Thu, Jul 1, 2010 at 12:25 PM, kevid [email protected] wrote:
require ‘open-uri’
File.open ‘hannity_and_hitchens.mov’ , ‘wb’ do |file|
file.print open(’
onegoodmovemedia.org’).read
end
Thanks bro,
I worked perfectly.
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?
the url is redirected.
try change the url with
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs