更换点歌API
This commit is contained in:
@@ -6,4 +6,5 @@ command-format = """
|
||||
点歌 歌曲名
|
||||
"""
|
||||
|
||||
music_api_url ="https://hhlqilongzhu.cn/api/dg_douyinmusic.php?msg={song_name}&type=json&n=1"
|
||||
# 新的聚合搜索API,一次调用即可获取所有信息(包括播放链接)
|
||||
music_api_url = "https://music-dl.sayqz.com/api/?type=aggregateSearch&keyword={song_name}&limit=30"
|
||||
+39
-9
@@ -139,21 +139,51 @@ class MusicPlugin(MessagePluginInterface):
|
||||
def _search_song(self, song_name: str) -> Dict[str, Any]:
|
||||
"""搜索歌曲信息"""
|
||||
try:
|
||||
# 尝试QQ音乐API
|
||||
fallback_api = f"{self.music_api_url}".format(song_name=song_name)
|
||||
response = requests.get(fallback_api,verify=False)
|
||||
# 使用新的聚合搜索API
|
||||
api_url = f"{self.music_api_url}".format(song_name=song_name)
|
||||
self.LOG.info(f"请求歌曲API: {api_url}")
|
||||
|
||||
response = requests.get(api_url, verify=False)
|
||||
|
||||
if response.status_code != 200:
|
||||
self.LOG.error(f"API 请求失败,状态码: {response.status_code}")
|
||||
return {}
|
||||
|
||||
json_data = response.json().get("data")
|
||||
json_data = response.json()
|
||||
|
||||
# 检查API返回状态
|
||||
if json_data.get("code") != 200:
|
||||
self.LOG.error(f"API 返回错误: {json_data.get('message')}")
|
||||
return {}
|
||||
|
||||
# 从results中获取第一首歌
|
||||
song_list = json_data.get("data", {}).get("results", [])
|
||||
if not song_list or not isinstance(song_list, list) or len(song_list) == 0:
|
||||
self.LOG.error(f"未找到歌曲: {song_name}")
|
||||
return {}
|
||||
|
||||
# 获取第一首搜索结果
|
||||
first_song = song_list[0]
|
||||
|
||||
# 从API响应中提取所需字段
|
||||
result_song_name = first_song.get('name', '')
|
||||
result_singer_name = first_song.get('artist', '')
|
||||
play_url = first_song.get('url', '')
|
||||
singer_pic = first_song.get('pic', '')
|
||||
data_url = first_song.get('url', '') # 使用相同的URL作为数据链接
|
||||
|
||||
if not play_url:
|
||||
self.LOG.error(f"歌曲播放链接为空")
|
||||
return {}
|
||||
|
||||
self.LOG.info(f"成功获取歌曲: {result_singer_name} - {result_song_name}")
|
||||
|
||||
return {
|
||||
"song_name": json_data.get('title', ''),
|
||||
"singer_name": json_data.get('singer', ''),
|
||||
"play_url": json_data.get('url', ''),
|
||||
"singer_pic": json_data.get('cover', ''),
|
||||
"data_url": json_data.get('link', '')
|
||||
"song_name": result_song_name,
|
||||
"singer_name": result_singer_name,
|
||||
"play_url": play_url,
|
||||
"singer_pic": singer_pic,
|
||||
"data_url": data_url
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user