NeteaseMusic修复了bug (#45)

Co-authored-by: TNTcraftHIM <TNTcraftHIM@users.noreply.github.com>
This commit is contained in:
AAA 2020-08-29 19:07:35 +08:00 committed by GitHub
parent 840cd8f6c4
commit 3d7b7592a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -282,10 +282,10 @@
}, },
{ {
"name": "neteasemusic", "name": "neteasemusic",
"version": "2.7", "version": "2.8",
"section": "daily", "section": "daily",
"maintainer": "TNTcraftHIM", "maintainer": "TNTcraftHIM",
"size": "24.3 kb", "size": "25.3 kb",
"supported": true, "supported": true,
"des-short": "网易云点歌", "des-short": "网易云点歌",
"des": "可以在线搜索并且快速点歌歌曲信息齐全支持直接回复点歌。命令nem。" "des": "可以在线搜索并且快速点歌歌曲信息齐全支持直接回复点歌。命令nem。"

View File

@ -14,6 +14,7 @@ from os.path import exists
from collections import defaultdict from collections import defaultdict
from telethon.tl.types import DocumentAttributeAudio from telethon.tl.types import DocumentAttributeAudio
class RetryError(Exception): # 重试错误,用于再次重试 class RetryError(Exception): # 重试错误,用于再次重试
pass pass
@ -26,7 +27,8 @@ async def nem(context):
proxynum = 0 proxynum = 0
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063', headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063',
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "X-Real-IP": "223.252.199.66"} "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "X-Real-IP": "223.252.199.66"}
proxy = [{'http': 'http://192.210.137.108:8080', 'https': 'http://192.210.137.108:8080'}, {'http': 'http://music.lolico.me:39000', 'https': 'http://music.lolico.me:39000'}, {'http': 'http://aimer.one:2333', 'https': 'http://aimer.one:2333'}, {'http': 'http://fs2.ilogic.net.cn:5200','https': 'http://fs2.ilogic.net.cn:5200'}, {'http': 'http://64.64.250.246:8080', 'https': 'http://64.64.250.246:8080'}] proxy = [{'http': 'http://192.210.137.108:8080', 'https': 'http://192.210.137.108:8080'}, {'http': 'http://music.lolico.me:39000', 'https': 'http://music.lolico.me:39000'}, {'http': 'http://aimer.one:2333',
'https': 'http://aimer.one:2333'}, {'http': 'http://fs2.ilogic.net.cn:5200', 'https': 'http://fs2.ilogic.net.cn:5200'}, {'http': 'http://64.64.250.246:8080', 'https': 'http://64.64.250.246:8080'}]
if len(context.parameter) < 2: if len(context.parameter) < 2:
await context.edit("**使用方法:** `-nem` `<指令>` `<关键词>`\n\n指令s为搜索p为点歌id为歌曲ID点歌\n搜索灰色歌曲请给出歌手\n可回复搜索结果消息`-nem` `p` `<歌曲数字序号>`点歌") await context.edit("**使用方法:** `-nem` `<指令>` `<关键词>`\n\n指令s为搜索p为点歌id为歌曲ID点歌\n搜索灰色歌曲请给出歌手\n可回复搜索结果消息`-nem` `p` `<歌曲数字序号>`点歌")
return return
@ -144,7 +146,8 @@ async def nem(context):
proxies = proxy[proxynum] proxies = proxy[proxynum]
proxynum += 1 proxynum += 1
if idplay: # 指定ID播放 if idplay: # 指定ID播放
url = "http://music.163.com/api/song/detail?id="+ idplay +"&ids=[" + idplay + "]" url = "http://music.163.com/api/song/detail?id=" + \
idplay + "&ids=[" + idplay + "]"
# 搜索后播放 # 搜索后播放
req = requests.request("GET", url, headers=headers) req = requests.request("GET", url, headers=headers)
if req.status_code == 200: if req.status_code == 200:
@ -189,6 +192,7 @@ async def nem(context):
name = info['title'].replace('/', " ") + ".mp3" name = info['title'].replace('/', " ") + ".mp3"
if ccimported: # 尝试使用高清音质下载 if ccimported: # 尝试使用高清音质下载
songid = str(info['id']) songid = str(info['id'])
class WangyiyunDownload(object): class WangyiyunDownload(object):
def __init__(self): def __init__(self):
self.key = '0CoJUm6Qyw8W8jud' self.key = '0CoJUm6Qyw8W8jud'
@ -329,7 +333,7 @@ async def nem(context):
try: try:
content = requests.get( content = requests.get(
url=real_url, headers=self.headers).content url=real_url, headers=self.headers).content
with open(file, 'wb') as fp: with open(file, 'wb', encoding='utf8') as fp:
fp.write(content) fp.write(content)
except: except:
print('服务器连接出错') print('服务器连接出错')
@ -368,7 +372,7 @@ async def nem(context):
';', ', ') + " - " + "**" + info['title'] + "**" ';', ', ') + " - " + "**" + info['title'] + "**"
if ccimported is False: if ccimported is False:
with open(name, 'wb') as f: with open(name, 'wb', encoding='utf8') as f:
f.write(music.content) f.write(music.content)
if (path.getsize(name) / 1024) < 100: if (path.getsize(name) / 1024) < 100:
remove(name) remove(name)
@ -383,14 +387,16 @@ async def nem(context):
' <strong>这里</strong> ' + '</a>' + '前往网页版收听' ' <strong>这里</strong> ' + '</a>' + '前往网页版收听'
await bot.send_message(context.chat_id, f"<strong>【{info['title']}】</strong>\n" + "歌曲获取失败,资源获取可能受限,你可以再次尝试。\n" + res, parse_mode='html', link_preview=True) await bot.send_message(context.chat_id, f"<strong>【{info['title']}】</strong>\n" + "歌曲获取失败,资源获取可能受限,你可以再次尝试。\n" + res, parse_mode='html', link_preview=True)
return return
duration = 0
if imported is True: if imported is True:
await context.edit(f"{title}信息导入中 . . .") await context.edit(f"{title}信息导入中 . . .")
try: try:
imagedata = requests.get( imagedata = requests.get(
info['albumpic'], headers=headers).content info['albumpic'], headers=headers).content
except: except:
await bot.send_message(context.chat_id, '~ 封面好像获取失败了呢,不要在意不要在意 ~ ') await bot.send_message(context.chat_id, '封面好像获取失败了呢,不要在意不要在意 ~ ')
tag = eyed3.load(name) tag = eyed3.load(name)
duration = int(tag.info.time_secs)
tag.initTag() tag.initTag()
tag = tag.tag tag = tag.tag
tag.artist = info['artist'] tag.artist = info['artist']
@ -417,7 +423,7 @@ async def nem(context):
link_preview=False, link_preview=False,
force_document=False, force_document=False,
attributes=(DocumentAttributeAudio( attributes=(DocumentAttributeAudio(
0, False, info['title'], info['artist']),) duration, False, info['title'], info['artist']),)
) )
try: try:
if reply.sender.is_self: if reply.sender.is_self: