feat: 设置播放类型支持配置语音提示词,定时任务支持设置播放类型
This commit is contained in:
parent
ca2ddcd89c
commit
0bc4bc8b13
@ -6,6 +6,11 @@ import os
|
|||||||
from dataclasses import asdict, dataclass, field
|
from dataclasses import asdict, dataclass, field
|
||||||
from typing import get_type_hints
|
from typing import get_type_hints
|
||||||
|
|
||||||
|
from xiaomusic.const import (
|
||||||
|
PLAY_TYPE_ALL,
|
||||||
|
PLAY_TYPE_ONE,
|
||||||
|
PLAY_TYPE_RND,
|
||||||
|
)
|
||||||
from xiaomusic.utils import validate_proxy
|
from xiaomusic.utils import validate_proxy
|
||||||
|
|
||||||
|
|
||||||
@ -161,6 +166,15 @@ class Config:
|
|||||||
get_ask_by_mina: bool = (
|
get_ask_by_mina: bool = (
|
||||||
os.getenv("XIAOMUSIC_GET_ASK_BY_MINA", "false").lower() == "true"
|
os.getenv("XIAOMUSIC_GET_ASK_BY_MINA", "false").lower() == "true"
|
||||||
)
|
)
|
||||||
|
play_type_one_tts_msg: str = os.getenv(
|
||||||
|
"XIAOMUSIC_PLAY_TYPE_ONE_TTS_MSG", "已经设置为单曲循环"
|
||||||
|
)
|
||||||
|
play_type_all_tts_msg: str = os.getenv(
|
||||||
|
"XIAOMUSIC_PLAY_TYPE_ALL_TTS_MSG", "已经设置为全部循环"
|
||||||
|
)
|
||||||
|
play_type_rnd_tts_msg: str = os.getenv(
|
||||||
|
"XIAOMUSIC_PLAY_TYPE_RND_TTS_MSG", "已经设置为随机播放"
|
||||||
|
)
|
||||||
|
|
||||||
def append_keyword(self, keys, action):
|
def append_keyword(self, keys, action):
|
||||||
for key in keys.split(","):
|
for key in keys.split(","):
|
||||||
@ -280,3 +294,12 @@ class Config:
|
|||||||
os.makedirs(self.conf_path)
|
os.makedirs(self.conf_path)
|
||||||
cookies_path = os.path.join(self.conf_path, "yt-dlp-cookie.txt")
|
cookies_path = os.path.join(self.conf_path, "yt-dlp-cookie.txt")
|
||||||
return cookies_path
|
return cookies_path
|
||||||
|
|
||||||
|
def get_play_type_tts(self, play_type):
|
||||||
|
if play_type == PLAY_TYPE_ONE:
|
||||||
|
return self.play_type_one_tts_msg
|
||||||
|
if play_type == PLAY_TYPE_ALL:
|
||||||
|
return self.play_type_all_tts_msg
|
||||||
|
if play_type == PLAY_TYPE_RND:
|
||||||
|
return self.play_type_rnd_tts_msg
|
||||||
|
return ""
|
||||||
|
@ -14,12 +14,6 @@ PLAY_TYPE_ONE = 0 # 单曲循环
|
|||||||
PLAY_TYPE_ALL = 1 # 全部循环
|
PLAY_TYPE_ALL = 1 # 全部循环
|
||||||
PLAY_TYPE_RND = 2 # 随机播放
|
PLAY_TYPE_RND = 2 # 随机播放
|
||||||
|
|
||||||
PLAY_TYPE_TTS = {
|
|
||||||
PLAY_TYPE_ONE: "已经设置为单曲循环",
|
|
||||||
PLAY_TYPE_ALL: "已经设置为全部循环",
|
|
||||||
PLAY_TYPE_RND: "已经设置为随机播放",
|
|
||||||
}
|
|
||||||
|
|
||||||
# 需要采用 mina 获取对话记录的设备型号
|
# 需要采用 mina 获取对话记录的设备型号
|
||||||
GET_ASK_BY_MINA = {
|
GET_ASK_BY_MINA = {
|
||||||
"M01",
|
"M01",
|
||||||
|
@ -63,6 +63,14 @@ class Crontab:
|
|||||||
|
|
||||||
self.add_job(expression, job)
|
self.add_job(expression, job)
|
||||||
|
|
||||||
|
# 设置播放类型任务
|
||||||
|
def add_job_set_play_type(self, expression, xiaomusic, did, arg1, **kwargs):
|
||||||
|
async def job():
|
||||||
|
play_type = int(arg1)
|
||||||
|
await xiaomusic.set_play_type(did, play_type, False)
|
||||||
|
|
||||||
|
self.add_job(expression, job)
|
||||||
|
|
||||||
def add_job_cron(self, xiaomusic, cron):
|
def add_job_cron(self, xiaomusic, cron):
|
||||||
expression = cron["expression"] # cron 计划格式
|
expression = cron["expression"] # cron 计划格式
|
||||||
name = cron["name"] # stop, play, play_music_list, tts
|
name = cron["name"] # stop, play, play_music_list, tts
|
||||||
|
@ -170,6 +170,13 @@ var vConsole = new window.VConsole();
|
|||||||
|
|
||||||
<label for="stop_tts_msg">停止提示音:</label>
|
<label for="stop_tts_msg">停止提示音:</label>
|
||||||
<input id="stop_tts_msg" type="text" value="收到,再见"></input>
|
<input id="stop_tts_msg" type="text" value="收到,再见"></input>
|
||||||
|
<label for="play_type_one_tts_msg">单曲循环提示音:</label>
|
||||||
|
<input id="play_type_one_tts_msg" type="text" value="已经设置为单曲循环"></input>
|
||||||
|
<label for="play_type_all_tts_msg">全部循环提示音:</label>
|
||||||
|
<input id="play_type_all_tts_msg" type="text" value="已经设置为全部循环"></input>
|
||||||
|
<label for="play_type_rnd_tts_msg">随机播放提示音:</label>
|
||||||
|
<input id="play_type_rnd_tts_msg" type="text" value="已经设置为随机播放"></input>
|
||||||
|
|
||||||
<label for="keywords_playlocal">播放本地歌曲口令:</label>
|
<label for="keywords_playlocal">播放本地歌曲口令:</label>
|
||||||
<input id="keywords_playlocal" type="text" value="播放本地歌曲,本地播放歌曲"></input>
|
<input id="keywords_playlocal" type="text" value="播放本地歌曲,本地播放歌曲"></input>
|
||||||
<label for="keywords_play">播放歌曲口令:</label>
|
<label for="keywords_play">播放歌曲口令:</label>
|
||||||
|
@ -31,7 +31,6 @@ from xiaomusic.const import (
|
|||||||
PLAY_TYPE_ALL,
|
PLAY_TYPE_ALL,
|
||||||
PLAY_TYPE_ONE,
|
PLAY_TYPE_ONE,
|
||||||
PLAY_TYPE_RND,
|
PLAY_TYPE_RND,
|
||||||
PLAY_TYPE_TTS,
|
|
||||||
SUPPORT_MUSIC_TYPE,
|
SUPPORT_MUSIC_TYPE,
|
||||||
)
|
)
|
||||||
from xiaomusic.crontab import Crontab
|
from xiaomusic.crontab import Crontab
|
||||||
@ -885,15 +884,18 @@ class XiaoMusic:
|
|||||||
|
|
||||||
# 设置为单曲循环
|
# 设置为单曲循环
|
||||||
async def set_play_type_one(self, did="", **kwargs):
|
async def set_play_type_one(self, did="", **kwargs):
|
||||||
await self.devices[did].set_play_type(PLAY_TYPE_ONE)
|
await self.set_play_type(did, PLAY_TYPE_ONE)
|
||||||
|
|
||||||
# 设置为全部循环
|
# 设置为全部循环
|
||||||
async def set_play_type_all(self, did="", **kwargs):
|
async def set_play_type_all(self, did="", **kwargs):
|
||||||
await self.devices[did].set_play_type(PLAY_TYPE_ALL)
|
await self.set_play_type(did, PLAY_TYPE_ALL)
|
||||||
|
|
||||||
# 设置为随机播放
|
# 设置为随机播放
|
||||||
async def set_random_play(self, did="", **kwargs):
|
async def set_random_play(self, did="", **kwargs):
|
||||||
await self.devices[did].set_play_type(PLAY_TYPE_RND)
|
await self.set_play_type(did, PLAY_TYPE_RND)
|
||||||
|
|
||||||
|
async def set_play_type(self, did="", play_type=PLAY_TYPE_RND, dotts=True):
|
||||||
|
await self.devices[did].set_play_type(play_type, dotts)
|
||||||
|
|
||||||
# 设置为刷新列表
|
# 设置为刷新列表
|
||||||
async def gen_music_list(self, **kwargs):
|
async def gen_music_list(self, **kwargs):
|
||||||
@ -1758,11 +1760,12 @@ class XiaoMusicDevice:
|
|||||||
self.log.info("get_volume. volume:%d", volume)
|
self.log.info("get_volume. volume:%d", volume)
|
||||||
return volume
|
return volume
|
||||||
|
|
||||||
async def set_play_type(self, play_type):
|
async def set_play_type(self, play_type, dotts=True):
|
||||||
self.device.play_type = play_type
|
self.device.play_type = play_type
|
||||||
self.xiaomusic.save_cur_config()
|
self.xiaomusic.save_cur_config()
|
||||||
tts = PLAY_TYPE_TTS[play_type]
|
if dotts:
|
||||||
await self.do_tts(tts)
|
tts = self.config.get_play_type_tts(play_type)
|
||||||
|
await self.do_tts(tts)
|
||||||
self.update_playlist()
|
self.update_playlist()
|
||||||
|
|
||||||
async def play_music_list(self, list_name, music_name):
|
async def play_music_list(self, list_name, music_name):
|
||||||
|
Loading…
Reference in New Issue
Block a user