diff --git a/plugins/setmyvolume.py b/plugins/setmyvolume.py deleted file mode 100644 index f722c32..0000000 --- a/plugins/setmyvolume.py +++ /dev/null @@ -1,5 +0,0 @@ -async def setmyvolume(arg1): - global log, xiaomusic - log.info(f"code1:{arg1}") - did = xiaomusic._cur_did - await xiaomusic.set_myvolume(did, arg1) diff --git a/pyproject.toml b/pyproject.toml index 8260fef..c5f04e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,6 @@ dependencies = [ "python-multipart>=0.0.12", "requests>=2.32.3", "sentry-sdk[fastapi]==1.45.1", - "python-socketio>=5.12.1", "pyjwt>=2.10.1", "fake-useragent>=2.2.0", "miservice-fork", diff --git a/xiaomusic/cli.py b/xiaomusic/cli.py index 7ddf4d7..dcddb66 100644 --- a/xiaomusic/cli.py +++ b/xiaomusic/cli.py @@ -40,7 +40,7 @@ def main(): from xiaomusic import __version__ from xiaomusic.config import Config from xiaomusic.httpserver import HttpInit - from xiaomusic.httpserver import socketio_app as HttpApp + from xiaomusic.httpserver import app as HttpApp from xiaomusic.xiaomusic import XiaoMusic parser = argparse.ArgumentParser() diff --git a/xiaomusic/httpserver.py b/xiaomusic/httpserver.py index 22dfb9a..0fd63e7 100644 --- a/xiaomusic/httpserver.py +++ b/xiaomusic/httpserver.py @@ -14,7 +14,6 @@ from typing import TYPE_CHECKING, Annotated from urllib.parse import urlparse import jwt -import socketio from fastapi import WebSocket, WebSocketDisconnect if TYPE_CHECKING: @@ -128,47 +127,6 @@ app = FastAPI( openapi_url=None, ) -# 创建Socket.IO实例 -sio = socketio.AsyncServer( - async_mode="asgi", - cors_allowed_origins="*", # 允许所有跨域请求,生产环境应限制 -) -# 将Socket.IO挂载到FastAPI应用 -socketio_app = socketio.ASGIApp( - socketio_server=sio, other_asgi_app=app, socketio_path="/socket.io" -) - - -# Socket.IO事件处理 -@sio.event -async def connect(sid, environ, auth): - global onlines - print(f"客户端连接: {sid}") - onlines.update([sid]) - await sio.emit("message", {"data": "欢迎连接"}, room=sid) - - -@sio.event -async def disconnect(sid): - print(f"客户端断开: {sid}") - onlines.discard(sid) - - -@sio.on("message") -async def custom_event(sid, data): - log.info(f"收到来自 {sid} 的数据: {data}") - await sio.emit("response", {"action": "切歌", "status": data}) - - -@app.post("/thdaction") -async def thdaction(item: Item): - await sio.emit( - "response", - {"action": item.action, "args": item.args, "status": item.args}, - ) - return onlines - - app.add_middleware( CORSMiddleware, allow_origins=["*"], # 允许访问的源 diff --git a/xiaomusic/static/3thdplay.mp3 b/xiaomusic/static/3thdplay.mp3 deleted file mode 100644 index fff4e2f..0000000 Binary files a/xiaomusic/static/3thdplay.mp3 and /dev/null differ diff --git a/xiaomusic/static/3thplay.html b/xiaomusic/static/3thplay.html deleted file mode 100644 index 8370a15..0000000 --- a/xiaomusic/static/3thplay.html +++ /dev/null @@ -1,499 +0,0 @@ - - - - - - - - Mini音乐播放器 - - - - - - -
- -
- 封面 -
- -
-

Let Go

-

Avril Lavigne

-
- -
-
-
- -
- 00:00 - 00:00 -
- -
-
-
-
-
-
- -
- - -
- -
- - - - - -
- - diff --git a/xiaomusic/utils.py b/xiaomusic/utils.py index eac9921..87c6e5e 100644 --- a/xiaomusic/utils.py +++ b/xiaomusic/utils.py @@ -240,27 +240,6 @@ def traverse_music_directory(directory, depth, exclude_dirs, support_extension): return result -# 发送给网页3thplay,用于三者设备播放 -async def thdplay( - action, args="/static/3thdplay.mp3", target="HTTP://192.168.1.10:58090/thdaction" -): - # 接口地址 target,在参数文件指定 - data = {"action": action, "args": args} - try: - async with aiohttp.ClientSession() as session: - async with session.post( - target, json=data, timeout=5 - ) as response: # 增加超时以避免长时间挂起 - # 如果响应不是200,引发异常 - response.raise_for_status() - # 读取响应文本 - text = await response.text() - return "[]" not in text - except Exception as e: - log.error(f"Error thdplay: {e}") - return False - - async def downloadfile(url): # 清理和验证URL # 解析URL diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py index 3be6112..c7998d2 100644 --- a/xiaomusic/xiaomusic.py +++ b/xiaomusic/xiaomusic.py @@ -67,7 +67,6 @@ from xiaomusic.utils import ( parse_str_to_dict, save_picture_by_base64, set_music_tag_to_file, - thdplay, traverse_music_directory, try_add_access_control_param, ) @@ -1972,33 +1971,12 @@ class XiaoMusic: async def get_volume(self, did="", **kwargs): return await self.devices[did].get_volume() - # 3thdplay.html 的音量设置消息发送 需要配置文件加入自定义指令 - # "user_key_word_dict": { - # "音量": "set_myvolume", - # "继续": "stop", - # "大点音": "exec#setmyvolume(\"up\")", - # "小点音": "exec#setmyvolume(\"down\")", - - async def set_myvolume(self, did="", arg1=0, **kwargs): - if did not in self.devices: - self.log.info(f"设备 did:{did} 不存在, 不能设置音量") - return - if arg1 == "up": - await thdplay("up", "", self.thdtarget) - - elif arg1 == "down": - await thdplay("down", "", self.thdtarget) - else: - volume = chinese_to_number(arg1) - await thdplay("volume", str(volume), self.thdtarget) - # 设置音量 async def set_volume(self, did="", arg1=0, **kwargs): if did not in self.devices: self.log.info(f"设备 did:{did} 不存在, 不能设置音量") return volume = int(arg1) - await thdplay("volume", str(volume), self.thdtarget) return await self.devices[did].set_volume(volume) # 搜索音乐 @@ -2386,23 +2364,19 @@ class XiaoMusicDevice: sec, url = await self.xiaomusic.get_music_sec_url(name, true_url) await self.group_force_stop_xiaoai() self.log.info(f"播放 {url}") - # 有3方设备打开 /static/3thplay.html 通过socketio连接返回true 忽律小爱音箱的播放 - online = await thdplay("play", url, self.xiaomusic.thdtarget) - self.log.info(f"IS online {online}") - if not online: - results = await self.group_player_play(url, name) - if all(ele is None for ele in results): - self.log.info(f"播放 {name} 失败. 失败次数: {self._play_failed_cnt}") - await asyncio.sleep(1) - if ( - self.isplaying() - and self._last_cmd != "stop" - and self._play_failed_cnt < 10 - ): - self._play_failed_cnt = self._play_failed_cnt + 1 - await self._play_next() - return + results = await self.group_player_play(url, name) + if all(ele is None for ele in results): + self.log.info(f"播放 {name} 失败. 失败次数: {self._play_failed_cnt}") + await asyncio.sleep(1) + if ( + self.isplaying() + and self._last_cmd != "stop" + and self._play_failed_cnt < 10 + ): + self._play_failed_cnt = self._play_failed_cnt + 1 + await self._play_next() + return # 重置播放失败次数 self._play_failed_cnt = 0 @@ -2788,7 +2762,6 @@ class XiaoMusicDevice: await self.do_tts(self.config.stop_tts_msg) await asyncio.sleep(3) # 等它说完 # 取消组内所有的下一首歌曲的定时器 - await thdplay("stop", "", self.xiaomusic.thdtarget) self.cancel_group_next_timer() await self.group_force_stop_xiaoai() self.log.info("stop now")