调试内容
This commit is contained in:
@@ -50,8 +50,6 @@ class MusicPlugin(MessagePluginInterface):
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
|
||||
# 加载配置
|
||||
self.load_config()
|
||||
self._commands = self._config.get("Music", {}).get("command", ["点歌", "音乐"])
|
||||
self.command_format = self._config.get("Music", {}).get("command-format", "点歌 歌曲名")
|
||||
self.enable = self._config.get("Music", {}).get("enable", True)
|
||||
@@ -84,6 +82,7 @@ class MusicPlugin(MessagePluginInterface):
|
||||
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
||||
"""处理消息"""
|
||||
content = str(message.get("content", "")).strip()
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
command = content.split(" ")[0]
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
@@ -117,98 +116,26 @@ class MusicPlugin(MessagePluginInterface):
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理音乐请求出错: {e}")
|
||||
wcf.send_text(f"-----Bot-----\n❌请求出错:{e}",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"处理出错: {e}"
|
||||
|
||||
def _search_song(self, song_name: str) -> Dict[str, Any]:
|
||||
"""搜索歌曲信息"""
|
||||
try:
|
||||
# 尝试QQ音乐API
|
||||
short_play_api = f"https://qqmusic.qqovo.cn/getSearchByKey?key={song_name}&page=1&limit=1"
|
||||
fallback_api = f"https://www.hhlqilongzhu.cn/api/dg_wyymusic.php?gm={song_name}&n=1&num=1&type=json"
|
||||
|
||||
response = requests.get(short_play_api)
|
||||
if response.status_code == 400:
|
||||
response = requests.get(fallback_api)
|
||||
response = requests.get(fallback_api)
|
||||
|
||||
if response.status_code != 200:
|
||||
self.LOG.error(f"API 请求失败,状态码: {response.status_code}")
|
||||
return {}
|
||||
|
||||
json_data = response.json()
|
||||
result = json_data.get('response', {}).get('data', {}).get('song', {}).get('list', [])
|
||||
|
||||
if not result:
|
||||
# 尝试备用API
|
||||
response = requests.get(fallback_api)
|
||||
if response.status_code == 200:
|
||||
music_response = response.json()
|
||||
return {
|
||||
"song_name": music_response.get('title', ''),
|
||||
"singer_name": music_response.get('singer', ''),
|
||||
"play_url": music_response.get('music_url', ''),
|
||||
"singer_pic": music_response.get('cover', ''),
|
||||
"data_url": music_response.get('link', '')
|
||||
}
|
||||
return {}
|
||||
|
||||
# 解析QQ音乐结果
|
||||
first_song = result[0]
|
||||
song_name = first_song.get('songname', '')
|
||||
song_mid = first_song.get('songmid', '')
|
||||
first_singer_name = first_song.get('singer', [{}])[0].get('name', '')
|
||||
|
||||
zhida_singer = json_data.get('response', {}).get('data', {}).get('zhida', {}).get('zhida_singer', {})
|
||||
singer_pic = zhida_singer.get('singerPic', '') if zhida_singer else None
|
||||
|
||||
# 获取播放链接
|
||||
music_play_api = f"https://qqmusic.qqovo.cn/getMusicPlay?songmid={song_mid}&quality=m4a"
|
||||
music_response = requests.get(music_play_api)
|
||||
|
||||
if music_response.status_code == 400:
|
||||
# 尝试备用API
|
||||
response = requests.get(fallback_api)
|
||||
if response.status_code == 200:
|
||||
music_response = response.json()
|
||||
return {
|
||||
"song_name": music_response.get('title', song_name),
|
||||
"singer_name": music_response.get('singer', first_singer_name),
|
||||
"play_url": music_response.get('music_url', ''),
|
||||
"singer_pic": music_response.get('cover', singer_pic),
|
||||
"data_url": music_response.get('link', '')
|
||||
}
|
||||
return {}
|
||||
|
||||
if music_response.status_code != 200:
|
||||
self.LOG.error(f"获取播放链接失败,状态码: {music_response.status_code}")
|
||||
return {}
|
||||
|
||||
music_data = music_response.json()
|
||||
play_url = music_data.get('data', {}).get('playUrl', {}).get(song_mid, {}).get('url', '')
|
||||
|
||||
if not play_url:
|
||||
# 尝试备用API
|
||||
response = requests.get(fallback_api)
|
||||
if response.status_code == 200:
|
||||
music_response = response.json()
|
||||
return {
|
||||
"song_name": music_response.get('title', song_name),
|
||||
"singer_name": music_response.get('singer', first_singer_name),
|
||||
"play_url": music_response.get('music_url', ''),
|
||||
"singer_pic": music_response.get('cover', singer_pic),
|
||||
"data_url": music_response.get('link', '')
|
||||
}
|
||||
return {}
|
||||
|
||||
data_url = f"https://y.qq.com/n/ryqq/songDetail/{song_mid}"
|
||||
|
||||
return {
|
||||
"song_name": song_name,
|
||||
"singer_name": first_singer_name,
|
||||
"play_url": play_url,
|
||||
"singer_pic": singer_pic,
|
||||
"data_url": data_url
|
||||
"song_name": json_data.get('title', ''),
|
||||
"singer_name": json_data.get('singer', ''),
|
||||
"play_url": json_data.get('music_url', ''),
|
||||
"singer_pic": json_data.get('cover', ''),
|
||||
"data_url": json_data.get('link', '')
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user