Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Diaoxiaozhang committed Aug 27, 2024
1 parent bed0bed commit f9f24fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def select_directory():
except Exception:
print("输入有误,请重新输入!")
continue
album_name, sounds = ximalaya.analyze_album(album_id)
album_name, sounds = ximalaya.analyze_album(album_id, headers)
if not sounds:
continue
album_type = ximalaya.judge_album(album_id, headers)
Expand Down
11 changes: 7 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def analyze_sound(self, sound_id, headers):
return sound_info

# 解析专辑,如果成功返回专辑名和专辑声音列表,否则返回False
def analyze_album(self, album_id):
def analyze_album(self, album_id, headers):
logger.debug(f'开始解析ID为{album_id}的专辑')
url = "https://www.ximalaya.com/revision/album/v1/getTracksList"
params = {
Expand All @@ -99,10 +99,9 @@ def analyze_album(self, album_id):
"sort": 0,
"pageSize": 100
}
headers = self.default_headers
headers["referer"] = f"https://www.ximalaya.com/album/{album_id}"
retries = 5
while True:
retries = 5
try:
response = requests.get(url, headers=headers, params=params, timeout=15)
except Exception as e:
Expand All @@ -117,6 +116,7 @@ def analyze_album(self, album_id):
if retries == 0:
print(colorama.Fore.RED + f'ID为{album_id}的专辑解析失败!')
logger.debug(f'ID为{album_id}的专辑解析失败!(getTracksList错误)')
return False, False
pages = math.ceil(response.json()["data"]["trackTotalCount"] / 100)
sounds = []
for page in range(1, pages + 1):
Expand All @@ -126,8 +126,8 @@ def analyze_album(self, album_id):
"sort": 0,
"pageSize": 100
}
retries = 5
while True:
retries = 5
try:
response = requests.get(url, headers=headers, params=params, timeout=30)
except Exception as e:
Expand All @@ -136,12 +136,15 @@ def analyze_album(self, album_id):
logger.debug(traceback.format_exc())
return False, False
if response.json()["data"]["tracks"] == []:
print(f"第{page}页解析失败第{6-retries}次,共{pages}页")
retries -= 1
else:
print(f"第{page}页解析成功,共{pages}页")
break
if retries == 0:
print(colorama.Fore.RED + f'ID为{album_id}的专辑解析失败!')
logger.debug(f'ID为{album_id}的专辑解析失败!(getTracksList错误)')
return False, False
sounds += response.json()["data"]["tracks"]
album_name = sounds[0]["albumTitle"]
logger.debug(f'ID为{album_id}的专辑解析成功')
Expand Down

0 comments on commit f9f24fd

Please sign in to comment.