2025-03-12 09:26:36 +00:00
|
|
|
|
import asyncio
|
2025-02-20 09:33:58 +00:00
|
|
|
|
import pickle
|
|
|
|
|
|
import time
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
from nonebot import on_command
|
|
|
|
|
|
from nonebot.rule import to_me
|
|
|
|
|
|
from nonebot.adapters.qq import MessageSegment,MessageEvent
|
|
|
|
|
|
from src.clover_music.cloud_music.cloud_music import *
|
2025-02-28 06:19:15 +00:00
|
|
|
|
from src.clover_image.delete_file import delete_file
|
2025-02-20 09:33:58 +00:00
|
|
|
|
|
2025-03-12 09:26:36 +00:00
|
|
|
|
music = on_command("点歌", rule=to_me(), priority=10,block=False)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
@music.handle()
|
|
|
|
|
|
async def handle_function(msg: MessageEvent):
|
|
|
|
|
|
keyword = msg.get_plaintext().replace("/点歌", "").strip(" ")
|
|
|
|
|
|
|
|
|
|
|
|
if keyword == "":
|
|
|
|
|
|
await music.finish("\n请输入“/点歌+歌曲名”喔🎶")
|
|
|
|
|
|
|
|
|
|
|
|
#获取登录信息 可以获取更换高音质
|
|
|
|
|
|
session = requests.session()
|
|
|
|
|
|
if not os.path.exists('cloud_music_cookies.cookie'):
|
|
|
|
|
|
with open('cloud_music_cookies.cookie', 'wb') as f:
|
|
|
|
|
|
pickle.dump(session.cookies, f)
|
|
|
|
|
|
# 读取 cookie
|
|
|
|
|
|
session.cookies = pickle.load(open('cloud_music_cookies.cookie', 'rb'))
|
2025-03-03 13:36:06 +00:00
|
|
|
|
session, status,user_id = await netease_cloud_music_is_login(session)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
if not status:
|
|
|
|
|
|
await music.send("登录失效,请联系管理员进行登录")
|
2025-02-28 06:19:15 +00:00
|
|
|
|
unikey = await get_qr_key(session)
|
|
|
|
|
|
path = await create_qr_code(unikey)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
|
|
|
|
|
|
"""是否要发送到QQ上面登录 """
|
|
|
|
|
|
# await clover_music.send(MessageSegment.file_image(Path(path)))
|
|
|
|
|
|
"""是否要发送到QQ上面登录 """
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
2025-02-28 06:19:15 +00:00
|
|
|
|
code = await check_qr_code(unikey, session)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
if '801' in str(code):
|
|
|
|
|
|
print('二维码未失效,请扫码!')
|
|
|
|
|
|
elif '802' in str(code):
|
|
|
|
|
|
print('已扫码,请确认!')
|
|
|
|
|
|
elif '803' in str(code):
|
|
|
|
|
|
print('已确认,登入成功!')
|
|
|
|
|
|
break
|
|
|
|
|
|
else:
|
2025-03-12 09:26:36 +00:00
|
|
|
|
break
|
|
|
|
|
|
await asyncio.sleep(2)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
|
|
|
|
|
|
#搜索歌曲
|
2025-02-28 06:19:15 +00:00
|
|
|
|
song_id,song_name,singer,song_url = await netease_music_search(keyword,session)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
song_name = str(song_name).replace(".", "·").replace("/", "、")
|
|
|
|
|
|
if song_id is None:
|
|
|
|
|
|
await music.finish("\n没有找到歌曲,或检索到的歌曲均为付费喔qwq\n这绝对不是我的错,绝对不是!")
|
|
|
|
|
|
else:
|
|
|
|
|
|
await music.send(MessageSegment.text(f" 来源:网易云音乐\n歌曲:{song_name} - {singer}\n请稍等喔🎵"))
|
|
|
|
|
|
#返回转换后的歌曲路径
|
2025-02-28 06:19:15 +00:00
|
|
|
|
output_silk_path = await netease_music_download(song_id, song_name, singer,session)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
|
|
|
|
|
|
if output_silk_path == -1:
|
|
|
|
|
|
await music.send("歌曲音频获取失败:登录信息失效。")
|
|
|
|
|
|
elif output_silk_path is None:
|
|
|
|
|
|
await music.send("歌曲音频获取失败了Σヽ(゚Д ゚; )ノ,请重试。")
|
|
|
|
|
|
else:
|
|
|
|
|
|
await music.send(MessageSegment.file_audio(Path(output_silk_path)))
|
|
|
|
|
|
|
|
|
|
|
|
#删除临时文件
|
2025-02-28 06:19:15 +00:00
|
|
|
|
await delete_file(output_silk_path)
|
2025-02-20 09:33:58 +00:00
|
|
|
|
await music.finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|