Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🍲修复异步下载失败率高的问题, fix #496 #502 #503 #505 #506

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions Util/Download.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ async def AwemeDownload(self, aweme_data):
aweme_data (list): 抖音数据列表,列表的每个元素都是一个字典,字典包含了抖音的各种信息,如aweme_type, path, desc等。
"""

# 用于存储作者本页所有的下载任务, 最后会等待本页所有作品下载完成才结束本函数
download_tasks = []

# 遍历aweme_data中的每一个aweme字典
for aweme in aweme_data:
# 将UNIX时间戳转换为格式化的字符串
Expand Down Expand Up @@ -152,7 +155,9 @@ async def AwemeDownload(self, aweme_data):
filename=self.trim_filename(music_file_path, 50),
start=False)
Util.log.info(f"New task created with ID: {task_id}")
Util.asyncio.create_task(self.download_file(task_id, music_url, music_full_path))
download_task = Util.asyncio.create_task(self.download_file(task_id, music_url, music_full_path))
# 将任务添加到任务列表中
download_tasks.append(download_task)
except IndexError:
# 如果无法提取音乐URL,则跳过下载该音乐
Util.console.print("[ 提示 ]:该原声不可用,无法下载。")
Expand Down Expand Up @@ -185,7 +190,9 @@ async def AwemeDownload(self, aweme_data):
filename=self.trim_filename(video_file_path, 50),
start=False)
Util.log.info(f"New task created with ID: {task_id}")
Util.asyncio.create_task(self.download_file(task_id, video_url, video_full_path))
download_task = Util.asyncio.create_task(self.download_file(task_id, video_url, video_full_path))
# 将任务添加到任务列表中
download_tasks.append(download_task)
except IndexError:
# 如果无法提取视频URL,则跳过下载该音乐
Util.console.print("[ 提示 ]:该视频不可用,无法下载。")
Expand Down Expand Up @@ -218,9 +225,14 @@ async def AwemeDownload(self, aweme_data):
filename=self.trim_filename(image_file_path, 50),
start=False)
Util.log.info(f"New task created with ID: {task_id}")
Util.asyncio.create_task(self.download_file(task_id, image_url, image_full_path))
download_task = Util.asyncio.create_task(self.download_file(task_id, image_url, image_full_path))
# 将任务添加到任务列表中
download_tasks.append(download_task)
except IndexError:
# 如果无法提取图集URL,则跳过下载该音乐
Util.console.print("[ 提示 ]:该图片不可用,无法下载。")
Util.log.warning(f"[ 提示 ]:该图片不可用,无法下载。{IndexError}")
pass

# 等待本页所有的下载任务完成, 如果不等待的话就会还没等下完就去下载下一页了, 并发下载多了会被服务器断开连接
await Util.asyncio.gather(*download_tasks)