# vim: fileencoding=utf-8
require 'nkf'
-def encode(str)
- str && NKF.nkf('-Sw', str)
-end
+class Scrap
+ def match(line)
+ @md = @row_re.match(line)
+ end
+
+ def row
+ raise
+ end
-def encode_to_sjis(str)
- str && NKF.nkf('-Ws', str)
+ def encode(str)
+ str && NKF.nkf('-Sw', str)
+ end
+
+ def encode_to_sjis(str)
+ str && NKF.nkf('-Ws', str)
+ end
end
-class Scrap_mmd
+class Scrap_mmd < Scrap
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
- def match(line)
- @md = @row_re.match(line)
- end
-
def row
_, href, name, comment, size, date, mime, orig = @md.to_a
comment.sub!(@key_re, '')
end
end
-class Scrap_mmdfile
+class Scrap_mmdfile < Scrap
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, '')
end
end
-class Scrap_mmdacc1
+class Scrap_mmdacc1 < Scrap
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
+class Scrap_mmdacc2 < Scrap
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, '')
open(ent) do |f|
while line = f.gets
if scrap.match(line)
- name, comment, size, date, orig = scrap.row
- puts [ name, comment, size, date, orig ].join("\t")
+ puts scrap.row.join("\t")
end
end
end