OSDN Git Service

added
authornomeu <nomeu@nomeu.org>
Mon, 14 Jun 2010 15:08:06 +0000 (00:08 +0900)
committernomeu <nomeu@nomeu.org>
Mon, 14 Jun 2010 15:08:06 +0000 (00:08 +0900)
bin/load-arc_thumbs.rb [new file with mode: 0644]
lib/arc_thumb.rb [new file with mode: 0644]
lib/location.rb

diff --git a/bin/load-arc_thumbs.rb b/bin/load-arc_thumbs.rb
new file mode 100644 (file)
index 0000000..2457ce4
--- /dev/null
@@ -0,0 +1,27 @@
+#!ruby
+# vim: fileencoding=utf-8
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'connection'
+require 'location'
+require 'arc'
+require 'thumb'
+require 'arc_thumb'
+locations = Location.all
+thumbs = Thumb.all
+thumbs.each do |thumb|
+  # puts "# #{thumb.video_id}"
+  locations.each do |location|
+    path_re = Regexp.new(Regexp.escape(location.site) + location.path_pattern)
+    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)
+    end
+  end
+end
diff --git a/lib/arc_thumb.rb b/lib/arc_thumb.rb
new file mode 100644 (file)
index 0000000..308385c
--- /dev/null
@@ -0,0 +1,4 @@
+class ArcThumb < ActiveRecord::Base
+  belongs_to :arc
+  belongs_to :thumb
+end
index eda840e..22c6089 100644 (file)
@@ -1,10 +1,27 @@
 class Location < ActiveRecord::Base
   has_many :arcs
 
+  def path_pattern
+    case self.code
+    when 'mmd'
+      "src/(\\w+)"
+    when 'mmdfile'
+      "\\?id=(\\d+)"
+    when 'mmdacc1'
+      "log/(\\w+)"
+    when 'mmdacc2'
+      "src/(\\w+)"
+    end
+  end
+
   def generate_arc_code_and_extname(name)
-    md = /\.(.+)\z/.match(name)
-    extname = md[1]
-    code = File.basename(name, '.' + extname)
+    if md = /\.(.+)\z/.match(name)
+      extname = md[1]
+      code = File.basename(name, '.' + extname)
+    else
+      extname = nil
+      code = name.dup
+    end
     case self.code
     when 'mmd'
       #