From 2c3523283e039a73db1989cd3c24296d4837d7f7 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 5 Dec 2021 16:06:20 +0800 Subject: [PATCH] =?UTF-8?q?neteasedown=20=E6=94=AF=E6=8C=81=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=99=BB=E5=BD=95=E4=BF=A1=E6=81=AF=EF=BC=8C=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B8=85=E7=90=86=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 6 ++-- neteasedown.py | 83 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 17 deletions(-) diff --git a/list.json b/list.json index 62e229a..048c3f8 100644 --- a/list.json +++ b/list.json @@ -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", diff --git a/neteasedown.py b/neteasedown.py index 0ca4ba3..5d16b54 100644 --- a/neteasedown.py +++ b/neteasedown.py @@ -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,11 +117,21 @@ 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: + 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"**未登录/登录失败**,错误信息:`{login_info['content']}`") - return + 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()