mirror of
https://github.com/Xtao-Labs/iShotaBot.git
synced 2024-11-16 12:51:38 +00:00
Fix a bug.
This commit is contained in:
parent
dfb16bb47a
commit
571cbd13ef
@ -13,6 +13,15 @@ from pyncm.utils.helper import TrackHelper
|
|||||||
from pyrogram.types import Message
|
from pyrogram.types import Message
|
||||||
|
|
||||||
|
|
||||||
|
def download_by_url(url, dest):
|
||||||
|
# Downloads generic content
|
||||||
|
response = GetCurrentSession().get(url, stream=True)
|
||||||
|
with open(dest, 'wb') as f:
|
||||||
|
for chunk in response.iter_content(1024 * 2 ** 10):
|
||||||
|
f.write(chunk) # write every 1MB read
|
||||||
|
return dest
|
||||||
|
|
||||||
|
|
||||||
def gen_author(song_info: dict) -> str:
|
def gen_author(song_info: dict) -> str:
|
||||||
data = []
|
data = []
|
||||||
for i in song_info["songs"][0]["ar"]:
|
for i in song_info["songs"][0]["ar"]:
|
||||||
@ -42,23 +51,27 @@ def get_music_id(url: str) -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
async def netease_down(track_info: dict, song_info: dict, song, song_id: int) -> str:
|
async def netease_down(song_info: dict, song, song_id: int) -> str:
|
||||||
for i in listdir('data'):
|
for i in listdir('data'):
|
||||||
if splitext(i)[1] == ".lrc":
|
if splitext(i)[1] == ".lrc":
|
||||||
remove(i)
|
remove(f"data{sep}{i}")
|
||||||
continue
|
continue
|
||||||
if song_info["songs"][0]["name"] in splitext(i)[0]:
|
if song_info["songs"][0]["name"] in splitext(i)[0] and (not splitext(i)[1] == ".jpg"):
|
||||||
return i
|
return f"data{sep}{i}"
|
||||||
# Download
|
# Download audio
|
||||||
await execute(f"{executable} -m pyncm http://music.163.com/song?id={song_id} "
|
await execute(f"{executable} -m pyncm http://music.163.com/song?id={song_id} "
|
||||||
f"--output data --load data/session.ncm --lyric-no lrc --lyric-no tlyric --lyric-no romalrc")
|
f"--output data --load data/session.ncm --lyric-no lrc --lyric-no tlyric --lyric-no romalrc")
|
||||||
|
# Download cover
|
||||||
|
if not isfile(f'data{sep}{song_info["songs"][0]["name"]}.jpg'):
|
||||||
|
download_by_url(song.AlbumCover,
|
||||||
|
f'data{sep}{song_info["songs"][0]["name"]}.jpg')
|
||||||
for i in listdir('data'):
|
for i in listdir('data'):
|
||||||
if splitext(i)[1] == ".lrc":
|
if splitext(i)[1] == ".lrc":
|
||||||
remove(i)
|
remove(f"data{sep}{i}")
|
||||||
continue
|
continue
|
||||||
if song_info["songs"][0]["name"] in splitext(i)[0]:
|
if song_info["songs"][0]["name"] in splitext(i)[0] and (not splitext(i)[1] == ".jpg"):
|
||||||
name = f'data{sep}{song_info["songs"][0]["name"]}{splitext(i)[1]}'
|
name = f'data{sep}{song_info["songs"][0]["name"]}{splitext(i)[1]}'
|
||||||
rename(i, name)
|
rename(f"data{sep}{i}", name)
|
||||||
return name
|
return name
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@ -87,7 +100,7 @@ async def start_download(context: Message, message: Message, song_id: int, flac_
|
|||||||
for char in song_info["songs"][0]["name"]:
|
for char in song_info["songs"][0]["name"]:
|
||||||
if char in ['/', '\\', ':', '*', '?', '"', '<', '>', '|']:
|
if char in ['/', '\\', ':', '*', '?', '"', '<', '>', '|']:
|
||||||
song_info["songs"][0]["name"] = song_info["songs"][0]["name"].replace(char, '')
|
song_info["songs"][0]["name"] = song_info["songs"][0]["name"].replace(char, '')
|
||||||
path = await netease_down(track_info, song_info, song, song_id)
|
path = await netease_down(song_info, song, song_id)
|
||||||
if path:
|
if path:
|
||||||
await context.edit("正在上传歌曲。。。")
|
await context.edit("正在上传歌曲。。。")
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user