点歌功能再次优化
This commit is contained in:
@@ -10,7 +10,7 @@ command-format = """
|
||||
|
||||
[GuessSong.api]
|
||||
# 新的聚合搜索API,一次调用即可获取所有信息(包括播放链接)
|
||||
music_api = "http://192.168.2.170:5000?keyword={keywords}&limit=10"
|
||||
music_api = "http://192.168.2.240:5000"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
|
||||
# 加载API配置
|
||||
api_config = guess_song_config.get("api", {})
|
||||
self.music_api = api_config.get("music_api", "http://192.168.2.170:5000")
|
||||
self.music_api = api_config.get("music_api", "http://192.168.2.170:5000?keywords={keywords}&limit=10")
|
||||
|
||||
# 加载游戏配置
|
||||
game_config = guess_song_config.get("game", {})
|
||||
@@ -359,10 +359,13 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
async def _get_random_song(self, singer_name: Optional[str]) -> Dict[str, Any]:
|
||||
"""获取随机歌曲信息"""
|
||||
try:
|
||||
base_url = self.music_api.rstrip("/")
|
||||
keyword = singer_name if singer_name else random.choice(self.popular_singers)
|
||||
search_url = f"{base_url}/Search"
|
||||
resp = requests.get(search_url, params={"keywords": keyword}, timeout=10)
|
||||
if "{keywords}" in self.music_api:
|
||||
search_url = self.music_api.format(keywords=keyword)
|
||||
else:
|
||||
base = self.music_api.split("?")[0].rstrip("/")
|
||||
search_url = f"{base}/Search?keywords={keyword}&limit=10"
|
||||
resp = requests.get(search_url, timeout=10)
|
||||
if resp.status_code != 200:
|
||||
self.LOG.error(f"API 请求失败,状态码: {resp.status_code}")
|
||||
return {}
|
||||
@@ -376,9 +379,9 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
return {}
|
||||
random_song = random.choice(songs)
|
||||
song_id = str(random_song.get("id", ""))
|
||||
detail_url = f"{base_url}/Song_V1"
|
||||
detail_params = {"url": song_id, "level": "standard", "type": "json"}
|
||||
detail_resp = requests.get(detail_url, params=detail_params, timeout=15)
|
||||
base = self.music_api.split("?")[0].rstrip("/")
|
||||
detail_url = f"{base}/Song_V1?url={song_id}&level=standard&type=json"
|
||||
detail_resp = requests.get(detail_url, timeout=15)
|
||||
if detail_resp.status_code != 200:
|
||||
self.LOG.error(f"详情请求失败,状态码: {detail_resp.status_code}")
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user