#!/usr/bin/env ruby # == Flikr Downloader # # flikr_downloader # # Download the set of photos from a specified Flikr page # This currently has very little error checking so be careful # # No file existance checking is done, each download starts at image_1.jpg and counts up # any existing images will be overwritten # # == Usage # # flikr_download.rb URL # # URL: The page of images to download # # Author:: Robin Wood (dninja@gmail.com) # Copyright:: Copyright (c) Robin Wood 2009 # Licence:: GPL # require 'net/http' url=ARGV.shift if url =~ /http:\/\/([^\/]*)(\/.*)/ base=$1 page=$2 else puts "Couldn't parse the url\n" exit end image_number = 1 Net::HTTP.start(base) { |http| resp=http.get(url) #puts resp resp.body.each { |line| if line =~ /.*src="http:\/\/([^\/]*)(.*)_m\.jpg.*/ #o.puts("wget "+$1+".jpg") img_base=$1 img_page=$2+".jpg" output_file="image_"+image_number.to_s()+".jpg" puts "Getting "+img_base+img_page+" to "+output_file Net::HTTP.start(img_base) { |img_http| img_resp=img_http.get(img_page) open(output_file, "wb") { |file| file.write(img_resp.body) } } image_number+=1 end } }