Skip to content

Commit

Permalink
feat: Add API method
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnieey authored and pawamoy committed Sep 4, 2020
1 parent a53f081 commit 77678f5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/aria2p/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,35 @@ def move_to_bottom(self, download: Download) -> int:
"""
return self.client.change_position(download.gid, 0, "POS_END")

def retry_downloads(self, downloads: List[Download], clean: bool = False) -> List[bool]:
"""
Resume failed downloads from where they left off with new GIDs.
Parameters:
downloads: the list of downloads to remove.
clean: whether to remove the aria2 control file as well.
Returns:
Success or failure of the operation for each given download.
"""
result = []
for download in downloads:
if not download.has_failed:
continue
try:
uri = download.files[0].uris[0]["uri"]
new_download_gid = self.add_uris([uri], download.options)
if not new_download_gid:
continue

self.remove([download], clean)
result.append(True)

except ClientException as error:
result.append(error)

return result

def remove(
self, downloads: List[Download], force: bool = False, files: bool = False, clean: bool = True
) -> List[bool]:
Expand Down

0 comments on commit 77678f5

Please sign in to comment.