From 0dac2cf4a75bf5503046872fae13d530f1728ca9 Mon Sep 17 00:00:00 2001 From: student_2333 Date: Fri, 28 Jun 2024 19:08:18 +0800 Subject: [PATCH] up --- nonebot_plugin_multincm/data_source/song.py | 12 +++++++++--- .../interaction/commands/search.py | 2 +- nonebot_plugin_multincm/utils/__init__.py | 1 + nonebot_plugin_multincm/utils/base.py | 9 +++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/nonebot_plugin_multincm/data_source/song.py b/nonebot_plugin_multincm/data_source/song.py index 47480fe..65a8380 100644 --- a/nonebot_plugin_multincm/data_source/song.py +++ b/nonebot_plugin_multincm/data_source/song.py @@ -1,7 +1,13 @@ from typing import Generic, Iterable, List, Optional, TypeVar from typing_extensions import Self, override -from ..utils import format_artists, format_time, get_thumb_url, normalize_lrc +from ..utils import ( + format_artists, + format_time, + get_thumb_url, + merge_alias, + normalize_lrc, +) from .base import ( BaseSearcher, BaseSong, @@ -23,7 +29,7 @@ async def transform_resp_to_list_card(cls, resp: md.Song) -> ListPageCard: return ListPageCard( cover=get_thumb_url(resp.al.pic_url), title=resp.name, - alias=";".join(resp.alias), + alias=";".join(merge_alias(resp)), extras=[format_artists(resp.ar)], small_extras=[f"{format_time(resp.dt)} | 热度 {resp.pop}"], ) @@ -53,7 +59,7 @@ async def get_name(self) -> str: @override async def get_alias(self) -> List[str]: - return self.info.alias + (self.info.tns or []) + return merge_alias(self.info) @override async def get_artists(self) -> List[str]: diff --git a/nonebot_plugin_multincm/interaction/commands/search.py b/nonebot_plugin_multincm/interaction/commands/search.py index 39c5fdb..7349ea5 100644 --- a/nonebot_plugin_multincm/interaction/commands/search.py +++ b/nonebot_plugin_multincm/interaction/commands/search.py @@ -78,7 +78,7 @@ async def tip_illegal(message: str): while True: msg = await prompt("") if msg is None: - await matcher.finish() + await matcher.finish("等待超时,已退出选择") msg = msg.extract_plain_text().strip().lower() if msg in EXIT_COMMAND: diff --git a/nonebot_plugin_multincm/utils/__init__.py b/nonebot_plugin_multincm/utils/__init__.py index c9273d9..3d13670 100644 --- a/nonebot_plugin_multincm/utils/__init__.py +++ b/nonebot_plugin_multincm/utils/__init__.py @@ -12,6 +12,7 @@ format_time as format_time, get_thumb_url as get_thumb_url, is_debug_mode as is_debug_mode, + merge_alias as merge_alias, write_debug_file as write_debug_file, ) from .lrc_parser import ( diff --git a/nonebot_plugin_multincm/utils/base.py b/nonebot_plugin_multincm/utils/base.py index 202dddf..3a8db55 100644 --- a/nonebot_plugin_multincm/utils/base.py +++ b/nonebot_plugin_multincm/utils/base.py @@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Any, List, Optional, Tuple, TypeVar from typing_extensions import ParamSpec +from cookit import flatten from nonebot.utils import run_sync from yarl import URL @@ -126,3 +127,11 @@ async def encode_silk(path: Path, rate: int = 24000) -> Path: pcm_path.unlink(missing_ok=True) return silk_path + + +def merge_alias(song: "md.Song") -> List[str]: + alias = song.tns.copy() if song.tns else [] + alias.extend( + x for x in flatten(x.split(";") for x in song.alias) if x not in alias + ) + return alias