start Aria2 Websocket listener before adding download in queue.
This commit is contained in:
parent
d3938784ac
commit
c4e81d5ab1
|
|
@ -17,6 +17,7 @@ class AriaDownloadHelper(DownloadHelper):
|
|||
|
||||
def __onDownloadStarted(self, api, gid):
|
||||
with self._resource_lock:
|
||||
LOGGER.info(f"onDownloadStart: {gid}")
|
||||
if self.gid == gid:
|
||||
download = api.get_download(gid)
|
||||
self.name = download.name
|
||||
|
|
@ -24,15 +25,16 @@ class AriaDownloadHelper(DownloadHelper):
|
|||
|
||||
def __onDownloadComplete(self, api: API, gid):
|
||||
with self._resource_lock:
|
||||
LOGGER.info(f"onDownloadComplete: {gid}")
|
||||
if self.gid == gid:
|
||||
download = api.get_download(gid)
|
||||
if download.followed_by_ids:
|
||||
self.gid = download.followed_by_ids[0]
|
||||
with download_dict_lock:
|
||||
download_dict[self.__listener.uid] = AriaDownloadStatus(self, self.__listener)
|
||||
if download.is_torrent:
|
||||
download_dict[self.__listener.uid].is_torrent = True
|
||||
update_all_messages()
|
||||
if download.is_torrent:
|
||||
download_dict[self.__listener.uid].is_torrent = True
|
||||
update_all_messages()
|
||||
LOGGER.info(f'Changed gid from {gid} to {self.gid}')
|
||||
else:
|
||||
self.__listener.onDownloadComplete()
|
||||
|
|
@ -56,22 +58,20 @@ class AriaDownloadHelper(DownloadHelper):
|
|||
self.__listener.onDownloadError(error)
|
||||
|
||||
def add_download(self, link: str, path):
|
||||
if is_magnet(link):
|
||||
download = aria2.add_magnet(link, {'dir': path})
|
||||
else:
|
||||
download = aria2.add_uris([link], {'dir': path})
|
||||
self.gid = download.gid
|
||||
with download_dict_lock:
|
||||
download_dict[self.__listener.uid] = AriaDownloadStatus(self, self.__listener)
|
||||
if download.error_message:
|
||||
self.__listener.onDownloadError(download.error_message)
|
||||
return
|
||||
LOGGER.info(f"Started: {self.gid} DIR:{download.dir} ")
|
||||
aria2.listen_to_notifications(threaded=True, on_download_start=self.__onDownloadStarted,
|
||||
on_download_error=self.__onDownloadError,
|
||||
on_download_pause=self.__onDownloadPause,
|
||||
on_download_stop=self.__onDownloadStopped,
|
||||
on_download_complete=self.__onDownloadComplete)
|
||||
if is_magnet(link):
|
||||
download = aria2.add_magnet(link, {'dir': path})
|
||||
else:
|
||||
download = aria2.add_uris([link], {'dir': path})
|
||||
with self._resource_lock:
|
||||
self.gid = download.gid
|
||||
with download_dict_lock:
|
||||
download_dict[self._listener.uid] = AriaDownloadStatus(self.gid, self._listener)
|
||||
LOGGER.info(f"Started: {self.gid} DIR:{download.dir} ")
|
||||
|
||||
def cancel_download(self):
|
||||
download = aria2.get_download(self.gid)
|
||||
|
|
|
|||
Loading…
Reference in New Issue