class Video
Attributes
aid[RW]
cid[RW]
commentURL[RW]
time[RW]
title[RW]
up[RW]
videos[RW]
Public Class Methods
av(aid = nil)
click to toggle source
# File lib/bilibili.rb, line 136 def Video.av(aid = nil) response = Net::HTTP.new(K_BILIBILI_API_MAIN_URL).get('/video/av' + aid.to_s + '/') video = Video.new video.videos = Array.new video.aid = aid response.body.each_line { |line| t = /<div class="v-title"><h1 title="(.*?)">/.match(line); if t != nil video.title = t[1] end t = /<i>(\d{4}-\d{2}-\d{2} \d{2}:\d{2})<\/i><\/time>/.match(line); if t != nil video.time = t[1] end t = /<div class="usname"><a class="name" href="http:\/\/space.bilibili.com\/(\d+)"/.match(line); if t != nil video.up = t[1] end t = /<script type='text\/javascript'>EmbedPlayer\('player', "http:\/\/static.hdslb.com\/play.swf", "cid=(\d+)(?:.*?)"/.match(line); if t != nil video.cid = t[1] video.commentURL = K_BILIBILI_COMMENT_HOST + video.cid + '.xml' end t = /<option value='(.*?)'>(.*?)<\/option>/.match(line); if t != nil sp = Hash.new sp['URL'] = 'http://www.bilibili.com' + t[1] sp['title'] = t[2] video.videos.push(sp) end } return video end
avToCID(aid)
click to toggle source
通过av号获取cid
# File lib/bilibili.rb, line 186 def Video.avToCID(aid) response = Net::HTTP.new(K_BILIBILI_API_MAIN_URL).get('/video/av' + aid.to_s + '/') response.body.each_line { |line| t = /<script type='text\/javascript'>EmbedPlayer\('player', "http:\/\/static.hdslb.com\/play.swf", "cid=(\d+)(?:.*?)"/.match(line); if t != nil return t[1] end } end
commentWithAID(aid)
click to toggle source
视频弹幕(aid)
# File lib/bilibili.rb, line 197 def Video.commentWithAID(aid) Video.commentWithCID(Video.avToCID(aid)) end
commentWithCID(cid)
click to toggle source
视频弹幕(cid)
# File lib/bilibili.rb, line 202 def Video.commentWithCID(cid) uri = URI(K_BILIBILI_COMMENT_HOST + cid.to_s + '.xml') req = Net::HTTP::Get.new(uri) req['Accept-Encoding'] = 'deflate' res = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(req) } comments = Array.new Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(res.body).split("\n").each do |line| t = /<d p="(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?)">(.*)<\/d>/.match(line) if t != nil comment = Hash.new comment['time'] = t[1] comment['mode'] = t[2] comment['fontsize'] = t[3] comment['fontcolor'] = t[4] comment['timestamp'] = t[5] comment['pool'] = t[6] comment['sender'] = t[7] comment['rowID'] = t[8] comment['content'] = t[9] comments.push(comment) end end comments end
downloadURLWithAID(aid, quality = 5)
click to toggle source
获取下载链接(aid)
# File lib/bilibili.rb, line 230 def Video.downloadURLWithAID(aid, quality = 5) Video.downloadURLWithCID(Video.avToCID(aid), quality) end
downloadURLWithCID(cid, quality = 5)
click to toggle source
获取下载链接(cid)
# File lib/bilibili.rb, line 235 def Video.downloadURLWithCID(cid, quality = 5) response = Net::HTTP.new(K_BILIBILI_API_INTERFACE_URL).get(K_BILIBILI_API_VIDEO_DOWNLOAD + quality.to_s + '&cid=' + cid.to_s) JSON.parse(response.body) end
Public Instance Methods
comment()
click to toggle source
视频弹幕
# File lib/bilibili.rb, line 241 def comment Video.commentWithCID(@cid) end
downloadURL(quality = 5)
click to toggle source
获取下载链接
# File lib/bilibili.rb, line 260 def downloadURL(quality = 5) Video.downloadURLWithCID(@cid, quality) end
refresh()
click to toggle source
刷新视频信息
# File lib/bilibili.rb, line 255 def refresh return Video.av(@aid) end