--- /dev/null
+#!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
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'
#