Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
add demo HTTP API
Browse files Browse the repository at this point in the history
  • Loading branch information
c-basalt committed Nov 9, 2022
1 parent c2aaee5 commit bc5bb8e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app.pyw
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import wx
import threading

from frame.main import MainFrame

from utils import local_api

if __name__ == '__main__':
app = wx.App()
frame = MainFrame()
threading.Thread(target=local_api.app.run, kwargs={"host": '127.0.0.1', "port": 8745}, daemon=True).start()
app.MainLoop()
11 changes: 10 additions & 1 deletion frame/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class MainFrame(wx.Frame):

LD_VERSION = "v1.5.3"
LD_VERSION = "v1.5.3 mod"

def __init__(self, parent=None):
"""B站直播同传/歌词弹幕发送工具"""
Expand All @@ -56,6 +56,7 @@ def __init__(self, parent=None):
pub.subscribe(self.SpreadDanmu,"ws_recv") # 消息:监听到同传弹幕
pub.subscribe(self.StartListening,"ws_start") # 消息:开始监听房间内的弹幕
pub.subscribe(self.SetSpreadButtonState,"ws_error") # 消息:监听过程中出现错误/恢复
pub.subscribe(self.HandleApi, 'api_control')
# API
self.blApi = BiliLiveAPI(self.cookies,(self.timeout_s,5)) # B站账号与直播相关接口
self.wyApi = NetEaseMusicAPI() # 网易云音乐接口
Expand Down Expand Up @@ -101,6 +102,7 @@ def __init__(self, parent=None):
# 其他参数
self.tmp_clipboard="" # 临时剪贴板内容
self.recent_danmu = {"_%d_"%i:0 for i in range(5)} # 近期发送的弹幕字典({弹幕内容:内容重复次数})
self.last_set_comment = None
self.danmu_queue = [] # 待发送弹幕队列
self.recent_history = [] # 评论框历史记录列表
self.tmp_history = [] # 评论框历史记录列表(临时)
Expand Down Expand Up @@ -1244,6 +1246,13 @@ def SendDanmu(self, roomid, msg, src:DanmuSrc, pre, max_len, try_times=2):
self.SendDanmu(roomid,pre+remain_msg,src,pre,max_len)
return succ_send

def HandleApi(self, command, payload):
if command == 'set_comment':
if payload['text'] != self.last_set_comment:
self.last_set_comment = payload['text']
text = re.sub(r'\s+', ' ', payload['text'])
self.tcComment.SetValue(text)

def SpreadDanmu(self,roomid,speaker,content):
"""转发同传弹幕"""
if self.sp_max_len is None:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ qrcode==7.3.1
requests==2.25.1
wxPython==4.1.1
websockets==10.2
flask
13 changes: 13 additions & 0 deletions utils/local_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import Flask, Response, request
from pubsub import pub

app = Flask(__name__)

@app.route('/')
def index():
return 'test'

@app.route('/control', methods=['POST'])
def control():
pub.sendMessage('api_control', command=request.json['command'], payload=request.json['payload'])
return 'recv'

0 comments on commit bc5bb8e

Please sign in to comment.