Skip to content

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

License

Notifications You must be signed in to change notification settings

Nats-ji/dy_danmu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages