Created
June 6, 2010 07:45
-
-
Save onodes/427406 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mechanize' | |
require 'pp' | |
require 'nkf' | |
require 'thread' | |
require 'hpricot' | |
q = Queue.new | |
WWW::Mechanize.html_parser = Hpricot | |
agent = WWW::Mechanize.new | |
agent.user_agent_alias = "iPhone" | |
page = agent.get("http://iphone.pinkape.net/amateur/index.html") | |
class Eget | |
def initialize(data) | |
@data = data | |
end | |
def get | |
Dir::mkdir(@data) | |
3.times{|n| | |
name = "http://pinkape.fam.cx/iphone/"+ @data +"_"+ (n+1).to_s + ".m4v" | |
success = system("wget " + name + " -P " + @data) | |
} | |
end | |
end | |
page.links.each{|link| | |
next if link.href.include?("index") | |
pp data = link.href.sub(".html","") | |
q.push(Eget.new(data)) | |
} | |
ary =[] | |
pp ary | |
3.times{|n| | |
ary[n] = Thread.new{ | |
while(!q.empty?) | |
instance = q.pop | |
instance.get | |
end | |
self.kill | |
} | |
} | |
ary.map{|thread| thread.join} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment