OSDN Git Service

link thumb to locked arc
authornomeu <nomeu@users.sourceforge.jp>
Sun, 27 Jun 2010 09:02:20 +0000 (18:02 +0900)
committernomeu <nomeu@users.sourceforge.jp>
Sun, 27 Jun 2010 09:02:20 +0000 (18:02 +0900)
bin/load-arc_thumbs.rb
lib/location.rb

index ceaa174..58e28a9 100644 (file)
@@ -6,6 +6,16 @@ require 'location'
 require 'arc'
 require 'thumb'
 require 'arc_thumb'
+
+def link(thumb, code)
+  arc = Arc.find_by_code(code)
+  unless arc
+    puts "not found arc.code: #{code}"
+    return
+  end
+  ArcThumb.find_or_create_by_arc_id_and_thumb_id(arc.id, thumb.id)
+end
+
 locations = Location.all
 thumbs = Thumb.all
 thumbs.each do |thumb|
@@ -15,13 +25,17 @@ thumbs.each do |thumb|
     if md = path_re.match(thumb.description)
       name = md[1]
       code, extname = location.generate_arc_code_and_extname(name)
-      puts [ thumb.video_id, location.code, code ].join("\t")
-      arc = Arc.find_by_code(code)
-      unless arc
-        puts "not found arc.code: #{code}"
-        next arc
-      end
-      ArcThumb.find_or_create_by_arc_id_and_thumb_id(arc.id, thumb.id)
+      puts [ thumb.video_id, "", code ].join("\t")
+      link(thumb, code)
+    end
+
+    next unless location.locked_path_pattern
+    locked_path_re = Regexp.new(Regexp.escape(location.site) + location.locked_path_pattern)
+    if md = locked_path_re.match(thumb.description)
+      name = md[1]
+      code = location.generate_locked_arc_code(name)
+      puts [ thumb.video_id, "locked", code ].join("\t")
+      link(thumb, code)
     end
   end
 end
index 15655a6..1d9952e 100644 (file)
@@ -1,6 +1,15 @@
 class Location < ActiveRecord::Base
   has_many :arcs
 
+  def locked_path_pattern
+    case self.code
+    when 'mmd'
+      "upload\\.cgi\\?mode=dl&file=(\\d+)"
+    when 'mmdfile'
+      "\\?mode=pass&idd=(\\d+)"
+    end
+  end
+
   def path_pattern
     case self.code
     when 'mmd'
@@ -14,6 +23,16 @@ class Location < ActiveRecord::Base
     end
   end
 
+  def generate_locked_arc_code(name)
+    case self.code
+    when 'mmd'
+      code = 'up%04d' % name.to_i
+    when 'mmdfile'
+      code = 'file%04d' % name.to_i
+    end
+    code
+  end
+
   def generate_arc_code_and_extname(name)
     if md = /\.(.+)\z/.match(name)
       extname = md[1]