def __onDownloadComplete(self, api: API, gid): with self._resource_lock: if self.gid == gid: if api.get_download(gid).followed_by_ids: self.gid = api.get_download(gid).followed_by_ids[0] download_dict[self._listener.uid] = AriaDownloadStatus( self.gid, self._listener) update_all_messages() LOGGER.info(f'Changed gid from {gid} to {self.gid}') else: self._listener.onDownloadComplete()
def __onDownloadComplete(self, api: API, gid): LOGGER.info(f"onDownloadComplete: {gid}") dl = getDownloadByGid(gid) download = api.get_download(gid) if download.followed_by_ids: new_gid = download.followed_by_ids[0] new_download = api.get_download(new_gid) with download_dict_lock: download_dict[dl.uid()] = AriaDownloadStatus(new_gid, dl.getListener()) if new_download.is_torrent: download_dict[dl.uid()].is_torrent = True update_all_messages() LOGGER.info(f'Changed gid from {gid} to {new_gid}') elif dl: threading.Thread(target=dl.getListener().onDownloadComplete).start()
def on_complete_thread(self, api: aria2p.API, gid: str): print(datetime.datetime.now().strftime("%Y/%m/%dT%H:%M:%S.%f") + " " + gid + " OnComplete") dl = api.get_download(gid) for file in dl.files: self.HandleDownload(api, dl, file.path) print(datetime.datetime.now().strftime("%Y/%m/%dT%H:%M:%S.%f") + " " + gid + " Complete")
def __onDownloadStarted(self, api: API, gid): if STOP_DUPLICATE_MIRROR or TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None: sleep(1) dl = getDownloadByGid(gid) download = api.get_download(gid) if STOP_DUPLICATE_MIRROR: LOGGER.info(f"Checking File/Folder if already in Drive...") sleep(1) self.name = aria2.get_download(gid).name sname = self.name if self.listener.isTar: sname = sname + ".tar" if self.listener.extract: smsg = None else: gdrive = GoogleDriveHelper(None) smsg, button = gdrive.drive_list(sname) if smsg: dl.getListener().onDownloadError(f'File/Folder already available in Drive.\n\n') aria2.remove([download], force = True) aria2.purge() sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button) return if TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None: limit = None if TAR_UNZIP_LIMIT is not None and (self.listener.isTar or self.listener.extract): LOGGER.info(f"Checking File/Folder Size...") limit = TAR_UNZIP_LIMIT mssg = f'Tar/Unzip limit is {TAR_UNZIP_LIMIT}' if TORRENT_DIRECT_LIMIT is not None and limit is None: LOGGER.info(f"Checking File/Folder Size...") limit = TORRENT_DIRECT_LIMIT mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}' if limit is not None: sleep(1.5) size = aria2.get_download(gid).total_length limit = limit.split(' ', maxsplit=1) limitint = int(limit[0]) if 'G' in limit[1] or 'g' in limit[1]: if size > limitint * 1024**3: dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}') aria2.remove([download], force = True) aria2.purge() return elif 'T' in limit[1] or 't' in limit[1]: if size > limitint * 1024**4: dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}') aria2.remove([download], force = True) aria2.purge() return update_all_messages()
def __onDownloadComplete(self, api: API, gid): with self._resource_lock: 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() LOGGER.info(f'Changed gid from {gid} to {self.gid}') else: self.__listener.onDownloadComplete()