Giter Site home page Giter Site logo

dy_danmu's Introduction

dy_danmu

A python library for fetching the chat data from the douyin livestream. Rewrote from douyin-live.

Install requirements

python 3.10 and above

(Recommanded) Set up a virtual environment

# set up the venv
python -m venv .venv

Activate the venv, one of the following:

# activate the venv

# linux and macos
.venv/Scripts/activate

# windows cmd
.venv/Scripts/activate.bat

# windows powershell
.venv/Scripts/Activate.ps1

pip install

pip install -r requirements.txt

Run the demo

You may want to edit the channel id and the cookies first.

python ./demo/main.py

Usage

import dy_danmu as DYDM

def OnChatMessage(data: DYDM.ChatMessage):
    print(f"User:\t{data.user.nick_name}")
    print(f"Msg:\t{data.content}")

cookies: str = "__ac_nonce=PutYourCookiesStringHere"
channelId: str = "1234567890"

myChannel = DYDM.Channel(channelId, cookies)
myChannel.OnChatMessage = OnChatMessage
myChannel.Connect()

Threading

from threading import Thread
import dy_danmu as DYDM

def OnChatMessage(data: DYDM.ChatMessage):
    print(f"Channel:\t{data.common.room_id}")
    print(f"User:\t{data.user.nick_name}")
    print(f"Msg:\t{data.content}")

cookies: str = "__ac_nonce=PutYourCookiesStringHere"
channelId1: str = "1234567890"
channelId2: str = "2345678901"

myChannel1 = DYDM.Channel(channelId1, cookies)
myChannel2 = DYDM.Channel(channelId2, cookies)
myChannel1.OnChatMessage = OnChatMessage
myChannel2.OnChatMessage = OnChatMessage

Thread(target=myChannel1.Connect).start()
Thread(target=myChannel2.Connect).start()

input("Press Enter to disconnect..")
myChannel1.Disconnect()
myChannel2.Disconnect()

Compile the Protocol Buffers

This project use python-betterproto to compile the proto file.

To compile the proto file, run the following commands.

# install the compiler
pip install "betterproto[compiler]"
# invoke protoc directly
protoc -I ./proto --python_betterproto_out=dy_danmu/lib dy.proto

# or invoke protoc via grpcio-tools
pip install grpcio-tools
python -m grpc_tools.protoc -I ./proto --python_betterproto_out=dy_danmu/lib douyin.proto

Contribute to the code

Feel free to make pull requests.

Credits

YunzhiYike/douyin-live for all the reverse engineering works and douyin.proto.

HaoDong108/DouyinBarrageGrab for some of the message classes in douyin.proto.

dy_danmu's People

Contributors

nats-ji 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.