-
Notifications
You must be signed in to change notification settings - Fork 3
/
BiliWeb.rb
91 lines (62 loc) · 1.49 KB
/
BiliWeb.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module BiliWeb
require 'open-uri'
require_relative 'BiliConfig'
$cachePath = File.join($configPath, 'cache')
Dir.mkdir($cachePath) unless Dir.exist?($cachePath)
class BiliParser
include BiliConfig
include BiliFile
def initialize(array=["http://bilibili.tv"])
@filename = {}
array.each do |url|
filename = $cachePath + "/" + url.gsub(/http:\/\//,"") + ".html"
@filename[filename] = url
end
@pool = Queue.new
@index = "bilibili.tv.html"
@indexfile = File.join($cachePath,@index)
get
end
def get
@filename.each do |array|
Thread.new {
content = open(array[1]).read
io = File.open(array[0], "w")
io.puts(content)
io.close
@pool << array[0]
}
end
clean
end
def clean
@filename.size.times do
Thread.new {
file = @pool.pop
if file.index(@index) then
biliMove(file,"line.index('/video/') && ! line.index('av271')")
else
p "[WARN] Don't know what to do!"
end
}
end
end
def parse
hash1 = {}
lev1 = @indexfile + ".l1"
biliMove(@indexfile,lev1,"line.index('i-link')")
# parse level 1 pair
open(lev1) do |f|
f.each_line do |line|
line.chomp!
key = line.gsub(/^.*<em>/,'').gsub(/<\/em.*$/,'')
value = line.gsub(/^.*href=\"/,'').gsub(/\"><em.*$/,'')
hash1[key] = value
end
end
return hash1
end
end
end
# Test code below
#Test.new("http://www.bilibili.com/video/av1718394/").get