概述
danmu 是一个开源的直播平台弹幕接口
用python pip install danmu
# -*- coding: utf-8 -*-
import time, sys
from danmu import DanMuClient
import pymongo
client = pymongo.MongoClient(host='localhost', port=27017)
db = client['douyu']
coll = db['content']
def pp(msg):
print(msg.encode(sys.stdin.encoding, 'ignore').
decode(sys.stdin.encoding))
# https://www.douyu.com/***** 为斗鱼直播房间地址
dmc = DanMuClient('https://www.douyu.com/*****')
if not dmc.isValid(): print('Url not valid')
@dmc.danmu
def danmu_fn(msg):
content = {}
content[msg['NickName']] = msg['Content']
# content = '[%s] %s' % (msg['NickName'], msg['Content'])
# content = content.encode(sys.stdin.encoding, 'ignore').decode(sys.stdin.encoding)
# 保存到mongodb
coll.insert(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)
最后
以上就是超级月饼为你收集整理的斗鱼直播弹幕python_python利用danmu实时获取斗鱼等直播网站字幕的全部内容,希望文章能够帮你解决斗鱼直播弹幕python_python利用danmu实时获取斗鱼等直播网站字幕所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复