netease 优化安装依赖包流程,支持登出

This commit is contained in:
xtaodada 2021-12-05 18:13:46 +08:00
parent 2efe4c1d25
commit 5e14035f70
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 16 additions and 9 deletions

View File

@ -292,10 +292,10 @@
}, },
{ {
"name": "neteasedown", "name": "neteasedown",
"version": "1.21", "version": "1.211",
"section": "daily", "section": "daily",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "9.2 kb", "size": "9.4 kb",
"supported": true, "supported": true,
"des-short": "网易云搜歌/点歌", "des-short": "网易云搜歌/点歌",
"des": "可以在线搜索并且快速点歌支持解锁VIP歌曲。命令ned。" "des": "可以在线搜索并且快速点歌支持解锁VIP歌曲。命令ned。"

View File

@ -10,11 +10,11 @@ try:
from pyncm import GetCurrentSession, apis, DumpSessionAsString, SetCurrentSession, LoadSessionFromString from pyncm import GetCurrentSession, apis, DumpSessionAsString, SetCurrentSession, LoadSessionFromString
from pyncm.apis import LoginFailedException from pyncm.apis import LoginFailedException
from pyncm.apis.cloudsearch import CloudSearchType from pyncm.apis.cloudsearch import CloudSearchType
from pyncm.apis.login import LoginLogout
cc_imported = True cc_imported = True
except ImportError: except ImportError:
print(f'[!] Please run {executable} -m pip install requests pycryptodome tqdm mutagen and ' print(f'[!] Please run {executable} -m pip install pyncm')
f'{executable} -m pip installgit+https://github.com/Xtao-Labs/pyncm.git')
cc_imported = False cc_imported = False
@ -99,8 +99,7 @@ i.e.
parameters="{关键词/id}/{login <账号> <密码>}/{clear}") parameters="{关键词/id}/{login <账号> <密码>}/{clear}")
async def ned(context): async def ned(context):
if not cc_imported: if not cc_imported:
await context.edit(f"[!] Please run `-sh {executable} -m pip install requests pycryptodome tqdm mutagen` " await context.edit(f"[!] Please run `-sh {executable} -m pip install pyncm` "
f"and run `-sh {executable} -m pip install git+https://github.com/Xtao-Labs/pyncm.git` "
f"and then restart pagermaid.") f"and then restart pagermaid.")
return return
if len(context.parameter) < 1: if len(context.parameter) < 1:
@ -111,6 +110,8 @@ async def ned(context):
if isfile(f"data{sep}session.ncm"): if isfile(f"data{sep}session.ncm"):
with open(f"data{sep}session.ncm") as f: with open(f"data{sep}session.ncm") as f:
SetCurrentSession(LoadSessionFromString(f.read())) SetCurrentSession(LoadSessionFromString(f.read()))
# 海外用户
GetCurrentSession().headers['X-Real-IP'] = '118.88.88.88'
# 处理账号登录 # 处理账号登录
if context.parameter[0] == "login": if context.parameter[0] == "login":
# 显示登录信息 # 显示登录信息
@ -161,12 +162,18 @@ async def ned(context):
with open(f"data{sep}session.ncm", 'w+') as f: with open(f"data{sep}session.ncm", 'w+') as f:
f.write(DumpSessionAsString(GetCurrentSession())) f.write(DumpSessionAsString(GetCurrentSession()))
return return
if context.parameter[0] == "clear": elif context.parameter[0] == "logout":
# 登出
LoginLogout()
if isfile(f"data{sep}session.ncm"):
remove(f"data{sep}session.ncm")
return await context.edit("[ned] 账号登出成功。")
elif context.parameter[0] == "clear":
# 清除歌曲缓存 # 清除歌曲缓存
for i in listdir("data"): for i in listdir("data"):
if i.find(".mp3") != -1 or i.find(".jpg") != -1: if i.find(".mp3") != -1 or i.find(".jpg") != -1:
remove(f"data{sep}{i}") remove(f"data{sep}{i}")
await context.edit("**已清除缓存**") await context.edit("[ned] **已清除缓存**")
return return
# 搜索歌曲 # 搜索歌曲
song_id = context.arguments song_id = context.arguments
@ -217,6 +224,6 @@ async def ned(context):
for i in listdir("data"): for i in listdir("data"):
if i.find(".mp3") != -1 or i.find(".jpg") != -1: if i.find(".mp3") != -1 or i.find(".jpg") != -1:
remove(f"data{sep}{i}") remove(f"data{sep}{i}")
msg = await context.respond("**已清除缓存**") msg = await context.respond("[ned] **已自动清除缓存**")
await sleep(3) await sleep(3)
await msg.delete() await msg.delete()