feat: 新增口令【播放列表第几个+列表名】来播放列表里的第几个 #158
This commit is contained in:
parent
c923ad00f8
commit
cef5278f16
@ -25,6 +25,7 @@ def default_key_word_dict():
|
||||
"刷新列表": "gen_music_list",
|
||||
"加入收藏": "add_to_favorites",
|
||||
"取消收藏": "del_from_favorites",
|
||||
"播放列表第": "play_music_list_index",
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +54,7 @@ def default_key_match_order():
|
||||
"随机播放",
|
||||
"关机",
|
||||
"刷新列表",
|
||||
"播放列表第",
|
||||
"播放列表",
|
||||
"加入收藏",
|
||||
"取消收藏",
|
||||
@ -91,7 +93,8 @@ class Config:
|
||||
) # "bilisearch:" or "ytsearch:"
|
||||
ffmpeg_location: str = os.getenv("XIAOMUSIC_FFMPEG_LOCATION", "./ffmpeg/bin")
|
||||
active_cmd: str = os.getenv(
|
||||
"XIAOMUSIC_ACTIVE_CMD", "play,set_random_play,playlocal,play_music_list,stop"
|
||||
"XIAOMUSIC_ACTIVE_CMD",
|
||||
"play,set_random_play,playlocal,play_music_list,play_music_list_index,stop_after_minute,stop",
|
||||
)
|
||||
exclude_dirs: str = os.getenv("XIAOMUSIC_EXCLUDE_DIRS", "@eaDir")
|
||||
music_path_depth: int = int(os.getenv("XIAOMUSIC_MUSIC_PATH_DEPTH", "10"))
|
||||
|
@ -402,3 +402,41 @@ def convert_file_to_mp3(input_file: str, ffmpeg_location: str, music_path: str)
|
||||
|
||||
relative_path = os.path.relpath(out_file_path, music_path)
|
||||
return relative_path
|
||||
|
||||
|
||||
chinese_to_arabic = {
|
||||
"零": 0,
|
||||
"一": 1,
|
||||
"二": 2,
|
||||
"三": 3,
|
||||
"四": 4,
|
||||
"五": 5,
|
||||
"六": 6,
|
||||
"七": 7,
|
||||
"八": 8,
|
||||
"九": 9,
|
||||
"十": 10,
|
||||
"百": 100,
|
||||
"千": 1000,
|
||||
"万": 10000,
|
||||
"亿": 100000000,
|
||||
}
|
||||
|
||||
|
||||
def chinese_to_number(chinese):
|
||||
result = 0
|
||||
unit = 1
|
||||
num = 0
|
||||
for char in reversed(chinese):
|
||||
if char in chinese_to_arabic:
|
||||
val = chinese_to_arabic[char]
|
||||
if val >= 10:
|
||||
if val > unit:
|
||||
unit = val
|
||||
else:
|
||||
unit *= val
|
||||
else:
|
||||
num += val * unit
|
||||
result += num
|
||||
num = 0
|
||||
return result
|
||||
|
@ -35,6 +35,7 @@ from xiaomusic.const import (
|
||||
from xiaomusic.crontab import Crontab
|
||||
from xiaomusic.plugin import PluginManager
|
||||
from xiaomusic.utils import (
|
||||
chinese_to_number,
|
||||
convert_file_to_mp3,
|
||||
custom_sort_key,
|
||||
deepcopy_data_no_sensitive_info,
|
||||
@ -741,6 +742,30 @@ class XiaoMusic:
|
||||
music_name = parts[1]
|
||||
await self.devices[did].play_music_list(list_name, music_name)
|
||||
|
||||
# 播放一个播放列表里第几个
|
||||
async def play_music_list_index(self, did="", arg1="", **kwargs):
|
||||
patternarg = r"^([零一二三四五六七八九十百千万亿]+)个(.*)"
|
||||
# 匹配参数
|
||||
matcharg = re.match(patternarg, arg1)
|
||||
if not matcharg:
|
||||
return await self.play_music_list(did, arg1)
|
||||
|
||||
chinese_index = matcharg.groups()[0]
|
||||
list_name = matcharg.groups()[1]
|
||||
list_name = self._find_real_music_list_name(list_name)
|
||||
if list_name not in self.music_list:
|
||||
await self.do_tts(did, f"播放列表{list_name}不存在")
|
||||
return
|
||||
|
||||
index = chinese_to_number(chinese_index)
|
||||
play_list = self.music_list[list_name]
|
||||
if 0 <= index - 1 < len(play_list):
|
||||
music_name = play_list[index - 1]
|
||||
self.log.info(f"即将播放 ${arg1} 里的第 ${index} 个: ${music_name}")
|
||||
await self.devices[did].play_music_list(list_name, music_name)
|
||||
return
|
||||
await self.do_tts(did, f"播放列表{list_name}中找不到第${index}个")
|
||||
|
||||
# 播放
|
||||
async def play(self, did="", arg1="", **kwargs):
|
||||
parts = arg1.split("|")
|
||||
|
Loading…
Reference in New Issue
Block a user