From: Mariano Kamp Date: 2006-12-23T21:36:55+09:00 Subject: Re: Question: Downloading files with open(-uri)? --Apple-Mail-1--408356501 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Oops, forgot the output: RubyMate r5712 running Ruby v1.8.4 (/usr/local/bin/ruby) >>> download.rb downloading http://ibm.com opened connection. .done. downloading http://downloads.scribemedia.net/ rails2006/03_martin_fowler_full.m4v On Dec 23, 2006, at 1:35 PM, Mariano Kamp wrote: > Hi, > > I could need a quick hand here. > > I want to watch the RailsConf 2006 videos and want to download > them with a script. > > Unfortunately open("http:/xx") never comes back? Any idea what I > am doing wrong here? > > I tested it with an URL that returns plain html and that worked > fine. See the first line, ibm.com. > > require 'open-uri' > > urls = %w{ > http://ibm.com > http://downloads.scribemedia.net/rails2006/03_martin_fowler_full.m4v > http://downloads.scribemedia.net/rails2006/02_dave_thomas_full.m4v > http://downloads.scribemedia.net/rails2006/01_dh_hansson.m4v > http://downloads.scribemedia.net/rails2006/04_paul_graham_full.m4v > http://downloads.scribemedia.net/rails2006/06_railsCorePanel_full.m4v > http://downloads.scribemedia.net/rails2006/07_why_lucky_stiff.m4v > } > BUFFER_SIZE = 1_024*1_024*1 > > urls.each do |url| > puts "downloading #{url}" > open(url) do |input| > puts "opened connection." > output = open(url.split(/\//).last, "wb") > while (buffer = input.read(BUFFER_SIZE)) > print "." > $stdout.flush > output.write(buffer) > end > output.close > end > puts "done." > end > puts "All downloads done." > > Cheers, > Mariano > > > --Apple-Mail-1--408356501--