Skip to main content

bilibili Python 弹幕机

Project description

biliLive

bilibili Python 弹幕机框架,使用代码快速塔建b站弹幕机,实现完全自定义

更新

v0.3.0

1,引入 websocket-client 库实现长连接,获取更多数据

2,事件 Event 添加更多事件,收到礼物,上舰,获取人气,粉丝数更新,热门榜等等...

v0.2.0

1,点歌模块 PlayCloudMusic, 点歌模块事件 MusicEvent

2, 将直播间事件分离出 Live 类 加入直播间事件 Event

3, 加入 LiveLog 一行设置输出统一格式 并将输出内容保存进文件 (同样支持自定义)

4,send_msg_loop 更名为 time_loop,sendMsgList 更名为 timeLoopList

安装

pip install biliLive

点歌模块播放使用 pydub 使用请安装依赖 ffmpeg,pyaudio

注意 pyaudio 必须去下面下载 然后使用 pip install pyaudio的下载路径 安装

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio

ffmpeg 这个估计都有 没有的话下载解压将 ffmpeg 目录下的 bin 文件夹加入环境变量

https://ffmpeg.org/download.html

简单使用

from biliLive import BiliApi, commandList, liveLog

"""
设置一个打印字符串到终端的指令 名为 /text
指令格式: /text 要打印的字符串
并每12秒发送弹幕 弹幕内容: "12s sendMsg"
保存日志到 ./log
"""

# 一行设置输出统一格式 并将输出内容保存进文件
liveLog()

# 默认请求头
headers = BiliApi.bilibili_headers
headers["cookie"] += "用户cookie"
api = BiliApi(headers)

# 指令方法 /text
def text(commKey, msg):
    # commKey 是后面空格的参数
    # 如/text xxx xxx xxx 后面的[xxx, xxx, xxx]
    # msg 当前执行该指令的弹幕
    print(f"打印字符串 -> {commKey[0]}")

# 实列化弹幕指令对像 commandList
MyCommandList = commandList()

# 绑定方法 /text
MyCommandList.command = {
    # 指令 /text
    "text": text
}

# 定时发送
MyCommandList.timeLoopList = {
    # 秒数: 要执行的
    # 为字符串时视为发送弹幕
    12: "12s sendMsg"
}

# 连接房间
live = api.live("房间号")
# 绑定指令对像到房间
live.bind(MyCommandList)

# 开启弹幕轮查
live.msg_loop()
# 开启定时发送
live.time_loop()
# 堵塞主线程
input("")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

biliLive-0.3.0.tar.gz (22.9 kB view details)

Uploaded Source

File details

Details for the file biliLive-0.3.0.tar.gz.

File metadata

  • Download URL: biliLive-0.3.0.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for biliLive-0.3.0.tar.gz
Algorithm Hash digest
SHA256 172784e41565b8bc9375dedd2af49374a9925fdc644958ac44a9a45f5dcab9db
MD5 0e3f12cca7f24e80d023f271af80552d
BLAKE2b-256 04e055f33a7893a03e9ca29a543a850cd7d66ff746c8ef360fe9288b2c92ef02

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page