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(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td></tr>)
- key_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">[DLKey] </font>"))
- password_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">*</font>"))
+class Scrap_mmd
+ def initialize
+ @row_re = %r(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td></tr>)
+ @key_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">[DLKey] </font>"))
+ @password_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">*</font>"))
+ 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(<td>\[<a href="(.+?)" >(.+?)</a>\]</td><td>(.+?) <a href="(?:.+?)">(?:.+?)</a></td><td class="size">(.+?)</td><td class="date">(.+?)</td><td class="orig"><span class="orig">(.+?)</span></td>)
- key_re = Regexp.new(Regexp.escape("<strong class=\"key\">[P]</strong> "))
- 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(<td align=center>\[<a href='(.+?)' target='_new'>(.+?)</a>\]</td><td>(.+?)</td><td align=right>(.+?)</td><td align=center>(.+?)</td><td>(.+))
+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(<td>\[<a href="(.+?)" >(.+?)</a>\]</td><td>(.+?) <a href="(?:.+?)">(?:.+?)</a></td><td class="size">(.+?)</td><td class="date">(.+?)</td><td class="orig"><span class="orig">(.+?)</span></td>)
+ @key_re = Regexp.new(Regexp.escape("<strong class=\"key\">[P]</strong> "))
+ 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(<td align=center>\[<a href='(.+?)' target='_new'>(.+?)</a>\]</td><td>(.+?)</td><td align=right>(.+?)</td><td align=center>(.+?)</td><td>(.+))
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(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td class="down_max">(.+?)</td></tr>)
+ @key_re = Regexp.new(Regexp.escape(encode_to_sjis("<font color=\"#FF0000\">[パス設定] </font>")))
+ 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(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td class="down_max">(.+?)</td></tr>)
- key_re = Regexp.new(Regexp.escape(encode_to_sjis("<font color=\"#FF0000\">[パス設定] </font>")))
+ 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