1
0
mirror of https://github.com/hanxi/xiaomusic.git synced 2025-12-06 14:52:50 +08:00

Compare commits

...

5 Commits

Author SHA1 Message Date
涵曦
f3658e0368 new version v0.1.63 2024-06-26 01:24:09 +00:00
涵曦
d28f4e1473 修复自动播放的问题 2024-06-26 01:18:58 +00:00
涵曦
1efdcf2144 修复自动播放的问题 2024-06-26 01:10:26 +00:00
涵曦
0f1516ae7e 优化日志输出 2024-06-26 00:22:23 +00:00
涵曦
f111d67819 优化不定长参数arg1的用法 2024-06-26 00:17:29 +00:00
4 changed files with 17 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
[project]
name = "xiaomusic"
version = "0.1.62"
version = "0.1.63"
description = "Play Music with xiaomi AI speaker"
authors = [
{name = "涵曦", email = "im.hanxi@gmail.com"},

View File

@@ -1 +1 @@
__version__ = "0.1.62"
__version__ = "0.1.63"

View File

@@ -192,7 +192,9 @@ async def get_web_music_duration(url, start=0, end=500):
async with aiohttp.ClientSession(timeout=timeout) as session:
duration = await _get_web_music_duration(session, url, start=0, end=500)
if duration <= 0:
duration = await _get_web_music_duration(session, url, start=0, end=1000)
duration = await _get_web_music_duration(
session, url, start=0, end=1000
)
except Exception:
pass
return duration

View File

@@ -108,7 +108,7 @@ class XiaoMusic:
# 启动时初始化获取声音
self.set_last_record("get_volume#")
self.log.debug("ffmpeg_location: %s", self.ffmpeg_location)
self.log.info("ffmpeg_location: %s", self.ffmpeg_location)
async def poll_latest_ask(self):
async with ClientSession() as session:
@@ -269,7 +269,9 @@ class XiaoMusic:
await self.mina_service.text_to_speech(self.device_id, value)
except Exception as e:
self.log.error(f"Execption {e}")
if self._playing:
self.log.debug(f"do_tts. cur_music:{self.cur_music}")
if self._playing and not self.is_downloading():
# 继续播放歌曲
await self.play()
@@ -322,7 +324,7 @@ class XiaoMusic:
if self.proxy:
sbp_args += ("--proxy", f"{self.proxy}")
self.log.debug(f"download: {sbp_args}")
self.log.info(f"download: {sbp_args}")
self.download_proc = await asyncio.create_subprocess_exec(*sbp_args)
await self.do_tts(f"正在下载歌曲{search_key}")
@@ -617,14 +619,13 @@ class XiaoMusic:
return True
else:
# 当前播放的歌曲不存在了
if self.is_music_exist(self.cur_music):
if not self.is_music_exist(self.cur_music):
return True
return False
# 播放歌曲
async def play(self, **kwargs):
self._playing = True
parts = kwargs["arg1"].split("|")
parts = kwargs.get("arg1", "").split("|")
search_key = parts[0]
name = parts[1] if len(parts) > 1 else search_key
if name == "":
@@ -637,7 +638,7 @@ class XiaoMusic:
else:
name = self.cur_music
self.log.debug("play. search_key:%s name:%s", search_key, name)
self.log.info("play. search_key:%s name:%s", search_key, name)
# 本地歌曲不存在时下载
if not self.is_music_exist(name):
@@ -647,6 +648,7 @@ class XiaoMusic:
# 把文件插入到播放列表里
self.add_download_music(name)
self._playing = True
self.cur_music = name
self.log.info("cur_music %s", self.cur_music)
url = self.get_music_url(name)
@@ -709,7 +711,7 @@ class XiaoMusic:
# 播放一个播放列表
async def play_music_list(self, **kwargs):
parts = kwargs["arg1"].split("|")
parts = kwargs.get("arg1").split("|")
list_name = parts[0]
if list_name not in self._music_list:
await self.do_tts(f"播放列表{list_name}不存在")
@@ -737,7 +739,7 @@ class XiaoMusic:
if self._stop_timer:
self._stop_timer.cancel()
self.log.info("关机定时器已取消")
minute = int(kwargs["arg1"])
minute = int(kwargs.get("arg1", 0))
async def _do_stop():
await asyncio.sleep(minute * 60)
@@ -750,7 +752,7 @@ class XiaoMusic:
self.log.info(f"{minute}分钟后将关机")
async def set_volume(self, **kwargs):
value = kwargs["arg1"]
value = kwargs.get("arg1", 0)
await self.do_set_volume(value)
async def get_volume(self, **kwargs):
@@ -841,8 +843,6 @@ class XiaoMusic:
# 获取所有设备
async def getalldevices(self, **kwargs):
arg1 = kwargs["arg1"]
self.log.debug("getalldevices. arg1:%s", arg1)
did_list = []
hardware_list = []
hardware_data = await self.mina_service.device_list()