OSDN Git Service

41b4d44268d2b1032e85e3870792649953de527b
[tdcgexplorer/nimono-crawlers.git] / bin / read-upl.rb
1 #!ruby
2 # vim: fileencoding=utf-8
3 require 'nkf'
4
5 def encode(str)
6   str && NKF.nkf('-Sw', str)
7 end
8
9 def encode_to_sjis(str)
10   str && NKF.nkf('-Ws', str)
11 end
12
13 location = ARGV.shift || 'mmd'
14   ent = "/Volumes/uploader/src/#{location}/index.html"
15   f = open(ent)
16 case location
17 when 'mmd'
18   row_re = %r(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td></tr>)
19   key_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">[DLKey] </font>"))
20   password_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">*</font>"))
21
22   while line = f.gets
23     if md = row_re.match(line)
24       _, href, name, comment, size, date, mime, orig = md.to_a
25       comment.sub!(key_re, '')
26       comment.sub!(password_re, '')
27       puts [ name, comment, size, date, orig ].join("\t")
28     end
29   end
30 when 'mmdfile'
31   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>)
32   key_re = Regexp.new(Regexp.escape("<strong class=\"key\">[P]</strong> "))
33
34   while line = f.gets
35     if md = row_re.match(line)
36       _, href, name, comment, size, date, orig = md.to_a
37       comment.sub!(key_re, '')
38       puts [ name, comment, size, date, orig ].join("\t")
39     end
40   end
41 when 'mmdacc1'
42   row_re = %r(<td align=center>\[<a href='(.+?)' target='_new'>(.+?)</a>\]</td><td>(.+?)</td><td align=right>(.+?)</td><td align=center>(.+?)</td><td>(.+))
43
44   while line = f.gets
45     if md = row_re.match(line)
46       _, href, name, comment, size, date, orig = md.to_a
47       puts [ name, encode(comment), size, date, encode(orig) ].join("\t")
48     end
49   end
50 when 'mmdacc2'
51   row_re = %r(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td class="down_max">(.+?)</td></tr>)
52   key_re = Regexp.new(Regexp.escape(encode_to_sjis("<font color=\"#FF0000\">[パス設定] </font>")))
53
54   while line = f.gets
55     if md = row_re.match(line)
56       _, href, name, comment, size, date = md.to_a
57       comment.sub!(key_re, '')
58       puts [ name, encode(comment), size, encode(date) ].join("\t")
59     end
60   end
61 end
62   f.close