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|
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
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'
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]