OSDN Git Service

update save_arc
authornomeu <nomeu@users.sourceforge.jp>
Tue, 6 Sep 2011 17:10:55 +0000 (02:10 +0900)
committernomeu <nomeu@users.sourceforge.jp>
Tue, 6 Sep 2011 17:10:55 +0000 (02:10 +0900)
bin/load-arcs-bowl.rb
lib/bowl.rb
spec/bowl_spec.rb

index e24d87d..6c2fcdd 100644 (file)
@@ -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?
 
index 36ae3d0..41e3c85 100644 (file)
@@ -172,4 +172,43 @@ class Bowl20110904 < Bowl
   def origname
     %r(<h3><b>ファイル名</b>&nbsp;:&nbsp;(.+?)</h3>).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
index f8bcba5..a77853a 100644 (file)
@@ -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