mirror of
https://github.com/BsaLee/up163cloud.git
synced 2026-01-15 18:20:43 +08:00
部分歌曲没有artist信息等,增加异常处理,增强稳健性
This commit is contained in:
parent
ede9a1fd35
commit
43cfe4e85b
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
__pycache__/
|
||||||
|
.history/
|
||||||
|
neteasecloudmusicapi/
|
||||||
|
cookies.txt
|
||||||
|
failed_ids.txt
|
||||||
|
*.json
|
||||||
47
main.py
47
main.py
@ -131,30 +131,37 @@ def process_songs(song_info_list, cookie):
|
|||||||
# 更新 song_info 添加 artist 和 album 信息
|
# 更新 song_info 添加 artist 和 album 信息
|
||||||
song_info['artist'] = song_artist
|
song_info['artist'] = song_artist
|
||||||
song_info['album'] = song_album
|
song_info['album'] = song_album
|
||||||
|
try:
|
||||||
|
try_to_upload_song(song_info, cookie)
|
||||||
|
except Exception as e:
|
||||||
|
print(f'上传过程异常,跳过该歌曲:{e}')
|
||||||
|
save_failed_id(song_id)
|
||||||
|
|
||||||
attempts = 0
|
def try_to_upload_song(song_info, cookie):
|
||||||
while attempts < 3:
|
song_id = song_info['id']
|
||||||
result = import_song(song_info, cookie)
|
attempts = 0
|
||||||
|
while attempts < 3:
|
||||||
|
result = import_song(song_info, cookie)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
success_songs = result.get('data', {}).get('successSongs', [])
|
success_songs = result.get('data', {}).get('successSongs', [])
|
||||||
failed = result.get('data', {}).get('failed', [])
|
failed = result.get('data', {}).get('failed', [])
|
||||||
|
|
||||||
if success_songs:
|
if success_songs:
|
||||||
print(f"歌曲 {song_id} 导入成功!")
|
print(f"歌曲 {song_id} 导入成功!")
|
||||||
break # 成功则跳出循环
|
break # 成功则跳出循环
|
||||||
else:
|
else:
|
||||||
print(f"歌曲 {song_id} 导入失败,失败原因:{failed}")
|
print(f"歌曲 {song_id} 导入失败,失败原因:{failed}")
|
||||||
if all(f['code'] == -100 for f in failed): # 文件已存在的错误码
|
if all(f['code'] == -100 for f in failed): # 文件已存在的错误码
|
||||||
print(f"歌曲 {song_id} 文件已存在,跳过")
|
print(f"歌曲 {song_id} 文件已存在,跳过")
|
||||||
save_failed_id(song_id) # 保存失败的 ID
|
save_failed_id(song_id) # 保存失败的 ID
|
||||||
break
|
break
|
||||||
time.sleep(5) # 请求失败后等待 5 秒重新请求
|
time.sleep(5) # 请求失败后等待 5 秒重新请求
|
||||||
attempts += 1
|
attempts += 1
|
||||||
|
|
||||||
if attempts == 3: # 如果失败三次,则跳过此 ID
|
if attempts == 3: # 如果失败三次,则跳过此 ID
|
||||||
print(f"歌曲 {song_id} 失败三次,跳过该歌曲。")
|
print(f"歌曲 {song_id} 失败三次,跳过该歌曲。")
|
||||||
save_failed_id(song_id) # 保存失败的 ID
|
save_failed_id(song_id) # 保存失败的 ID
|
||||||
|
|
||||||
# 主函数
|
# 主函数
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user