Skip to content

Commit

Permalink
feat: optimize download logic
Browse files Browse the repository at this point in the history
  • Loading branch information
s0urcelab committed Apr 26, 2023
1 parent b8dd2e1 commit 4ffb304
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,14 @@ def update_dynamic(cpdate, uid_list):
# async task
async def async_task():
# 未下载 || 可重试 && 时长小于10分钟
q = ((where('dstatus') == 0) | ((where('dstatus') == -1) & (where('dl_retry') < 3))) & (where('duration') < 600000)
dy_list = dynamic_list.search(q)
wait_dl_list = sorted(dy_list, key=lambda i: i['pdate'], reverse=True)[:CONCURRENT_TASK_NUM]
await download_video_list(wait_dl_list, logger.warning)
q_limit = where('duration') < 600000
q1 = (where('dstatus') == 0) & q_limit
q2 = ((where('dstatus') == -1) & (where('dl_retry') < 3)) & q_limit
wait_list = dynamic_list.search(q1)
retry_list = dynamic_list.search(q2)

dl_list = sorted(wait_list if len(wait_list) > 0 else retry_list, key=lambda i: i['pdate'], reverse=True)[:CONCURRENT_TASK_NUM]
await download_video_list(dl_list, logger.warning)

if __name__ == '__main__':
logger.info('定时任务:开始获取最新动态')
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def retry_dl_video(bvids):
if target != None:
find_and_remove(target['title'])
switch_dl_status(bvid, 0)
dynamic_list.update({'dl_retry': 0}, where('bvid') == bvid)
return {'code': 0, 'data': f'重新加入下载列表'}

# 修改推测bgm标题
Expand Down

0 comments on commit 4ffb304

Please sign in to comment.