bilibili 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bilibili.rb +179 -19
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4cebd8c5cf3d83209ad7201b3132738e21bf595
|
4
|
+
data.tar.gz: e58b0b4103e0bdcf1df702d76d0ae46cde3f428c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29a5d1f108214424c2637f4e9c571c8970af5a5f01cb003701cb48b40a01ef0fdf9d7978f6acfb59a6e58fa1087d6c64c6bed1083a4c41517ec56d844dc9e8f4
|
7
|
+
data.tar.gz: 182d2f5f427ad6fccb5c2ab15d37cfbb474f2a2afc695e1117b9a60f7379f83f0ca3a9857cb1d3972a4fa85df00863ac382432f16fd906cf668253efecbfac02
|
data/lib/bilibili.rb
CHANGED
@@ -2,17 +2,27 @@
|
|
2
2
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
|
+
require 'zlib'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
K_BILIBILI_API_SPACE_URL = 'space.bilibili.com'
|
8
|
+
K_BILIBILI_API_SPACE_MEMBER_QUERY = '/ajax/member/GetInfo?mid='
|
9
|
+
K_BILIBILI_API_SPACE_FANS_QUERY = '/ajax/friend/GetFansList?mid='
|
10
|
+
K_BILIBILI_API_SPACE_COINVIDEO_QUERY = '/ajax/member/getCoinVideos?pagesize=100&mid='
|
11
|
+
K_BILIBILI_API_SPACE_SUBSCRIBE_QUERY = '/ajax/tags/getList?mid='
|
12
|
+
K_BILIBILI_API_SPACE_SUBSCRIBE_TAGS_QUERY = '/ajax/tags/getSubList?mid='
|
13
|
+
K_BILIBILI_API_SPACE_TAGS_QUERY = '/ajax/member/getTags?mids='
|
14
|
+
K_BILIBILI_API_SPACE_SUBMITVIDEOS = '/ajax/member/getSubmitVideos?mids='
|
15
|
+
K_BILIBILI_API_SPACE_ATTENTION_LIST = '/ajax/friend/GetAttentionList?mid='
|
16
|
+
K_BILIBILI_API_SPACE_BOX_LIST = '/ajax/fav/getBoxList?mid='
|
17
|
+
|
18
|
+
K_BILIBILI_API_MAIN_URL = 'www.bilibili.com'
|
19
|
+
K_BILIBILI_API_INDEX_BANGUMI = '/index/index-bangumi-timeline.json'
|
20
|
+
|
21
|
+
K_BILIBILI_API_URL = 'api.bilibili.com'
|
22
|
+
K_BILIBILI_API_VIDEO_SHARE = '/x/share/count?actionKey=appkey&appkey=27eb53fc9058f8c3&aid='
|
23
|
+
|
24
|
+
K_BILIBILI_COMMENT_HOST = 'http://comment.bilibili.com/'
|
25
|
+
K_BILIBILI_API_COMMENT_URL = 'comment.bilibili.com'
|
16
26
|
|
17
27
|
class Member
|
18
28
|
attr_accessor :mid # 用户id
|
@@ -70,47 +80,169 @@ class Member
|
|
70
80
|
|
71
81
|
# 投稿视频
|
72
82
|
def submitVideos(tid = 0)
|
73
|
-
response = Net::HTTP.new(
|
83
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_SUBMITVIDEOS + @mid + "&tid=" + tid.to_s)
|
74
84
|
JSON.parse(response.body)
|
75
85
|
end
|
76
86
|
|
77
87
|
# 我的收藏
|
78
88
|
def collectionList
|
79
|
-
response = Net::HTTP.new(
|
89
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_BOX_LIST + @mid)
|
80
90
|
JSON.parse(response.body)
|
81
91
|
end
|
82
92
|
|
83
93
|
# 订阅番剧
|
84
94
|
def subscribeList
|
85
|
-
response = Net::HTTP.new(
|
95
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_SUBSCRIBE_QUERY + @mid)
|
86
96
|
JSON.parse(response.body)
|
87
97
|
end
|
88
98
|
|
89
99
|
# 订阅标签
|
90
100
|
def subscribeTags
|
91
|
-
response = Net::HTTP.new(
|
101
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_SUBSCRIBE_TAGS_QUERY + @mid)
|
92
102
|
JSON.parse(response.body)
|
93
103
|
end
|
94
104
|
|
95
105
|
# 投过币的视频
|
96
106
|
def coinVideos
|
97
|
-
response = Net::HTTP.new(
|
107
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_COINVIDEO_QUERY + @mid)
|
98
108
|
JSON.parse(response.body)
|
99
109
|
end
|
100
110
|
|
101
111
|
# 关注列表
|
102
112
|
def attentionList
|
103
|
-
response = Net::HTTP.new(
|
113
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_ATTENTION_LIST + @mid)
|
104
114
|
JSON.parse(response.body)
|
105
115
|
end
|
106
116
|
|
107
117
|
# 粉丝
|
108
118
|
def fans
|
109
|
-
response = Net::HTTP.new(
|
119
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_FANS_QUERY + @mid)
|
110
120
|
JSON.parse(response.body)
|
111
121
|
end
|
112
122
|
end
|
113
123
|
|
124
|
+
class Video
|
125
|
+
attr_accessor :title # 视频标题
|
126
|
+
attr_accessor :time # 视频发布时间
|
127
|
+
attr_accessor :up # up主的用户id
|
128
|
+
attr_accessor :videos # 分p
|
129
|
+
attr_accessor :cid # 视频cid
|
130
|
+
attr_accessor :aid # 视频aid
|
131
|
+
attr_accessor :commentURL # 弹幕URL
|
132
|
+
|
133
|
+
def Video.av(aid = nil)
|
134
|
+
response = Net::HTTP.new(K_BILIBILI_API_MAIN_URL).get('/video/av' + aid.to_s + '/')
|
135
|
+
|
136
|
+
video = Video.new
|
137
|
+
video.videos = Array.new
|
138
|
+
video.aid = aid
|
139
|
+
|
140
|
+
response.body.each_line { |line|
|
141
|
+
t = /<div class="v-title"><h1 title="(.*?)">/.match(line);
|
142
|
+
if t != nil
|
143
|
+
video.title = t[1]
|
144
|
+
end
|
145
|
+
|
146
|
+
t = /<i>(\d{4}-\d{2}-\d{2} \d{2}:\d{2})<\/i><\/time>/.match(line);
|
147
|
+
if t != nil
|
148
|
+
video.time = t[1]
|
149
|
+
end
|
150
|
+
|
151
|
+
t = /<div class="usname"><a class="name" href="http:\/\/space.bilibili.com\/(\d+)"/.match(line);
|
152
|
+
if t != nil
|
153
|
+
video.up = t[1]
|
154
|
+
end
|
155
|
+
|
156
|
+
t = /<script type='text\/javascript'>EmbedPlayer\('player', "http:\/\/static.hdslb.com\/play.swf", "cid=(\d+)(?:.*?)"/.match(line);
|
157
|
+
if t != nil
|
158
|
+
video.cid = t[1]
|
159
|
+
video.commentURL = K_BILIBILI_COMMENT_HOST + video.cid + '.xml'
|
160
|
+
end
|
161
|
+
|
162
|
+
t = /<option value='(.*?)'>(.*?)<\/option>/.match(line);
|
163
|
+
if t != nil
|
164
|
+
sp = Hash.new
|
165
|
+
sp['URL'] = 'http://www.bilibili.com' + t[1]
|
166
|
+
sp['title'] = t[2]
|
167
|
+
video.videos.push(sp)
|
168
|
+
end
|
169
|
+
}
|
170
|
+
return video
|
171
|
+
end
|
172
|
+
|
173
|
+
# 视频分享量
|
174
|
+
def Video.shareCount(aid)
|
175
|
+
response = Net::HTTP.new(K_BILIBILI_API_URL).get(K_BILIBILI_API_VIDEO_SHARE + aid.to_s)
|
176
|
+
result = JSON.parse(response.body)
|
177
|
+
if result['code'] == 0
|
178
|
+
return result['data']
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# 通过av号获取cid
|
183
|
+
def Video.avToCID(aid)
|
184
|
+
response = Net::HTTP.new(K_BILIBILI_API_MAIN_URL).get('/video/av' + aid.to_s + '/')
|
185
|
+
response.body.each_line { |line|
|
186
|
+
t = /<script type='text\/javascript'>EmbedPlayer\('player', "http:\/\/static.hdslb.com\/play.swf", "cid=(\d+)(?:.*?)"/.match(line);
|
187
|
+
if t != nil
|
188
|
+
return t[1]
|
189
|
+
end
|
190
|
+
}
|
191
|
+
end
|
192
|
+
|
193
|
+
# 视频弹幕(aid)
|
194
|
+
def Video.commentWithAID(aid)
|
195
|
+
Video.commentWithCID(Video.avToCID(aid))
|
196
|
+
end
|
197
|
+
|
198
|
+
# 视频弹幕(cid)
|
199
|
+
def Video.commentWithCID(cid)
|
200
|
+
uri = URI(K_BILIBILI_COMMENT_HOST + cid.to_s + '.xml')
|
201
|
+
req = Net::HTTP::Get.new(uri)
|
202
|
+
req['Accept-Encoding'] = 'deflate'
|
203
|
+
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
|
204
|
+
http.request(req)
|
205
|
+
}
|
206
|
+
comments = Array.new
|
207
|
+
Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(res.body).split("\n").each do |line|
|
208
|
+
t = /<d p="(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?)">(.*)<\/d>/.match(line)
|
209
|
+
if t != nil
|
210
|
+
comment = Hash.new
|
211
|
+
comment['time'] = t[1]
|
212
|
+
comment['mode'] = t[2]
|
213
|
+
comment['fontsize'] = t[3]
|
214
|
+
comment['fontcolor'] = t[4]
|
215
|
+
comment['timestamp'] = t[5]
|
216
|
+
comment['pool'] = t[6]
|
217
|
+
comment['sender'] = t[7]
|
218
|
+
comment['rowID'] = t[8]
|
219
|
+
comment['content'] = t[9]
|
220
|
+
comments.push(comment)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
comments
|
224
|
+
end
|
225
|
+
|
226
|
+
# 视频弹幕
|
227
|
+
def comment
|
228
|
+
Video.commentWithCID(@cid)
|
229
|
+
end
|
230
|
+
|
231
|
+
# 视频分享量
|
232
|
+
def shareCount
|
233
|
+
response = Net::HTTP.new(K_BILIBILI_API_URL).get(K_BILIBILI_API_VIDEO_SHARE + @aid.to_s)
|
234
|
+
result = JSON.parse(response.body)
|
235
|
+
if result['code'] == 0
|
236
|
+
return result['data']
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# 刷新视频信息
|
241
|
+
def refresh
|
242
|
+
return Video.av(@aid)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
114
246
|
class Bilibili
|
115
247
|
def Bilibili.hi
|
116
248
|
puts '哔哩哔哩(‾▽‾)~■□~(‾▽‾)Ruby'
|
@@ -118,7 +250,35 @@ class Bilibili
|
|
118
250
|
|
119
251
|
# 通过uid获取用户
|
120
252
|
def Bilibili.member(mid)
|
121
|
-
|
122
|
-
|
253
|
+
if mid != nil
|
254
|
+
response = Net::HTTP.new(K_BILIBILI_API_SPACE_URL).get(K_BILIBILI_API_SPACE_MEMBER_QUERY + mid.to_s)
|
255
|
+
Member.member_with_JSON(JSON.parse(response.body))
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# 获取最近一周的番剧信息
|
260
|
+
def Bilibili.bangumi(day = nil)
|
261
|
+
if day != nil
|
262
|
+
day = day.to_i % 7
|
263
|
+
end
|
264
|
+
response = Net::HTTP.new(K_BILIBILI_API_MAIN_URL).get(K_BILIBILI_API_INDEX_BANGUMI)
|
265
|
+
bangumi = JSON.parse(response.body)['bangumi']['list']
|
266
|
+
if day == nil
|
267
|
+
return bangumi
|
268
|
+
end
|
269
|
+
result = Array.new
|
270
|
+
bangumi.each do |filter|
|
271
|
+
if filter['weekday'] == day
|
272
|
+
result.push(filter)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
return result
|
276
|
+
end
|
277
|
+
|
278
|
+
# 通过av号获取视频信息
|
279
|
+
def Bilibili.av(aid = nil)
|
280
|
+
if aid != nil
|
281
|
+
Video.av(aid)
|
282
|
+
end
|
123
283
|
end
|
124
284
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bilibili
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BlueCocoa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Collections of Bilibili API. 哔哩哔哩(‾▽‾)~■□~(‾▽‾)Ruby
|
13
|
+
description: "Collections of Bilibili API. 哔哩哔哩(‾▽‾)~■□~(‾▽‾)Ruby. \nDocs: https://blog.0xbbc.com/bilibili-ruby"
|
14
14
|
email: 0xbbc@0xbbc.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|