From: nomeu Date: Tue, 6 Sep 2011 17:10:55 +0000 (+0900) Subject: update save_arc X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=30723979edb492f98a69a9b3fbb02a3bdac436ff;hp=c35b00421ab0d8b9423be595c49be5a185d6e485;p=tdcgexplorer%2Fnimono-crawlers.git update save_arc --- diff --git a/bin/load-arcs-bowl.rb b/bin/load-arcs-bowl.rb index e24d87d..6c2fcdd 100644 --- a/bin/load-arcs-bowl.rb +++ b/bin/load-arcs-bowl.rb @@ -14,7 +14,9 @@ require 'bowl' site = Site.find('mmdbowl') Bowl.each_code_in_rss do |code| - bowl = Bowl.new(code) + number = /dl(\d+)\z/.match(code)[1].to_i + bowl_class = (number > 650) ? Bowl20110904 : Bowl + bowl = bowl_class.new(code) bowl.load next if bowl.removed? diff --git a/lib/bowl.rb b/lib/bowl.rb index 36ae3d0..41e3c85 100644 --- a/lib/bowl.rb +++ b/lib/bowl.rb @@ -172,4 +172,43 @@ class Bowl20110904 < Bowl def origname %r(

ファイル名 ï¼š (.+?)

).match(@source)[1] end + + def number + /dl(\d+)/.match(code)[1].to_i + end + + def request_header + header = {} + header["user-agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)" + header["accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + header["accept-language"] = "ja,en-us;q=0.7,en;q=0.3" + header["accept-charset"] = "Shift_JIS,utf-8;q=0.7,*;q=0.7" + header["referer"] = "http://bowlroll.net/up/#{code}" + # header["content-type"] = "multipart/form-data; boundary=#{boundary}" + header + end + + def request_body + "upDlVal=&upDlNum=#{number}" + end + + def save_arc_0 + http = Net::HTTP.new('bowlroll.net') + http.start do + request = Net::HTTP::Post.new('/Php/p3UpDlTop.php') + + request_header.each do |key, value| + request[key] = value + end + request.body = request_body + + http.request(request) do |response| + p response.code + p response['content-type'] + open(arc_path, 'wb') { |f| + response.read_body { |buf| f.write buf } + } + end + end + end end diff --git a/spec/bowl_spec.rb b/spec/bowl_spec.rb index f8bcba5..a77853a 100644 --- a/spec/bowl_spec.rb +++ b/spec/bowl_spec.rb @@ -21,6 +21,9 @@ describe 'Bowl20110904', 'arc dl671' do its "origname" do should == 'デリンジャー.zip' end + its "number" do + should == 671 + end end describe 'Bowl', 'arc dl140' do