def __onDownloadStarted(self, api, gid):
     if STOP_DUPLICATE or TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None:
         sleep(1)
         dl = getDownloadByGid(gid)
         download = aria2.get_download(gid)
     if STOP_DUPLICATE and dl is not None and not dl.getListener().isLeech:
         LOGGER.info('Checking File/Folder if already in Drive...')
         sname = aria2.get_download(gid).name
         if dl.getListener().isTar:
             sname = sname + ".zip" if dl.getListener().isZip else sname + ".tar"
         if dl.getListener().extract:
             smsg = None
         else:
             gdrive = GoogleDriveHelper()
             smsg, button = gdrive.drive_list(sname, True)
         if smsg:
             dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n')
             aria2.remove([download], force=True)
             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) and dl is not None:
         sleep(1)
         size = aria2.get_download(gid).total_length
         if dl.getListener().isTar or dl.getListener().extract:
             is_tar_ext = True
             mssg = f'Tar/Unzip limit is {TAR_UNZIP_LIMIT}'
         else:
             is_tar_ext = False
             mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}'
         result = check_limit(size, TORRENT_DIRECT_LIMIT, TAR_UNZIP_LIMIT, is_tar_ext)
         if result:
             dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}')
             aria2.remove([download], force=True)
             return
     update_all_messages()
 def __onDownloadStarted(self, 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 = aria2.get_download(gid)
         if STOP_DUPLICATE_MIRROR:
             LOGGER.info(f"Checking File/Folder if already in Drive...")
             sleep(1)
             sname = aria2.get_download(gid).name
             if self.listener.isTar:
                 sname = sname + ".tar"
             elif 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)
                 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}'
             elif 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)
                         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)
                         return
     update_all_messages()
 def __onDownloadComplete(self, api: API, gid):
     dl = getDownloadByGid(gid)
     download = aria2.get_download(gid)
     if download.followed_by_ids:
         new_gid = download.followed_by_ids[0]
         new_download = aria2.get_download(new_gid)
         if dl is None:
             dl = getDownloadByGid(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 __onDownloadError(self, api, gid):
     LOGGER.info(f"onDownloadError: {gid}")
     sleep(0.5)  # sleep for split second to ensure proper dl gid update from onDownloadComplete
     dl = getDownloadByGid(gid)
     download = aria2.get_download(gid)
     error = download.error_message
     LOGGER.info(f"Download Error: {error}")
     if dl: 
         dl.getListener().onDownloadError(error)
Exemple #5
0
 def cancel_download(self):
     download = aria2.get_download(self.gid)
     if download.is_waiting:
         aria2.remove([download])
         self.__listener.onDownloadError("Cancelled by 👤User")
         return
     if len(download.followed_by_ids) != 0:
         downloads = aria2.get_downloads(download.followed_by_ids)
         aria2.pause(downloads)
     aria2.pause([download])
    def __onDownloadStarted(self, api, gid):
        if STOP_DUPLICATE_MIRROR or TORRENT_DIRECT_LIMIT is not None:
            sleep(0.5)
            dl = getDownloadByGid(gid)
            download = api.get_download(gid)
            
            if STOP_DUPLICATE_MIRROR:
                LOGGER.info(f"Checking File/Folder if already in Drive...")
                self.name = download.name
                sname = download.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:
                    aria2.remove([download])
                    dl.getListener().onDownloadError(f'File/Folder is already available in Drive.\n\n')
                    sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
                    return

            if TORRENT_DIRECT_LIMIT is not None:
                LOGGER.info(f"Checking File/Folder Size...")
                sleep(1.5)
                size = aria2.get_download(gid).total_length
                limit = TORRENT_DIRECT_LIMIT
                limit = limit.split(' ', maxsplit=1)
                limitint = int(limit[0])
                if 'GB' in limit or 'gb' in limit:
                    if size > limitint * 1024**3:
                        aria2.remove([download])
                        dl.getListener().onDownloadError(f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}')
                        return
                elif 'TB' in limit or 'tb' in limit:
                    if size > limitint * 1024**4:
                        aria2.remove([download])
                        dl.getListener().onDownloadError(f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}')
                        return
        update_all_messages()
def get_download(gid):
    return aria2.get_download(gid)
def get_download(gid):
    try:
        return aria2.get_download(gid)
    except:
        pass