neteasedown 支持显示登录信息,自动清理缓存

This commit is contained in:
xtaodada 2021-12-05 16:06:20 +08:00
parent bcbb12683c
commit 2c3523283e
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 72 additions and 17 deletions

View File

@ -292,13 +292,13 @@
},
{
"name": "neteasedown",
"version": "1.202",
"version": "1.21",
"section": "daily",
"maintainer": "xtaodada",
"size": "6.7 kb",
"size": "9.2 kb",
"supported": true,
"des-short": "网易云搜歌/点歌",
"des": "可以在线搜索并且快速点歌(可回复信息点歌)支持解锁VIP歌曲。命令ned。"
"des": "可以在线搜索并且快速点歌支持解锁VIP歌曲。命令ned。"
},
{
"name": "killallmembers",

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from asyncio import sleep
from os import sep, remove, listdir
from os.path import isfile
from sys import executable
from time import strftime, localtime
try:
from mutagen.id3 import ID3, APIC, TIT2, TPE1
@ -12,7 +13,8 @@ try:
cc_imported = True
except ImportError:
print(f'[!] Please install {executable} -m pip install requests mutagen pycryptodome tqdm git+https://github.com/Xtao-Labs/pyncm.git')
print(f'[!] Please run {executable} -m pip install requests pycryptodome tqdm mutagen and '
f'{executable} -m pip installgit+https://github.com/Xtao-Labs/pyncm.git')
cc_imported = False
@ -38,6 +40,13 @@ def gen_author(song_info: dict) -> str:
return " ".join(data)
def get_duration(song_info: dict, track_info: dict) -> int:
if track_info["data"][0]["freeTrialInfo"]:
return track_info["data"][0]["freeTrialInfo"]["end"] - track_info["data"][0]["freeTrialInfo"]["start"]
else:
return int(song_info["songs"][0]["dt"] / 1000)
async def netease_down(track_info: dict, song_info: dict) -> str:
if not isfile(f'data{sep}{song_info["songs"][0]["name"]}.{track_info["data"][0]["type"]}'):
# Downloding source audio
@ -73,17 +82,30 @@ async def netease_down(track_info: dict, song_info: dict) -> str:
return f'data{sep}{song_info["songs"][0]["name"]}.{track_info["data"][0]["type"]}'
ned_help_msg = f"""
网易云搜/点歌
i.e.
`-{alias_command('ned')} 失眠飞行 兔籽鲸 / 雨客Yoker` # 通过歌曲名称+歌手(可选)点歌
`-{alias_command('ned')} 1430702717` # 通过歌曲 ID 点歌
`-{alias_command('ned')} login` # 显示登录信息
`-{alias_command('ned')} login 手机号码 密码` # 登录账号
`-{alias_command('ned')} clear` # 手动清除缓存
"""
@listener(is_plugin=True, outgoing=True, command=alias_command("ned"),
description="网易云搜/点歌。",
description=ned_help_msg,
parameters="{关键词/id}/{login <账号> <密码>}/{clear}")
async def ned(context):
if not cc_imported:
await context.edit(f"[!] Please run `-sh {executable} -m pip install requests pycryptodome tqdm "
f"mutagen git+https://github.com/Xtao-Labs/pyncm.git` and then restart pagermaid.")
await context.edit(f"[!] Please run `-sh {executable} -m pip install requests pycryptodome tqdm mutagen` "
f"and run `-sh {executable} -m pip install git+https://github.com/Xtao-Labs/pyncm.git` "
f"and then restart pagermaid.")
return
if len(context.parameter) < 1:
# 使用方法
await context.edit(f"**使用方法:** `-{alias_command('ned')}" + " {关键词/id}/{login <账号> <密码>}`")
await context.edit(ned_help_msg)
return
# 加载登录信息
if isfile(f"data{sep}session.ncm"):
@ -95,10 +117,20 @@ async def ned(context):
if len(context.parameter) == 1:
login_info = GetCurrentSession().login_info
if login_info["success"]:
await context.edit(f"已登录账号:**{login_info['content']['profile']['nickname']}**")
return
# 获取VIP类型
if login_info['content']['account']['vipType'] != 0:
vip_type = "**VIP**"
else:
await context.edit(f"**未登录/登录失败**,错误信息:`{login_info['content']}`")
vip_type = "**普通**"
# 获取账号创建时间
time = strftime("%Y-%m-%d %H:%M:%S", localtime(login_info['content']['account']['createTime'] / 1000))
if context.is_group:
await context.edit(f"[ned] 已登录{vip_type}账号,账号创建时间:`{time}`")
else:
await context.edit(f"[ned] 已登录{vip_type}账号:`{login_info['content']['profile']['nickname']}`"
f"账号创建时间:`{time}`")
else:
await context.edit(f"[ned] **未登录/登录失败**,额外信息:`{login_info['content']}`")
return
# 过滤空参数
if len(context.parameter) == 2:
@ -113,7 +145,18 @@ async def ned(context):
return
# 获取登录信息
login_info = GetCurrentSession().login_info
await context.edit(f"**登录成功**,已登录账号:**{login_info['content']['profile']['nickname']}**")
# 获取VIP类型
if login_info['content']['account']['vipType'] != 0:
vip_type = "**VIP**"
else:
vip_type = "**普通**"
# 获取账号创建时间
time = strftime("%Y-%m-%d %H:%M:%S", localtime(login_info['content']['account']['createTime']/1000))
if context.is_group:
await context.edit(f"[ned] **登录成功**,已登录{vip_type}账号,账号创建时间:`{time}`")
else:
await context.edit(f"[ned] **登录成功**,已登录{vip_type}账号:`{login_info['content']['profile']['nickname']}`"
f"账号创建时间:`{time}`")
# 保存登录信息
with open(f"data{sep}session.ncm", 'w+') as f:
f.write(DumpSessionAsString(GetCurrentSession()))
@ -149,11 +192,15 @@ async def ned(context):
path = await netease_down(track_info, song_info)
await context.edit("正在上传歌曲。。。")
# 上传歌曲
cap_ = ""
# 提醒登录VIP账号
if track_info["data"][0]["freeTrialInfo"]:
cap_ = f"**非VIP正在试听 {track_info['data'][0]['freeTrialInfo']['start']}s ~ " \
f"{track_info['data'][0]['freeTrialInfo']['end']}s**\n"
cap = f"「**{song_info['songs'][0]['name']}**」\n" \
f"{gen_author(song_info)}\n" \
f"\n" \
f"\n{cap_}" \
f"#netease #{int(track_info['data'][0]['br'] / 1000)}kbps #{track_info['data'][0]['type']}"
duration = int(song_info['songs'][0]['dt'] / 1000)
await context.client.send_file(
context.chat_id,
path,
@ -162,6 +209,14 @@ async def ned(context):
force_document=False,
thumb=path[:-3] + 'jpg',
attributes=(DocumentAttributeAudio(
duration, False, song_info['songs'][0]['name'], gen_author(song_info)),)
get_duration(song_info, track_info), False, song_info['songs'][0]['name'], gen_author(song_info)),)
)
await context.delete()
# 过多文件自动清理
if len(listdir("data")) > 100:
for i in listdir("data"):
if i.find(".mp3") != -1 or i.find(".jpg") != -1:
remove(f"data{sep}{i}")
msg = await context.respond("**已清除缓存**")
await sleep(3)
await msg.delete()