From: Nathaniel Escribano Date: 2009-01-15T01:03:47+09:00 Subject: Re: Downloading an MP3 from the internet ------=_Part_252768_13962296.1231949083993 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Thank you guys very much! I was able to get it to work by fixing my path. I wasn't able to get it to work using alternate way even after changing the URL. I get the following error. syntax error, unexpected kDO, expecting $end do |src| Just out of curiosity- how can I fix this. I would like to know so that I can work through it and figure out exactly what the script is doing and compare it to the previous script. Thanks again! On Wed, Jan 14, 2009 at 4:30 AM, Brian Candler wrote: > Nathaniel Escribano wrote: > > require 'net/http' > > > > Net::HTTP.start("cdn.stereogum.com") { |http| > > resp = http.get("/mp3/My Morning Jacket - Celebration (Live).mp3") > > open("Celebration.mp3", "wb") { |file| > > file.write(resp.body) > > } > > } > > puts "the song has been downloaded" > > Here is an alternative way of doing it: > > require 'open-uri' > open("http://cdn.stereogum.com/mp3/My Morning Jacket - Celebration > (Live).mp3") do |src| > open("Celebration.mp3","wb") do |dst| > while blk = src.read(65536) > dst.write(blk) > end > end > end > > This gives a clear error: > > /usr/lib/ruby/1.8/uri/common.rb:436:in `split': bad URI(is not URI?): > http://cdn.stereogum.com/mp3/My Morning Jacket - Celebration (Live).mp3 > (URI::InvalidURIError) > > Fix the URI and it works: > > ... > open(" > http://cdn.stereogum.com/mp3/My%20Morning%20Jacket%20-%20Celebration%20%28Live%29.mp3 > ") > do |src| > ... > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_252768_13962296.1231949083993--