From: nomeu Date: Sat, 12 Jun 2010 18:09:37 +0000 (+0900) Subject: refactored X-Git-Tag: 0.0.3~39 X-Git-Url: http://git.osdn.net/view?p=tdcgexplorer%2Fnimono-crawlers.git;a=commitdiff_plain;h=80eae87dd308aeff17a1fb5860ca946f4f4b8bee refactored --- diff --git a/bin/read-upl.rb b/bin/read-upl.rb index 41b4d44..c33370e 100644 --- a/bin/read-upl.rb +++ b/bin/read-upl.rb @@ -10,53 +10,93 @@ def encode_to_sjis(str) str && NKF.nkf('-Ws', str) end -location = ARGV.shift || 'mmd' - ent = "/Volumes/uploader/src/#{location}/index.html" - f = open(ent) -case location -when 'mmd' - row_re = %r((.+?)(.+?)(.+?)(.+?)(.+?)(.+?)) - key_re = Regexp.new(Regexp.escape("[DLKey] ")) - password_re = Regexp.new(Regexp.escape("*")) +class Scrap_mmd + def initialize + @row_re = %r((.+?)(.+?)(.+?)(.+?)(.+?)(.+?)) + @key_re = Regexp.new(Regexp.escape("[DLKey] ")) + @password_re = Regexp.new(Regexp.escape("*")) + end - while line = f.gets - if md = row_re.match(line) - _, href, name, comment, size, date, mime, orig = md.to_a - comment.sub!(key_re, '') - comment.sub!(password_re, '') - puts [ name, comment, size, date, orig ].join("\t") - end + def match(line) + @md = @row_re.match(line) end -when 'mmdfile' - row_re = %r(\[(.+?)\](.+?) (?:.+?)(.+?)(.+?)(.+?)) - key_re = Regexp.new(Regexp.escape("[P] ")) - while line = f.gets - if md = row_re.match(line) - _, href, name, comment, size, date, orig = md.to_a - comment.sub!(key_re, '') - puts [ name, comment, size, date, orig ].join("\t") - end + def row + _, href, name, comment, size, date, mime, orig = @md.to_a + comment.sub!(@key_re, '') + comment.sub!(@password_re, '') + [ name, comment, size, date, orig ] end -when 'mmdacc1' - row_re = %r(\[(.+?)\](.+?)(.+?)(.+?)(.+)) +end - while line = f.gets - if md = row_re.match(line) - _, href, name, comment, size, date, orig = md.to_a - puts [ name, encode(comment), size, date, encode(orig) ].join("\t") - end +class Scrap_mmdfile + def initialize + @row_re = %r(\[(.+?)\](.+?) (?:.+?)(.+?)(.+?)(.+?)) + @key_re = Regexp.new(Regexp.escape("[P] ")) + end + + def match(line) + @md = @row_re.match(line) + end + + def row + _, href, name, comment, size, date, orig = @md.to_a + comment.sub!(@key_re, '') + [ name, comment, size, date, orig ] + end +end + +class Scrap_mmdacc1 + def initialize + @row_re = %r(\[(.+?)\](.+?)(.+?)(.+?)(.+)) end + + def match(line) + @md = @row_re.match(line) + end + + def row + _, href, name, comment, size, date, orig = @md.to_a + [ name, encode(comment), size, date, encode(orig) ] + end +end + +class Scrap_mmdacc2 + def initialize + @row_re = %r((.+?)(.+?)(.+?)(.+?)(.+?)) + @key_re = Regexp.new(Regexp.escape(encode_to_sjis("[パス設定] "))) + end + + def match(line) + @md = @row_re.match(line) + end + + def row + _, href, name, comment, size, date = @md.to_a + comment.sub!(@key_re, '') + [ name, encode(comment), size, encode(date) ] + end +end + +location = ARGV.shift || 'mmd' + +case location +when 'mmd' + scrap = Scrap_mmd.new +when 'mmdfile' + scrap = Scrap_mmdfile.new +when 'mmdacc1' + scrap = Scrap_mmdacc1.new when 'mmdacc2' - row_re = %r((.+?)(.+?)(.+?)(.+?)(.+?)) - key_re = Regexp.new(Regexp.escape(encode_to_sjis("[パス設定] "))) + scrap = Scrap_mmdacc2.new +end +ent = "/Volumes/uploader/src/#{location}/index.html" +open(ent) do |f| while line = f.gets - if md = row_re.match(line) - _, href, name, comment, size, date = md.to_a - comment.sub!(key_re, '') - puts [ name, encode(comment), size, encode(date) ].join("\t") + if scrap.match(line) + name, comment, size, date, orig = scrap.row + puts [ name, comment, size, date, orig ].join("\t") end end end - f.close