Git Product home page Git Product logo

danmu's Introduction

danmu

py2 py3 English Version

danmu 是一个开源的直播平台弹幕接口,使用他没什么基础的你也可以轻松的操作各平台弹幕。

使用不到三十行代码,你就可以使用Python基于弹幕进一步开发。

支持斗鱼、熊猫、战旗、全民、Bilibili多平台弹幕。

支持各版本Python,无平台依赖,方便各类开发者、爱好者使用。

一次开启,主播上线自动连接,下线后上线自动重连。

经过深度优化,几乎不漏过任何一条弹幕;使用抽象构架,方便修改与开发。

Documents

你可以在这里获取使用帮助。

Installation

可以通过本命令安装 danmu:

pip install danmu

Simple uses

通过如下代码,可以初步通过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!' % content['NickName'])

@dmc.other
def other_fn(msg):
    pp('Other message received')

dmc.start(blockThread = True)

Screenshot

screenshot

Advanced uses

设置默认的消息处理方式

消息被分为三种类型注册:danmu, gift, other

分别对应:普通弹幕,礼物消息,其他消息

如果某种类型没有注册过,将会使用默认方法,默认方法的注册方式如下:

from danmu import DanMuClient

dmc = DanMuClient('http://www.douyu.com/lslalala')

@dmc.default
def default_fn(msg):
    pp('[%s] %s' % (msg['NickName'], msg['Content']))

取消已经注册过的方法

通过以下方式可以取消某一种类型的注册。

from danmu import DanMuClient

dmc = DanMuClient('http://www.douyu.com/lslalala')
dmc.default(None)
dmc.gift(None)

FAQ

Q: 获取的消息格式都是什么?

A: 消息为一个字典,必有三个键:NickName、Content、MsgType,对应用户名、消息内容、消息类型。

Comments

如果有什么问题或者建议都可以在这个Issue和我讨论

或者也可以在gitter上交流:gitter

danmu's People

Contributors

littlecodersh avatar

Watchers

James Cloos avatar lUo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.