Skip to content
No description or website provided.
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
danmaku.py
main.py

README.md

用于下载Bilibili的弹幕

我看过很多相似的代码,但都只能下载www.bilibili.com/video/avXXXXX的弹幕, 不能下载bangumi.bilibili.com/anime/XXXXXX下的弹幕,并且对于弹幕文件XXXX.xml中 的p属性中的参数没有进行解析,此项目就是为了解决这些问题。

Feature

  1. 下载bangumi.bilibili.com/anime/下的弹幕
  2. 下载www.bilibili.com/video/avXXXXX下的弹幕
  3. 解析弹幕文件,并赋予p属性中的参数意义

Document

  1. danmaku.py

有函数:danmaku, danmakuParser

danmaku负责下载弹幕xml文件,danmakuParser负责解析xml文件,使之便于阅读

Example

URL: https://www.bilibili.com/video/av13203221/

Code:

from danmaku import *
from pprint import pprint

url = "https://www.bilibili.com/video/av13203221/"
pprint(danmakuParser(danmaku(url)))

Output:

[{'color': '0xffffff',
  'danmuid': '3677664588',
  'date': '2017-08-10 21:23:50',
  'fontsize': 25,
  'msg': '陆上最强',
  'pool': '0',
  'time': 396.64898681641,
  'timestamp': 1502371430,
  'type': 1,
  'userid': '458b4187'},
 {'color': '0xffffff',
  'danmuid': '3677665426',
  'date': '2017-08-10 21:24:00',
  'fontsize': 25,
  'msg': '夹击妹抖',
  'pool': '0',
  'time': 442.30899047852,
  'timestamp': 1502371440,
  'type': 1,
  'userid': '5ca6b303'},
.....

关于弹幕xml文件的解释

文件结构如下

<i>
<chatserver>chat.bilibili.com</chatserver>
<chatid>21651589</chatid>
<mission>0</mission>
<maxlimit>1500</maxlimit>
<source>k-v</source>
%3Cd p="180.57899475098,1,25,16777215,1502371152,0,5ca6b303,3677640812">社长</d%3E
<d p="775.22601318359,1,25,0,1502371182,0,efc9d749,3677643202">好好好好!!!</d>
<d p="131.26400756836,1,25,16777215,1502371211,0,bd56ada8,3677645814">好的抱走临。。。(woc别拿小刀扎我</d>
<d p="645.63598632812,1,25,16777215,1502371239,0,d28087eb,3677648118">团长好魔性的笑声</d>

解释如下

<d p="time, type, fontsize, color, timestamp, pool??, userID, danmuID">
        0     1     2          3     4     5       6         7
type:
	1: up   scroll
	2: advantage danmu(not test yet)
	3: advantage danmu(not test yet)
	4: down static
	5: up   static

time-弹幕在视频中的播放时间
type-弹幕类型解释中有
fontsize-是个人就看得懂
color-十六进制的颜色信息转成十进制的值
timestamp-弹幕发送时的timestamp
pool-我也不知道,但发送弹幕的数据包post了这个值
userID-与在个人中心那的uid不同,但也是用户的唯一id danmuID-弹幕的唯一id,用于管理(撤回)弹幕

You can’t perform that action at this time.