From 77678f5717e3f5d8d9f8d3edb76935210a997072 Mon Sep 17 00:00:00 2001 From: Jonnieey Date: Fri, 4 Sep 2020 11:49:26 +0200 Subject: [PATCH] feat: Add API method --- src/aria2p/api.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/aria2p/api.py b/src/aria2p/api.py index efe058e..c6faf78 100644 --- a/src/aria2p/api.py +++ b/src/aria2p/api.py @@ -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]: