def add_gd_download(link, listener, is_gdtot): res, size, name, files = GoogleDriveHelper().helper(link) if res != "": return sendMessage(res, listener.bot, listener.update) if STOP_DUPLICATE and not listener.isLeech: LOGGER.info('Checking File/Folder if already in Drive...') if listener.isZip: gname = name + ".zip" elif listener.extract: try: gname = get_base_name(name) except: gname = None if gname is not None: gmsg, button = GoogleDriveHelper().drive_list(gname, True) if gmsg: msg = "File/Folder is already available in Drive.\nHere are the search results:" return sendMarkup(msg, listener.bot, listener.update, button) if STORAGE_THRESHOLD is not None: acpt = check_storage_threshold(size, True) if not acpt: msg = f'You must leave {STORAGE_THRESHOLD}GB free storage.' msg += f'\nYour File/Folder size is {get_readable_file_size(size)}' return sendMessage(msg, listener.bot, listener.update) if ZIP_UNZIP_LIMIT is not None: LOGGER.info('Checking File/Folder Size...') if size > ZIP_UNZIP_LIMIT * 1024**3: msg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(size)}.' return sendMessage(msg, listener.bot, listener.update) LOGGER.info(f"Download Name: {name}") drive = GoogleDriveHelper(name, listener) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) download_status = GdDownloadStatus(drive, size, listener, gid) with download_dict_lock: download_dict[listener.uid] = download_status sendStatusMessage(listener.update, listener.bot) drive.download(link) if is_gdtot: drive.deletefile(link)
def countNode(update, context): args = update.message.text.split(" ", maxsplit=1) reply_to = update.message.reply_to_message link = '' if len(args) > 1: link = args[1] if update.message.from_user.username: tag = f"@{update.message.from_user.username}" else: tag = update.message.from_user.mention_html( update.message.from_user.first_name) if reply_to is not None: if len(link) == 0: link = reply_to.text if reply_to.from_user.username: tag = f"@{reply_to.from_user.username}" else: tag = reply_to.from_user.mention_html( reply_to.from_user.first_name) gdtot_link = is_gdtot_link(link) if gdtot_link: try: link = gdtot(link) except DirectDownloadLinkException as e: return sendMessage(str(e), context.bot, update) if is_gdrive_link(link): msg = sendMessage(f"Counting: <code>{link}</code>", context.bot, update) gd = GoogleDriveHelper() result = gd.count(link) deleteMessage(context.bot, msg) cc = f'\n\n<b>cc: </b>{tag}' sendMessage(result + cc, context.bot, update) if gdtot_link: gd.deletefile(link) else: sendMessage( 'Send Gdrive link along with command or by replying to the link by command', context.bot, update)
def add_gd_download(link: str, listener, gdtot): res, size, name, files = GoogleDriveHelper().helper(link) if res != "": sendMessage(res, listener.bot, listener.update) return if ZIP_UNZIP_LIMIT is not None: LOGGER.info('Checking File/Folder Size...') if size > ZIP_UNZIP_LIMIT * 1024**3: msg = f'Failed, Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(size)}.' sendMessage(msg, listener.bot, listener.update) return LOGGER.info(f"Download Name: {name}") drive = GoogleDriveHelper(name, listener) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) download_status = GdDownloadStatus(drive, size, listener, gid) with download_dict_lock: download_dict[listener.uid] = download_status sendStatusMessage(listener.update, listener.bot) drive.download(link) if gdtot: drive.deletefile(link)
def cloneNode(update, context): args = update.message.text.split(" ", maxsplit=1) reply_to = update.message.reply_to_message if len(args) > 1: link = args[1] if update.message.from_user.username: tag = f"@{update.message.from_user.username}" else: tag = update.message.from_user.mention_html( update.message.from_user.first_name) elif reply_to is not None: link = reply_to.text if reply_to.from_user.username: tag = f"@{reply_to.from_user.username}" else: tag = reply_to.from_user.mention_html( reply_to.from_user.first_name) else: link = '' gdtot_link = is_gdtot_link(link) if gdtot_link: try: msg = sendMessage(f"Processing: <code>{link}</code>", context.bot, update) link = gdtot(link) deleteMessage(context.bot, msg) except DirectDownloadLinkException as e: deleteMessage(context.bot, msg) return sendMessage(str(e), context.bot, update) if is_gdrive_link(link): gd = GoogleDriveHelper() res, size, name, files = gd.helper(link) if res != "": return sendMessage(res, context.bot, update) if STOP_DUPLICATE: LOGGER.info('Checking File/Folder if already in Drive...') smsg, button = gd.drive_list(name, True, True) if smsg: msg3 = "File/Folder is already available in Drive.\nHere are the search results:" sendMarkup(msg3, context.bot, update, button) if gdtot_link: gd.deletefile(link) return if CLONE_LIMIT is not None: LOGGER.info('Checking File/Folder Size...') if size > CLONE_LIMIT * 1024**3: msg2 = f'Failed, Clone limit is {CLONE_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(size)}.' return sendMessage(msg2, context.bot, update) if files <= 10: msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update) result, button = gd.clone(link) deleteMessage(context.bot, msg) else: drive = GoogleDriveHelper(name) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) clone_status = CloneStatus(drive, size, update, gid) with download_dict_lock: download_dict[update.message.message_id] = clone_status sendStatusMessage(update, context.bot) result, button = drive.clone(link) with download_dict_lock: del download_dict[update.message.message_id] count = len(download_dict) try: if count == 0: Interval[0].cancel() del Interval[0] delete_all_messages() else: update_all_messages() except IndexError: pass cc = f'\n\n<b>cc: </b>{tag}' if button in ["cancelled", ""]: sendMessage(f"{tag} {result}", context.bot, update) else: sendMarkup(result + cc, context.bot, update, button) if gdtot_link: gd.deletefile(link) else: sendMessage( 'Send Gdrive or gdtot link along with command or by replying to the link by command', context.bot, update)