Skip to content

Commit f9f24fd

Browse files
committed
debug
1 parent bed0bed commit f9f24fd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def select_directory():
106106
except Exception:
107107
print("输入有误,请重新输入!")
108108
continue
109-
album_name, sounds = ximalaya.analyze_album(album_id)
109+
album_name, sounds = ximalaya.analyze_album(album_id, headers)
110110
if not sounds:
111111
continue
112112
album_type = ximalaya.judge_album(album_id, headers)

main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def analyze_sound(self, sound_id, headers):
9090
return sound_info
9191

9292
# 解析专辑,如果成功返回专辑名和专辑声音列表,否则返回False
93-
def analyze_album(self, album_id):
93+
def analyze_album(self, album_id, headers):
9494
logger.debug(f'开始解析ID为{album_id}的专辑')
9595
url = "https://www.ximalaya.com/revision/album/v1/getTracksList"
9696
params = {
@@ -99,10 +99,9 @@ def analyze_album(self, album_id):
9999
"sort": 0,
100100
"pageSize": 100
101101
}
102-
headers = self.default_headers
103102
headers["referer"] = f"https://www.ximalaya.com/album/{album_id}"
103+
retries = 5
104104
while True:
105-
retries = 5
106105
try:
107106
response = requests.get(url, headers=headers, params=params, timeout=15)
108107
except Exception as e:
@@ -117,6 +116,7 @@ def analyze_album(self, album_id):
117116
if retries == 0:
118117
print(colorama.Fore.RED + f'ID为{album_id}的专辑解析失败!')
119118
logger.debug(f'ID为{album_id}的专辑解析失败!(getTracksList错误)')
119+
return False, False
120120
pages = math.ceil(response.json()["data"]["trackTotalCount"] / 100)
121121
sounds = []
122122
for page in range(1, pages + 1):
@@ -126,8 +126,8 @@ def analyze_album(self, album_id):
126126
"sort": 0,
127127
"pageSize": 100
128128
}
129+
retries = 5
129130
while True:
130-
retries = 5
131131
try:
132132
response = requests.get(url, headers=headers, params=params, timeout=30)
133133
except Exception as e:
@@ -136,12 +136,15 @@ def analyze_album(self, album_id):
136136
logger.debug(traceback.format_exc())
137137
return False, False
138138
if response.json()["data"]["tracks"] == []:
139+
print(f"第{page}页解析失败第{6-retries}次,共{pages}页")
139140
retries -= 1
140141
else:
142+
print(f"第{page}页解析成功,共{pages}页")
141143
break
142144
if retries == 0:
143145
print(colorama.Fore.RED + f'ID为{album_id}的专辑解析失败!')
144146
logger.debug(f'ID为{album_id}的专辑解析失败!(getTracksList错误)')
147+
return False, False
145148
sounds += response.json()["data"]["tracks"]
146149
album_name = sounds[0]["albumTitle"]
147150
logger.debug(f'ID为{album_id}的专辑解析成功')

0 commit comments

Comments
 (0)