mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
网易云音乐登录修复
This commit is contained in:
parent
6bd163a15b
commit
243159939f
4 changed files with 58 additions and 51 deletions
|
|
@ -7,6 +7,7 @@ nonebot2[websockets]
|
|||
sqlalchemy~=2.0.34
|
||||
autopep8
|
||||
graiax-silkcoder
|
||||
graiax-silkcoder[ffempeg]
|
||||
Crypto
|
||||
fake_useragent
|
||||
pycryptodome
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ def encSecKey():
|
|||
|
||||
|
||||
save_path = os.getcwd()+'/src/music/netease_music'
|
||||
qrcode_path = os.getcwd()+'/src/music'
|
||||
|
||||
|
||||
# 判断cookie是否有效
|
||||
|
|
@ -85,12 +86,18 @@ def netease_cloud_music_is_login(session):
|
|||
except Exception:
|
||||
pass
|
||||
csrf_token = session.cookies.get('__csrf')
|
||||
c = str({'csrf_token': csrf_token})
|
||||
if csrf_token is None:
|
||||
return session, False
|
||||
else:
|
||||
try:
|
||||
loginurl = session.post('https://music.163.com/weapi/w/nuser/account/get?csrf_token={}'.format(csrf_token),data={'params': params(None), 'encSecKey': encSecKey()}, headers=headers).json()
|
||||
loginurl = session.post(f'https://music.163.com/weapi/w/nuser/account/get?csrf_token={csrf_token}',data={'params': params(None), 'encSecKey': encSecKey()}, headers=headers).json()
|
||||
print(loginurl)
|
||||
print(loginurl['code'])
|
||||
if '200' in str(loginurl['code']):
|
||||
print('登录成功')
|
||||
return session, True
|
||||
else:
|
||||
print('登录失败')
|
||||
return session, False
|
||||
except BaseException:
|
||||
return session, False
|
||||
|
|
@ -120,16 +127,8 @@ def create_qr_code(unikey):
|
|||
img = qr.make_image()
|
||||
a = BytesIO()
|
||||
img.save(a, 'png')
|
||||
png = a.getvalue()
|
||||
# 将字节数据转换为图像
|
||||
img = Image.open(BytesIO(png))
|
||||
# 保存图像到本地文件
|
||||
img.save(save_path,'qrcode.png')
|
||||
a.close()
|
||||
return os.getcwd()+'/'+save_path+'/qrcode.png'
|
||||
# # 打开二维码进行扫码操作
|
||||
# t = showpng(png)
|
||||
# t.start()
|
||||
img.save(os.path.join(qrcode_path, 'qrcode.png'))
|
||||
return qrcode_path + '/qrcode.png'
|
||||
|
||||
|
||||
# 检查二维码状态是否被扫描
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
import random
|
||||
from nonebot.rule import Rule, to_me
|
||||
from nonebot import on_message
|
||||
from nonebot.adapters.qq import Message
|
||||
|
|
@ -17,4 +17,12 @@ rule = Rule(check_value_in_menu)
|
|||
check = on_message(rule=to_me() & rule ,block=True)
|
||||
@check.handle()
|
||||
async def check(bot: Bot, event: Event):
|
||||
await bot.send(message=Message("是什么呢?猫猫没有识别到,喵~"+'\n'+"(๑>ڡ<)☆ 请注意命令后要加空格哦~"),event=event)
|
||||
await bot.send(message=Message(random.choice(text_list)),event=event)
|
||||
|
||||
text_list = [
|
||||
"是什么呢?猫猫没有识别到,喵~"+'\n'+"(๑>ڡ<)☆ 给个准信,别让我瞎猜",
|
||||
"是想让我干嘛呢?猫猫一头雾水,喵~" + '\n' + "(๑•̀ㅂ•́)و✧ 直接跟我说,别这么含蓄,喵~",
|
||||
"是啥意思呀?猫猫完全没搞懂,喵~" + '\n' + "(๑・.・๑) 别折腾我啦,说明白,喵~",
|
||||
"是特殊信号?猫猫听不懂,喵~" + '\n' + "(๑・̀︶・́)و 下个明确指令,喵~",
|
||||
"难道是新指令?猫猫一脸茫然,喵~" + '\n' + "(๑>ڡ<)☆ 说详细点,别这么隐晦,喵~",
|
||||
]
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import pickle
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from lazy_object_proxy.utils import await_
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.adapters.qq import MessageSegment,MessageEvent
|
||||
|
|
@ -11,23 +13,6 @@ music = on_command("点歌", rule=to_me(), priority=10, block=True)
|
|||
async def handle_function(msg: MessageEvent):
|
||||
keyword = msg.get_plaintext().replace("/点歌", "").strip(" ")
|
||||
#获取登录信息 可以获取更换高音质
|
||||
session = cloud_music_login()
|
||||
#搜索歌曲
|
||||
song_id,song_name,singer,song_url = netease_music_search(keyword,session)
|
||||
if song_id is None:
|
||||
await music.finish("没有找到歌曲")
|
||||
else:
|
||||
await music.send(MessageSegment.text(f" 来源:网易云音乐\n歌曲:{song_name} - {singer}"))
|
||||
#返回转换后的歌曲路径
|
||||
output_silk_path = netease_music_download(song_id, song_name, singer,session)
|
||||
await music.send(MessageSegment.file_audio(Path(output_silk_path)))
|
||||
#删除临时文件
|
||||
netease_music_delete()
|
||||
await music.finish()
|
||||
|
||||
|
||||
def cloud_music_login():
|
||||
#判断返回cookie是否有效
|
||||
session = requests.session()
|
||||
if not os.path.exists('cloud_music_cookies.cookie'):
|
||||
with open('cloud_music_cookies.cookie', 'wb') as f:
|
||||
|
|
@ -36,9 +21,11 @@ def cloud_music_login():
|
|||
session.cookies = pickle.load(open('cloud_music_cookies.cookie', 'rb'))
|
||||
session, status = netease_cloud_music_is_login(session)
|
||||
if not status:
|
||||
await music.send("登录失效,请联系管理员进行登录")
|
||||
unikey = get_qr_key(session)
|
||||
path = create_qr_code(unikey)
|
||||
music.send(MessageSegment.file_image(Path(path)))
|
||||
"""是否要发送到QQ上面登录 """
|
||||
# await music.send(MessageSegment.file_image(Path(path)))
|
||||
while True:
|
||||
code = check_qr_code(unikey, session)
|
||||
if '801' in str(code):
|
||||
|
|
@ -53,7 +40,19 @@ def cloud_music_login():
|
|||
time.sleep(2)
|
||||
with open('cloud_music_cookies.cookie', 'wb') as f:
|
||||
pickle.dump(session.cookies, f)
|
||||
return session
|
||||
|
||||
#搜索歌曲
|
||||
song_id,song_name,singer,song_url = netease_music_search(keyword,session)
|
||||
if song_id is None:
|
||||
await music.finish("没有找到歌曲")
|
||||
else:
|
||||
await music.send(MessageSegment.text(f" 来源:网易云音乐\n歌曲:{song_name} - {singer}"))
|
||||
#返回转换后的歌曲路径
|
||||
output_silk_path = netease_music_download(song_id, song_name, singer,session)
|
||||
await music.send(MessageSegment.file_audio(Path(output_silk_path)))
|
||||
#删除临时文件
|
||||
netease_music_delete()
|
||||
await music.finish()
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue