Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Diaoxiaozhang committed Jul 25, 2024
1 parent 34ee6eb commit 850946c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
39 changes: 16 additions & 23 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from tkinter import filedialog
import json

current_version = main.version
ximalaya = main.Ximalaya()
loop = asyncio.get_event_loop()
parser = argparse.ArgumentParser()
Expand All @@ -23,8 +24,21 @@ def select_directory():
root.destroy()
return directory_path

def get_latest_release():
url = "https://api.github.com/repos/Diaoxiaozhang/Ximalaya-Downloader/releases/latest"
response = requests.get(url)
version = response.json()["tag_name"]
release_url = response.json()["html_url"]
return version, release_url

if __name__ == "__main__":
print("欢迎使用喜马拉雅下载器")
latest_version, latest_release_url = get_latest_release()
if latest_version == current_version:
print("当前您使用的已是最新版本,如果遇到任何问题,请前往github提交issue")
else:
print("您当前使用的并非最新版本,强烈建议前往github下载最新版本")
print(f"下载链接:{latest_release_url}")
cookie, path = ximalaya.analyze_config()
if not cookie:
username = False
Expand All @@ -35,35 +49,14 @@ def select_directory():
else:
print('在config文件中未检测到有效的下载路径,将使用默认下载路径./download')
path = './download'
response = requests.get(f"https://www.ximalaya.com/mobile-playpage/track/v3/baseInfo/{int(time.time() * 1000)}?device=web&trackId=188017958&trackQualityLevel=1",headers=ximalaya.default_headers)
if response.json()["ret"] == 927 and not username:
print("检测到当前ip不在中国大陆,由于喜马拉雅官方限制,必须登录才能继续使用,将自动跳转到登录流程")
if not username:
print("未检测到有效喜马拉雅登录信息,请登录后再使用")
ximalaya.login()
headers = {
"user-agent": ua.random,
"cookie": ximalaya.analyze_config()[0]
}
logined = True
elif not username:
while True:
print("未检测到有效喜马拉雅登录信息,请选择是否要登录:")
print("1. 登录")
print("2. 不登录")
choice = input()
if choice == "1":
ximalaya.login()
headers = {
"user-agent": ua.random,
"cookie": ximalaya.analyze_config()[0]
}
logined = True
break
elif choice == "2":
headers = ximalaya.default_headers
logined = False
break
else:
print("输入有误,请重新输入!")
else:
print(f"已检测到有效登录信息,当前登录用户为{username},如需切换账号请删除config.json文件然后重新启动本程序!")
headers = {
Expand Down
57 changes: 33 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import selenium.common.exceptions
import colorama

version = "v0.4.2"
colorama.init(autoreset=True)
logger = logging.getLogger('logger')
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -71,16 +72,22 @@ def analyze_sound(self, sound_id, headers):
logger.debug(f'ID为{sound_id}的声音解析失败!')
logger.debug(traceback.format_exc())
return False
sound_info = {"name": sound_name, 0: "", 1: "", 2: ""}
for encrypted_url in encrypted_url_list:
if encrypted_url["type"] == "M4A_128":
sound_info[2] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_64":
sound_info[1] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_32":
sound_info[0] = self.decrypt_url(encrypted_url["url"])
logger.debug(f'ID为{sound_id}的声音解析成功!')
return sound_info
if encrypted_url_list[0]["type"][:2] == "AI":
sound_info = {"name": sound_name, 0: "", 1: "", 2: ""}
sound_info[0] = sound_info[1] = self.decrypt_url(encrypted_url_list[0]["url"])
logger.debug(f'ID为{sound_id}的声音解析成功!')
return sound_info
else:
sound_info = {"name": sound_name, 0: "", 1: "", 2: ""}
for encrypted_url in encrypted_url_list:
if encrypted_url["type"] == "M4A_128":
sound_info[2] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_64":
sound_info[1] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_32":
sound_info[0] = self.decrypt_url(encrypted_url["url"])
logger.debug(f'ID为{sound_id}的声音解析成功!')
return sound_info

# 解析专辑,如果成功返回专辑名和专辑声音列表,否则返回False
def analyze_album(self, album_id):
Expand Down Expand Up @@ -148,20 +155,22 @@ async def async_analyze_sound(self, sound_id, session, headers):
retries -= 1
if not response_json["trackInfo"]["isAuthorized"]:
return 0 # 未购买或未登录vip账号
sound_info = {"name": sound_name, 0: "", 1: "", 2: ""}
for encrypted_url in encrypted_url_list:
if encrypted_url["type"] == "M4A_128":
sound_info[2] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "M4A_64":
sound_info[1] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "M4A_24":
sound_info[0] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_64":
sound_info[1] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_32":
sound_info[0] = self.decrypt_url(encrypted_url["url"])
logger.debug(f'ID为{sound_id}的声音解析成功!')
return sound_info
if encrypted_url_list[0]["type"][:2] == "AI":
sound_info = {"name": sound_name, 0: "", 1: "", 2: ""}
sound_info[0] = sound_info[1] = self.decrypt_url(encrypted_url_list[0]["url"])
logger.debug(f'ID为{sound_id}的声音解析成功!')
return sound_info
else:
sound_info = {"name": sound_name, 0: "", 1: "", 2: ""}
for encrypted_url in encrypted_url_list:
if encrypted_url["type"] == "M4A_128":
sound_info[2] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_64":
sound_info[1] = self.decrypt_url(encrypted_url["url"])
elif encrypted_url["type"] == "MP3_32":
sound_info[0] = self.decrypt_url(encrypted_url["url"])
logger.debug(f'ID为{sound_id}的声音解析成功!')
return sound_info

# 将文件名中不能包含的字符替换为空格
def replace_invalid_chars(self, name):
Expand Down

0 comments on commit 850946c

Please sign in to comment.