def clean(self): try: aria2.purge() Interval[0].cancel() del Interval[0] delete_all_messages() except IndexError: pass
def __onDownloadError(self, api, gid): sleep(0.5) # sleep for split second to ensure proper dl gid update from onDownloadComplete dl = getDownloadByGid(gid) download = api.get_download(gid) error = download.error_message LOGGER.info(f"Download Error: {error}") if dl: dl.getListener().onDownloadError(error) aria2.purge()
def clean(self): try: aria2.purge() get_client().torrents_delete(torrent_hashes="all", delete_files=True) Interval[0].cancel() del Interval[0] delete_all_messages() except IndexError: pass
def cancel_download(self): LOGGER.info(f"Cancelling Download: {self.name()}") download = self.aria_download() if download.is_waiting: aria2.remove([download], force=True) aria2.purge() self.__listener.onDownloadError("Cancelled by user") return if len(download.followed_by_ids) != 0: downloads = aria2.get_downloads(download.followed_by_ids) aria2.remove(downloads, force=True) self.__listener.onDownloadError("Download stopped by user!") aria2.remove([download], force=True) aria2.purge()
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}') else: if dl: threading.Thread(target=dl.getListener().onDownloadComplete).start() aria2.purge()
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 __onDownloadStopped(self, api, gid): sleep(5) dl = getDownloadByGid(gid) if dl: dl.getListener().onDownloadError('Dead torrent!') aria2.purge()