Jun 02, 2021 Article blog
Danmu is an open source live platform pop-up interface that you can easily operate with no foundation.
With less than thirty lines of code, you can use Python for further development based on the bullet screen.
Support for fish fighting, pandas, battle flags, national, Bilibili multi-platform impeachment.
Support for all versions of Python, no platform dependency, convenient for all types of developers, enthusiasts to use.
Once on, the host on-line automatic connection, off-line automatically reconnect.
Deeply optimized, almost no one screen is missed, and abstract architecture is used for easy modification and development.
You can get help using it here.
Danmu can be installed via this command:
pip install danmu
With the following code, the bullet screen can be initially processed via Python.
import time, sys
from danmu import DanMuClient
def pp(msg): print(msg.encode(sys.stdin.encoding, 'ignore'). decode(sys.stdin.encoding))
dmc = DanMuClient('http://www.douyu.com/lslalala') if not dmc.isValid(): print('Url not valid')
@dmc.danmu def danmu_fn(msg): pp('[%s] %s' % (msg['NickName'], msg['Content']))
@dmc.gift def gift_fn(msg): pp('[%s] sent a gift!' % msg['NickName'])
@dmc.other def other_fn(msg): pp('Other message received')
dmc.start(blockThread = True)
Messages are registered in three types: danmu, gift, and other
Corresponds to: ordinary impeachment, gift message, other messages
If a type is not registered, the default method is used, as follows:
from danmu import DanMuClient
dmc = DanMuClient('http://www.douyu.com/lslalala')
@dmc.default def default_fn(msg): pp('[%s] %s' % (msg['NickName'], msg['Content']))
You can cancel a certain type of registration by doing the following.
from danmu import DanMuClient
dmc = DanMuClient('http://www.douyu.com/lslalala') dmc.default(None) dmc.gift(None)
Q: What are the message formats you get?
A: The message is a dictionary and must have three keys: NickName, Content, MsgType, corresponding to the user name, message content, and message type.
If you have any questions or suggestions, you can discuss them with me in this Issue
https://github.com/littlecodersh/danmu/#danmu