vespa314 / bilibili-api Goto Github PK
View Code? Open in Web Editor NEWB站API收集整理及开发,不再维护
License: MIT License
B站API收集整理及开发,不再维护
License: MIT License
https://www.bilibili.com/read/cv5245087
作者是little_fish12345
投两个硬币能发送高级弹幕,有大量的可调参数,但如果想用高级弹幕进行字幕制作等创作活动的话,一条条调整参数发送会非常痛苦,还会有发送频率限制,希望能提供一个发送高级弹幕的api
很简单,在getURLContent函数里面加上cookie的header就行了,cookie可以从浏览器复制,也可以通过登录页面获取,貌似cookie有部分参数是不用的,不过这个我没深入研究。
NEW#所以为什么不改代码233333
路过
这里可以获取用户动态:http://api.bilibili.com/x/feed/pull?type=0&ps=5&pn=1
需要DedeUserID
和SESSDATA
的Cookie
,别的认证方式还不清楚
可以开jsonp:&jsonp=jsonp&callback=
(其实我想问的是,是否已阅是返回值的哪个)
文档里没看到这条,希望有帮助
获取开通直播状态
http://space.bilibili.com/ajax/live/getLive?
HasLiving(mid)
当前是否在直播
http://space.bilibili.com/ajax/live/getLive?
IsLiving(mid)
这两个API的URL一样?
如果是的话第二个好像不会返回第二层,会返回和第一个API一样的内容= =
是我打开方式不对吗
这里print function全部没有括号 有没有python3 version 的
python首先给我报了个错告诉我bilibili.py 184行的ver未定义然后看了看api.md…………漏改了代码?
于是去掉了GetComment()的ver=ver,嗯,能用了(why?)
随后发现最新的视频并不能抓到评论数据
不严格的二分法发现avid=3280075之后的评论不能直接抓取
举例
http://api.bilibili.cn/feedback?aid=3280082 ← {"totalResult":0,"pages":0}
http://api.bilibili.cn/feedback?aid=3280082&ver=3 ← ver=3后能返回数据
然后往后试了下其他avid
http://api.bilibili.cn/feedback?aid=4232083 ← No
http://api.bilibili.cn/feedback?aid=4232083&ver=3 ← Yes
再往前试了下
http://api.bilibili.cn/feedback?aid=2053 ← Yes
http://api.bilibili.cn/feedback?aid=2053&ver=3 ← Yes
看来世界需要ver=3 (:3」∠)
不知b站上传视频是靠哪些api
https://github.com/cnbeining/Biligrab/blob/master/biligrab.py#L265
然后跳到
https://github.com/cnbeining/Biligrab/blob/master/biligrab.py#L471
(是的,这个是Biligrab的本体。。。)
至于解析,
https://github.com/cnbeining/Biligrab/blob/master/biligrab.py#L157
我不厚道了。但是好使。
(如果你对于非API比较吃心,Flvxz有个漂亮的API。但是我觉得没有意义,就不弄了。)
这个适用于原始源是sina的,但是被二压备份的情况。可以保证更好的画质。
不知道原po还在不在,就是现在B站开始大面积测试使用基于DASH技术的播放器,可能会逐步取代旧版的FLV播放器,不知道PO能否对新版DASH播放器的地址做一次获取????
请问如何获取某直播分区所有直播间号?
本来以为是评论的多少问题,但是试了很少的评论好像也有问题诶。
报错信息:
请输入要拽取评论视频的av号
8037147
Traceback (most recent call last):
File "/Users/XieHong/Google Drive/Python/Bili_Com_Grab/spitcomments.py", line 212, in
allComment = GetAllComment(videoaid)
File "/Users/XieHong/Google Drive/Python/Bili_Com_Grab/spitcomments.py", line 202, in GetAllComment
while cl.comments[len(cl.comments) - 1].lv == None:
IndexError: list index out of range
源代码在这里:
SPIT_LV = True
SPIT_NAME = False
SPIT_MID = True
SPIT_MSG = True
"""
Created on Mon May 26 23:59:09 2014
@author: Vespa
"""
import urllib2
import urllib
import re
import json
import zlib
import gzip
import xml.dom.minidom
import hashlib
import time
import sys
import os
import codecs
import workerpool
class User():
def init(self,m_mid=None,m_name=None):
if m_mid:
self.mid = m_mid
if m_name:
if isinstance(m_name,unicode):
m_name = m_name.encode('utf8')
self.name = m_name
def GetSpace(self):
return 'http://space.bilibili.tv/'+str(self.mid)
mid = None
name = None
isApprove = None#是否是认证账号
spaceName = None
sex = None
rank = None
avatar = None
follow = None#关注好友数目
fans = None#粉丝数目
article = None#投稿数
place = None#所在地
description = None#认证用户为认证信息 普通用户为交友宣言
followlist = None#关注的好友列表
friend = None
DisplayRank = None
class Comment():
def init(self):
self.post_user = User()
lv = None#楼层
fbid = None#评论id
msg = None
ad_check = None#状态 (0: 正常 1: UP主隐藏 2: 管理员删除 3: 因举报删除)
post_user = None
class CommentList():
def init(self):
pass
comments = None
commentLen = None
page = None
class JsonInfo():
def init(self,url):
self.info = json.loads(getURLContent(url))
while self.info.has_key('code') and self.info['code'] != 0:
time.sleep(0.01)
self.info = json.loads(getURLContent(url))
print 'Entered!'
if self.info.has_key('message'):
print "【Error】code=%d, msg=%s, url=%s"%(self.info['code'],self.Getvalue('message'),url)
elif self.info.has_key('error'):
print "【Error】code=%d, msg=%s, url=%s"%(self.info['code'],self.Getvalue('error'),url)
error = True
error = False
def Getvalue(self,*keys):
if len(keys) == 0:
return None
if self.info.has_key(keys[0]):
temp = self.info[keys[0]]
else:
return None
if len(keys) > 1:
for key in keys[1:]:
if temp.has_key(key):
temp = temp[key]
else:
return None
if isinstance(temp,unicode):
temp = temp.encode('utf8')
return temp
info = None
error = False
def getURLContent(url):
while True:
flag = 1
try:
headers = {'User-Agent':'Mozilla/5.0 (Windows U Windows NT 6.1 en-US rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}
req = urllib2.Request(url = url,headers = headers)
content = urllib2.urlopen(req).read()
except:
flag = 0
if flag == 1:
break
return content
def GetString(t):
if type(t) == int:
return str(t)
return t
def GetComment(aid, page = None, pagesize = None, order = None):
"""
输入:
aid:AV号
page:页码
pagesize:单页返回的记录条数,最大不超过300,默认为10。
order:排序方式 默认按发布时间倒序 可选:good 按点赞人数排序 hot 按热门回复排序
返回:
评论列表
"""
url = 'http://api.bilibili.cn/feedback?aid='+GetString(aid)
if page:
url += '&page='+GetString(page)
if pagesize:
url += '&pagesize='+GetString(pagesize)
if order:
url += '&order='+GetString(order)
jsoninfo = JsonInfo(url)
commentList = CommentList()
commentList.comments = [Comment()] * pagesize
commentList.commentLen = jsoninfo.Getvalue('totalResult')
commentList.page = jsoninfo.Getvalue('pages')
idx = 0
while jsoninfo.Getvalue(str(idx)):
liuyan = Comment()
liuyan.lv = jsoninfo.Getvalue(str(idx),'lv')
liuyan.fbid = jsoninfo.Getvalue(str(idx),'fbid')
liuyan.msg = jsoninfo.Getvalue(str(idx),'msg')
liuyan.ad_check = jsoninfo.Getvalue(str(idx),'ad_check')
#liuyan.post_user = GetUserInfoBymid(jsoninfo.Getvalue(str(idx),'mid'))
liuyan.post_user.mid = jsoninfo.Getvalue(str(idx),'mid')
'''
liuyan.post_user.avatar = jsoninfo.Getvalue(str(idx),'face')
liuyan.post_user.rank = jsoninfo.Getvalue(str(idx),'rank')
liuyan.post_user.name = jsoninfo.Getvalue(str(idx),'nick')'''
commentList.comments[idx] = liuyan
idx += 1
return commentList
def GetAllComment(aid, order = None):
"""
获取一个视频全部评论,有可能需要多次爬取,所以会有较大耗时
输入:
aid:AV号
order:排序方式 默认按发布时间倒序 可选:good 按点赞人数排序 hot 按热门回复排序
返回:
评论列表
"""
MaxPageSize = 300
commentLists = [GetComment(aid = aid, page = 1, pagesize = MaxPageSize, order = order)]
totalPage = commentLists[0].page
directory = 'av' + str(aid) + 'Comments'
if not os.path.exists(directory):
os.makedirs(directory)
if totalPage > 1:
#urls = ['http://api.bilibili.cn/feedback?aid=' + str(aid) + '&page=' + str(p) + '&pagesize=' + str(MaxPageSize) for p in range(2, commentList.page + 1)]
# Make a pool
#pool = workerpool.WorkerPool(size = 10)
pool = workerpool.WorkerPool(size = totalPage - 1)
# Build our map
parameters
#saveto = [directory + '/' + str(x) for x in range(2, commentList.page + 1)]
# Perform the mapping
#pool.map(urllib.urlretrieve, urls, saveto)
commentLists2 = pool.map(GetComment, [aid] * (totalPage - 1), range(2, totalPage + 1), [MaxPageSize] * (totalPage - 1))
# Send shutdown jobs to all threads, and wait until all the jobs have been completed
pool.shutdown()
pool.wait()
for cl in commentLists2:
commentLists.append(cl)
'''
commentList.comments += [Comment()] * (commentList.page - 1)
for p in range(2, commentList.page + 1):
commentPath = directory + '/' + str(p)
commentList.comments[(p - 1) * MaxPageSize :] = GetCommentLocal(commentPath, MaxPageSize).comments
os.remove(commentPath)
os.rmdir(directory)
#经测试发现,如果视频评论涨幅过快(av2816940)
#那么JSON第一层的totalResult和pages可能不准
#即使每抓一页都重新读取totalResult也无济于事
while commentList.comments[len(commentList.comments) - 1].lv == None:
commentList.comments.pop()
commentList.commentLen = len(commentList.comments)'''
for cl in commentLists:
while cl.comments[len(cl.comments) - 1].lv == None:
cl.comments.pop()
commentLists = sorted(commentLists, key = GetCommentListKey, reverse = True)
return commentLists
def GetCommentListKey(commentList):
return commentList.comments[0].lv
if name == "main":
print u'请输入要拽取评论视频的av号'
videoaid = input()
commentTxt = codecs.open('av' + str(videoaid) + 'comments.txt', encoding = 'utf-8', mode = 'w')
allComment = GetAllComment(videoaid)
x = 0
#commentTxtList = [u''] * len(allComment.comments)
tempStrListSize = SPIT_LV + SPIT_NAME + SPIT_MID
for cl in allComment:
for aComment in cl.comments:
#while x < len(allComment.comments):
#aComment = allComment.comments[x]
tempStrList = [u''] * tempStrListSize
tempStr = u''
i = 0
if SPIT_LV:
tempStrList[i] = unicode(str(aComment.lv)) + u'楼'
i += 1
if SPIT_NAME:
tempStrList[i] = u'昵称: ' + unicode(str(aComment.post_user.name))
i += 1
if SPIT_MID:
tempStrList[i] = u'UID: ' + unicode(str(aComment.post_user.mid))
i += 1
y = 0
if tempStrListSize == 1:
tempStr += tempStrList[0] + u'\n'
if tempStrListSize > 1:
while y < tempStrListSize - 1:
tempStr += tempStrList[y] + u'\t'
y += 1
tempStr += tempStrList[y] + u'\n'
if SPIT_MSG:
tempStr += aComment.msg.decode('utf8')
tempStr += u'\n'
commentTxt.write(tempStr)
commentTxt.close()
如题。
最基本的能获取及发送弹幕即可。
感谢。
{
"code": -1
"error": "app is not exist."
}
Hi,
首先感谢作者做出如此出色的项目!
最近想把B站上的某部新番下到本地,刚好发现这个项目,貌似调用这个函数可以直接获取下载链接。
我试了下,确实成功了,下载链接是http://cn-zjcz7-dx.acgvideo.com/xxxx 这种形式的。现在有个小问题:我把链接直接复制到浏览器里下载是没有问题的,为什么在迅雷里下载会一直失败呢?我已经把迅雷设置为只从原始地址下载、单线程了啊。因为浏览器下载一直不太稳定,特来寻求帮助。
BR,
Drizzt
没装依赖库所以有的错误,直接给个依赖库清单呗
bilibili-vedio/:爬取B站所有视频信息【已完成,数据暂不公开】
//此处应为video
貌似 b 站姥爷知道了,修改了接口。
如下为报错提示。
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>D:\用户目录\Desktop\bilibiliUrlDownLoad.py http://www.bil
ibili.com/video/av4061686/
['appkey', 'id', 'page', 'type']
appkey=85eb6835b0a1034e&id=4061686&page=1&type=json&sign=64abb11c3ae20734d8d5f6e
c75ae85be
['appkey', 'cid', 'otype', 'quality', 'type']
appkey=85eb6835b0a1034e&cid=None&otype=json&quality=4&type=mp4&sign=ac49b3ee2239
625143ae70924121a357
Traceback (most recent call last):
File "D:\用户目录\Desktop\bilibiliUrlDownLoad.py", line 76, in <module>
media_urls = GetBilibiliUrl(sys.argv[1])
File "D:\用户目录\Desktop\bilibiliUrlDownLoad.py", line 41, in GetBilibiliUrl
resp_media = urlfetch(url_get_media+sign_1)
File "D:\用户目录\Desktop\bilibiliUrlDownLoad.py", line 70, in urlfetch
return urllib2.urlopen(req).read()
File "D:\Program Files\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "D:\Program Files\Python27\lib\urllib2.py", line 437, in open
response = meth(req, response)
File "D:\Program Files\Python27\lib\urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "D:\Program Files\Python27\lib\urllib2.py", line 475, in error
return self._call_chain(*args)
File "D:\Program Files\Python27\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "D:\Program Files\Python27\lib\urllib2.py", line 558, in http_error_defau
lt
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
C:\Users\Administrator>
我测试一下 报了404 想问一下 是不是要自己的key?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.