Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Jun 28, 2024
1 parent 1c06766 commit 0dac2cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
12 changes: 9 additions & 3 deletions nonebot_plugin_multincm/data_source/song.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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}"],
)
Expand Down Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_multincm/interaction/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions nonebot_plugin_multincm/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 9 additions & 0 deletions nonebot_plugin_multincm/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 0dac2cf

Please sign in to comment.