async def echo(bot, update): # logger.info(update) TRChatBase(update.from_user.id, update.text, "/echo") # bot.send_chat_action( # chat_id=update.chat.id, # action="typing" # ) logger.info(update.from_user) if str(update.from_user.id) in Config.BANNED_USERS: await bot.send_message( chat_id=update.chat.id, text=Translation.ABUSIVE_USERS, reply_to_message_id=update.message_id, disable_web_page_preview=True, parse_mode=pyrogram.ParseMode.HTML ) return url = update.text if "http" in url: if "|" in url: url, file_name = url.split("|") url = url.strip() # https://stackoverflow.com/a/761825/4723940 file_name = file_name.strip() logger.info(url) logger.info(file_name) else: for entity in update.entities: if entity.type == "text_link": url = entity.url elif entity.type == "url": o = entity.offset l = entity.length url = url[o:o + l] try: if ("hotstar.com" in url) and (Config.HTTP_PROXY != ""): command_to_exec = [ "youtube-dl", "--no-warnings", "--youtube-skip-dash-manifest", "-j", url, "--proxy", Config.HTTP_PROXY ] else: command_to_exec = [ "youtube-dl", "--no-warnings", "--youtube-skip-dash-manifest", "-j", url ] logger.info(command_to_exec) t_response = subprocess.check_output( command_to_exec, stderr=subprocess.STDOUT) # https://github.com/rg3/youtube-dl/issues/2630#issuecomment-38635239 except subprocess.CalledProcessError as exc: # print("Status : FAIL", exc.returncode, exc.output) await bot.send_message( chat_id=update.chat.id, text=exc.output.decode("UTF-8"), reply_to_message_id=update.message_id ) else: # logger.info(t_response) x_reponse = t_response.decode("UTF-8") response_json = json.loads(x_reponse) save_ytdl_json_path = Config.DOWNLOAD_LOCATION + \ "/" + str(update.from_user.id) + ".json" with open(save_ytdl_json_path, "w", encoding="utf8") as outfile: json.dump(response_json, outfile, ensure_ascii=False) # logger.info(response_json) inline_keyboard = [] duration = None if "duration" in response_json: duration = response_json["duration"] if "formats" in response_json: for formats in response_json["formats"]: format_id = formats.get("format_id") format_string = formats.get("format_note") if format_string is None: format_string = formats.get("format") format_ext = formats.get("ext") approx_file_size = "" if "filesize" in formats: approx_file_size = humanbytes(formats["filesize"]) cb_string_video = "{}|{}|{}".format( "video", format_id, format_ext) cb_string_file = "{}|{}|{}".format( "file", format_id, format_ext) if format_string is not None and not "audio only" in format_string: ikeyboard = [ pyrogram.InlineKeyboardButton( "S" + format_ext + "Video [" + format_string + "] ( " + approx_file_size + " )", callback_data=(cb_string_video).encode("UTF-8") ), pyrogram.InlineKeyboardButton( "D" + format_ext + "File [" + format_string + "] ( " + approx_file_size + " )", callback_data=(cb_string_file).encode("UTF-8") ) ] if duration is not None and duration <= 30: cb_string_video_message = "{}|{}|{}".format( "vm", format_id, format_ext) ikeyboard.append( pyrogram.InlineKeyboardButton( "VMessage [" + format_string + "] ( " + approx_file_size + " )", callback_data=( cb_string_video_message).encode("UTF-8") ) ) else: # special weird case :\ ikeyboard = [ pyrogram.InlineKeyboardButton( "SVideo [" + "] ( " + approx_file_size + " )", callback_data=(cb_string_video).encode("UTF-8") ), pyrogram.InlineKeyboardButton( "DFile [" + "] ( " + approx_file_size + " )", callback_data=(cb_string_file).encode("UTF-8") ) ] inline_keyboard.append(ikeyboard) if duration is not None: cb_string_64 = "{}|{}|{}".format("audio", "64k", "mp3") cb_string_128 = "{}|{}|{}".format("audio", "128k", "mp3") cb_string = "{}|{}|{}".format("audio", "320k", "mp3") inline_keyboard.append([ pyrogram.InlineKeyboardButton( "MP3 " + "(" + "64 kbps" + ")", callback_data=cb_string_64.encode("UTF-8")), pyrogram.InlineKeyboardButton( "MP3 " + "(" + "128 kbps" + ")", callback_data=cb_string_128.encode("UTF-8")) ]) inline_keyboard.append([ pyrogram.InlineKeyboardButton( "MP3 " + "(" + "320 kbps" + ")", callback_data=cb_string.encode("UTF-8")) ]) else: format_id = response_json["format_id"] format_ext = response_json["ext"] tg_send_type = "file" if duration is not None: tg_send_type = "video" cb_string = "{}|{}|{}".format( tg_send_type, format_id, format_ext) inline_keyboard.append([ pyrogram.InlineKeyboardButton( "Download", callback_data=cb_string.encode("UTF-8")) ]) reply_markup = pyrogram.InlineKeyboardMarkup(inline_keyboard) # logger.info(reply_markup) thumbnail = Config.DEF_THUMB_NAIL_VID_S thumbnail_image = Config.DEF_THUMB_NAIL_VID_S if "thumbnail" in response_json: if response_json["thumbnail"] is not None: thumbnail = response_json["thumbnail"] thumbnail_image = response_json["thumbnail"] thumb_image_path = DownLoadFile( thumbnail_image, Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg", Config.CHUNK_SIZE, None, # bot, Translation.DOWNLOAD_START, update.message_id, update.chat.id ) await bot.send_message( chat_id=update.chat.id, text=Translation.FORMAT_SELECTION.format(thumbnail), reply_markup=reply_markup, parse_mode=pyrogram.ParseMode.HTML, reply_to_message_id=update.message_id ) else: await bot.send_message( chat_id=update.chat.id, text=Translation.INVALID_UPLOAD_BOT_URL_FORMAT, reply_to_message_id=update.message_id )
def get_link(bot, update): TRChatBase(update.from_user.id, update.text, "transfersh") if str(update.from_user.id) in Config.BANNED_USERS: bot.send_message(chat_id=update.chat.id, text=Translation.ABUSIVE_USERS, reply_to_message_id=update.message_id, disable_web_page_preview=True, parse_mode=pyrogram.ParseMode.HTML) return logger.info(update.from_user) if update.reply_to_message is not None: reply_message = update.reply_to_message download_location = Config.DOWNLOAD_LOCATION + "/" start = datetime.now() a = bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() after_download_file_name = bot.download_media( message=reply_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a.message_id, update.chat.id, c_time)) download_extension = after_download_file_name.rsplit(".", 1)[-1] upload_name = after_download_file_name.rsplit("/", 1)[-1] upload_name = upload_name.replace(" ", "_") bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) end_one = datetime.now() if str(update.from_user.id) in Config.G_DRIVE_AUTH_DRQ: gauth = Config.G_DRIVE_AUTH_DRQ[str(update.from_user.id)] # Create GoogleDrive instance with authenticated GoogleAuth instance. drive = GoogleDrive(gauth) file_inance = drive.CreateFile() # Read file and set it as a content of this instance. file_inance.SetContentFile(after_download_file_name) file_inance.Upload() # Upload the file. end_two = datetime.now() time_taken_for_upload = (end_two - end_one).seconds logger.info(file_inance) adfulurl = file_inance.webContentLink max_days = 0 else: url = "https://transfer.sh/{}".format(upload_name) max_days = "3" command_to_exec = [ "curl", # "-H", 'Max-Downloads: 1', "-H", 'Max-Days: 5', # + max_days + '', "--upload-file", after_download_file_name, url ] bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) try: logger.info(command_to_exec) t_response = subprocess.check_output(command_to_exec, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: logger.info("Status : FAIL", exc.returncode, exc.output) bot.edit_message_text(chat_id=update.chat.id, text=exc.output.decode("UTF-8"), message_id=a.message_id) return False else: logger.info(t_response) t_response_arry = t_response.decode("UTF-8").split( "\n")[-1].strip() #shorten_api_url = "http://ouo.io/api/{}?s={}".format(Config.OUO_IO_API_KEY, t_response_arry) #adfulurl = requests.get(shorten_api_url).text bot.edit_message_text(chat_id=update.chat.id, text=Translation.AFTER_GET_DL_LINK.format( t_response_arry, max_days), parse_mode=pyrogram.ParseMode.HTML, message_id=a.message_id, disable_web_page_preview=True) try: os.remove(after_download_file_name) except: pass else: bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_GET_LINK, reply_to_message_id=update.message_id)
async def get_link(bot, update): if update.from_user.id not in Config.AUTH_USERS: await bot.delete_messages(chat_id=update.chat.id, message_ids=update.message_id, revoke=True) return TRChatBase(update.from_user.id, update.text, "getlink") logger.info(update.from_user) if update.reply_to_message is not None: reply_message = update.reply_to_message print(reply_message) download_location = Config.DOWNLOAD_LOCATION + "/" start = datetime.now() a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() after_download_file_name = await bot.download_media( message=reply_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a, c_time)) download_extension = after_download_file_name.rsplit(".", 1)[-1] await bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) end_one = datetime.now() url = "https://transfer.sh/{}.{}".format(str(update.from_user.id), str(download_extension)) max_days = "5" command_to_exec = [ "curl", # "-H", 'Max-Downloads: 1', "-H", 'Max-Days: 5', # + max_days + '', "--upload-file", after_download_file_name, url ] await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) try: logger.info(command_to_exec) t_response = subprocess.check_output(command_to_exec, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: logger.info("Status : FAIL", exc.returncode, exc.output) await bot.edit_message_text(chat_id=update.chat.id, text=exc.output.decode("UTF-8"), message_id=a.message_id) return False else: logger.info(t_response) t_response_arry = t_response.decode("UTF-8").split( "\n")[-1].strip() await bot.edit_message_text(chat_id=update.chat.id, text=Translation.AFTER_GET_DL_LINK.format( t_response_arry, max_days), parse_mode="html", message_id=a.message_id, disable_web_page_preview=True) try: os.remove(after_download_file_name) except: pass else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_GET_LINK, reply_to_message_id=update.message_id)
async def unzip(bot, update): if update.from_user.id not in Config.AUTH_USERS: await bot.delete_messages(chat_id=update.chat.id, message_ids=update.message_id, revoke=True) return TRChatBase(update.from_user.id, update.text, "unzip") saved_file_path = Config.DOWNLOAD_LOCATION + \ "/" + str(update.from_user.id) + ".unzip.zip" if os.path.exists(saved_file_path): os.remove(saved_file_path) reply_message = update.reply_to_message if ((reply_message is not None) and (reply_message.document is not None) and (reply_message.document.file_name.endswith( Translation.UNZIP_SUPPORTED_EXTENSIONS))): a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() try: await bot.download_media(message=reply_message, file_name=saved_file_path, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a, c_time)) except (ValueError) as e: await bot.edit_message_text(chat_id=update.chat.id, text=str(e), message_id=a.message_id) else: await bot.edit_message_text(chat_id=update.chat.id, text=Translation.SAVED_RECVD_DOC_FILE, message_id=a.message_id) extract_dir_path = Config.DOWNLOAD_LOCATION + \ "/" + str(update.from_user.id) + "zipped" + "/" if not os.path.isdir(extract_dir_path): os.makedirs(extract_dir_path) await bot.edit_message_text( chat_id=update.chat.id, text=Translation.EXTRACT_ZIP_INTRO_THREE, message_id=a.message_id) try: command_to_exec = [ "7z", "e", "-o" + extract_dir_path, saved_file_path ] # https://stackoverflow.com/a/39629367/4723940 logger.info(command_to_exec) t_response = subprocess.check_output(command_to_exec, stderr=subprocess.STDOUT) # https://stackoverflow.com/a/26178369/4723940 except: try: os.remove(saved_file_path) shutil.rmtree(extract_dir_path) except: pass await bot.edit_message_text( chat_id=update.chat.id, text=Translation.EXTRACT_ZIP_ERRS_OCCURED, disable_web_page_preview=True, parse_mode="html", message_id=a.message_id) else: os.remove(saved_file_path) inline_keyboard = [] zip_file_contents = os.listdir(extract_dir_path) i = 0 for current_file in zip_file_contents: cb_string = "ZIP:{}:ZIP".format(str(i)) inline_keyboard.append([ pyrogram.InlineKeyboardButton( current_file, callback_data=cb_string.encode("UTF-8")) ]) i = i + 1 cb_string = "ZIP:{}:ZIP".format("ALL") inline_keyboard.append([ pyrogram.InlineKeyboardButton( "Upload All Files", callback_data=cb_string.encode("UTF-8")) ]) cb_string = "ZIP:{}:ZIP".format("NONE") inline_keyboard.append([ pyrogram.InlineKeyboardButton( "Cancel", callback_data=cb_string.encode("UTF-8")) ]) reply_markup = pyrogram.InlineKeyboardMarkup(inline_keyboard) await bot.edit_message_text( chat_id=update.chat.id, text=Translation.EXTRACT_ZIP_STEP_TWO, message_id=a.message_id, reply_markup=reply_markup, ) else: await bot.send_message(chat_id=update.chat.id, text=Translation.EXTRACT_ZIP_INTRO_ONE, reply_to_message_id=update.message_id)
async def start_user(bot, update): # logger.info(update) TRChatBase(update.from_user.id, update.text, "/start")
async def echo(bot, update): if update.from_user.id not in Config.AUTH_USERS: await bot.delete_messages(chat_id=update.chat.id, message_ids=update.message_id, revoke=True) return # logger.info(update) TRChatBase(update.from_user.id, update.text, "/echo") # await bot.send_chat_action( # chat_id=update.chat.id, # action="typing" # ) logger.info(update.from_user) url = update.text youtube_dl_username = None youtube_dl_password = None file_name = None if "|" in url: url_parts = url.split("|") if len(url_parts) == 2: url = url_parts[0] file_name = url_parts[1] elif len(url_parts) == 4: url = url_parts[0] file_name = url_parts[1] youtube_dl_username = url_parts[2] youtube_dl_password = url_parts[3] else: for entity in update.entities: if entity.type == "text_link": url = entity.url elif entity.type == "url": o = entity.offset l = entity.length url = url[o:o + l] if url is not None: url = url.strip() if file_name is not None: file_name = file_name.strip() # https://stackoverflow.com/a/761825/4723940 if youtube_dl_username is not None: youtube_dl_username = youtube_dl_username.strip() if youtube_dl_password is not None: youtube_dl_password = youtube_dl_password.strip() logger.info(url) logger.info(file_name) else: for entity in update.entities: if entity.type == "text_link": url = entity.url elif entity.type == "url": o = entity.offset l = entity.length url = url[o:o + l] if Config.HTTP_PROXY != "": command_to_exec = [ "youtube-dl", "--no-warnings", "--youtube-skip-dash-manifest", "-j", url, "--proxy", Config.HTTP_PROXY ] else: command_to_exec = [ "youtube-dl", "--no-warnings", "--youtube-skip-dash-manifest", "-j", url ] if "hotstar" in url: command_to_exec.append("--geo-bypass-country") command_to_exec.append("IN") if youtube_dl_username is not None: command_to_exec.append("--username") command_to_exec.append(youtube_dl_username) if youtube_dl_password is not None: command_to_exec.append("--password") command_to_exec.append(youtube_dl_password) # logger.info(command_to_exec) process = await asyncio.create_subprocess_exec( *command_to_exec, # stdout must a pipe to be accessible as process.stdout stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) # Wait for the subprocess to finish stdout, stderr = await process.communicate() e_response = stderr.decode().strip() # logger.info(e_response) t_response = stdout.decode().strip() # logger.info(t_response) # https://github.com/rg3/youtube-dl/issues/2630#issuecomment-38635239 if e_response and "nonnumeric port" not in e_response: # logger.warn("Status : FAIL", exc.returncode, exc.output) error_message = e_response.replace( "please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.", "") if "This video is only available for registered users." in error_message: error_message += Translation.SET_CUSTOM_USERNAME_PASSWORD await bot.send_message(chat_id=update.chat.id, text=Translation.NO_VOID_FORMAT_FOUND.format( str(error_message)), reply_to_message_id=update.message_id, parse_mode="html", disable_web_page_preview=True) return False if t_response: # logger.info(t_response) x_reponse = t_response if "\n" in x_reponse: x_reponse, _ = x_reponse.split("\n") response_json = json.loads(x_reponse) save_ytdl_json_path = Config.DOWNLOAD_LOCATION + \ "/" + str(update.from_user.id) + ".json" with open(save_ytdl_json_path, "w", encoding="utf8") as outfile: json.dump(response_json, outfile, ensure_ascii=False) # logger.info(response_json) inline_keyboard = [] duration = None if "duration" in response_json: duration = response_json["duration"] if "formats" in response_json: for formats in response_json["formats"]: format_id = formats.get("format_id") format_string = formats.get("format_note") if format_string is None: format_string = formats.get("format") format_ext = formats.get("ext") approx_file_size = "" if "filesize" in formats: approx_file_size = humanbytes(formats["filesize"]) cb_string_video = "{}|{}|{}".format("video", format_id, format_ext) cb_string_file = "{}|{}|{}".format("file", format_id, format_ext) if format_string is not None and not "audio only" in format_string: ikeyboard = [ pyrogram.InlineKeyboardButton( "S " + format_string + " video " + approx_file_size + " ", callback_data=(cb_string_video).encode("UTF-8")), pyrogram.InlineKeyboardButton( "D " + format_ext + " " + approx_file_size + " ", callback_data=(cb_string_file).encode("UTF-8")) ] """if duration is not None: cb_string_video_message = "{}|{}|{}".format( "vm", format_id, format_ext) ikeyboard.append( pyrogram.InlineKeyboardButton( "VM", callback_data=( cb_string_video_message).encode("UTF-8") ) )""" else: # special weird case :\ ikeyboard = [ pyrogram.InlineKeyboardButton( "SVideo [" + "] ( " + approx_file_size + " )", callback_data=(cb_string_video).encode("UTF-8")), pyrogram.InlineKeyboardButton( "DFile [" + "] ( " + approx_file_size + " )", callback_data=(cb_string_file).encode("UTF-8")) ] inline_keyboard.append(ikeyboard) if duration is not None: cb_string_64 = "{}|{}|{}".format("audio", "64k", "mp3") cb_string_128 = "{}|{}|{}".format("audio", "128k", "mp3") cb_string = "{}|{}|{}".format("audio", "320k", "mp3") inline_keyboard.append([ pyrogram.InlineKeyboardButton( "MP3 " + "(" + "64 kbps" + ")", callback_data=cb_string_64.encode("UTF-8")), pyrogram.InlineKeyboardButton( "MP3 " + "(" + "128 kbps" + ")", callback_data=cb_string_128.encode("UTF-8")) ]) inline_keyboard.append([ pyrogram.InlineKeyboardButton( "MP3 " + "(" + "320 kbps" + ")", callback_data=cb_string.encode("UTF-8")) ]) else: format_id = response_json["format_id"] format_ext = response_json["ext"] cb_string_file = "{}|{}|{}".format("file", format_id, format_ext) cb_string_video = "{}|{}|{}".format("video", format_id, format_ext) inline_keyboard.append([ pyrogram.InlineKeyboardButton( "SVideo", callback_data=(cb_string_video).encode("UTF-8")), pyrogram.InlineKeyboardButton( "DFile", callback_data=(cb_string_file).encode("UTF-8")) ]) cb_string_file = "{}={}={}".format("file", format_id, format_ext) cb_string_video = "{}={}={}".format("video", format_id, format_ext) inline_keyboard.append([ pyrogram.InlineKeyboardButton( "video", callback_data=(cb_string_video).encode("UTF-8")), pyrogram.InlineKeyboardButton( "file", callback_data=(cb_string_file).encode("UTF-8")) ]) reply_markup = pyrogram.InlineKeyboardMarkup(inline_keyboard) # logger.info(reply_markup) thumbnail = Config.DEF_THUMB_NAIL_VID_S thumbnail_image = Config.DEF_THUMB_NAIL_VID_S if "thumbnail" in response_json: if response_json["thumbnail"] is not None: thumbnail = response_json["thumbnail"] thumbnail_image = response_json["thumbnail"] thumb_image_path = DownLoadFile( thumbnail_image, Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg", Config.CHUNK_SIZE, None, # bot, Translation.DOWNLOAD_START, update.message_id, update.chat.id) await bot.send_message( chat_id=update.chat.id, text=Translation.FORMAT_SELECTION.format(thumbnail) + "\n" + Translation.SET_CUSTOM_USERNAME_PASSWORD, reply_markup=reply_markup, parse_mode="html", reply_to_message_id=update.message_id) else: # fallback for nonnumeric port a.k.a seedbox.io inline_keyboard = [] cb_string_file = "{}={}={}".format("file", "LFO", "NONE") cb_string_video = "{}={}={}".format("video", "OFL", "ENON") inline_keyboard.append([ pyrogram.InlineKeyboardButton( "SVideo", callback_data=(cb_string_video).encode("UTF-8")), pyrogram.InlineKeyboardButton( "DFile", callback_data=(cb_string_file).encode("UTF-8")) ]) reply_markup = pyrogram.InlineKeyboardMarkup(inline_keyboard) await bot.send_message(chat_id=update.chat.id, text=Translation.FORMAT_SELECTION.format(""), reply_markup=reply_markup, parse_mode="html", reply_to_message_id=update.message_id)
async def convert_to_video(bot, update): if update.from_user.id in Config.BANNED_USERS: await bot.send_message( chat_id=update.chat.id, text=Translation.BANNED_USER_TEXT, reply_to_message_id=update.message_id ) return TRChatBase(update.from_user.id, update.text, "c2f") if update.reply_to_message is not None: description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message( chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id ) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=( Translation.DOWNLOAD_START, a, c_time ) ) if the_real_download_location is not None: bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id ) # don't care about the extension # await bot.edit_message_text( # text=Translation.UPLOAD_START, # chat_id=update.chat.id, # message_id=a.message_id # ) logger.info(the_real_download_location) # get the correct width, height, and duration for videos greater than 10MB # ref: message from @BotSupport width = 0 height = 0 duration = 0 metadata = extractMetadata(createParser(the_real_download_location)) if metadata.has("duration"): duration = metadata.get('duration').seconds thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): thumb_image_path = None # try to upload file c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=the_real_download_location, caption=description, # reply_markup=reply_markup, thumb=thumb_image_path, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a, c_time ) ) try: os.remove(the_real_download_location) # os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True ) else: await bot.send_message( chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_C2V, reply_to_message_id=update.message_id )
def rename_doc(bot, update): TRChatBase(update.from_user.id, update.text, "rename") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" a = bot.send_message(chat_id=update.from_user.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) the_real_download_location = bot.download_media( message=update.reply_to_message, file_name=download_location) if the_real_download_location is not None: bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.from_user.id, message_id=a.message_id) if "IndianMovie" in the_real_download_location: bot.edit_message_text(text=Translation.RENAME_403_ERR, chat_id=update.from_user.id, message_id=a.message_id) return new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.from_user.id, message_id=a.message_id) logger.info(the_real_download_location) thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): thumb_image_path = None else: # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 new_img = img.resize((90, 90)) new_img.save(thumb_image_path, "JPEG", optimize=True) bot.send_document( chat_id=update.from_user.id, document=new_file_name, thumb=thumb_image_path, caption=description, # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id) try: os.remove(the_real_download_location) os.remove(thumb_image_path) except: pass bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG_WITH_TS, chat_id=update.from_user.id, message_id=a.message_id, disable_web_page_preview=True) else: bot.send_message(chat_id=update.from_user.id, text=Translation.REPLY_TO_DOC_FOR_RENAME_FILE, reply_to_message_id=update.message_id)
async def rename_doc(bot, update): if update.from_user.id in Config.BANNED_USERS: await bot.delete_messages(chat_id=update.chat.id, message_ids=update.message_id, revoke=True) return TRChatBase(update.from_user.id, update.text, "/echo") update_channel = Config.UPDATE_CHANNEL if update_channel: try: user = await bot.get_chat_member(update_channel, update.chat.id) if user.status == "kicked": await update.reply_text( "🤠Sorry Mate, You're **B A N N E D **") return except UserNotParticipant: #await update.reply_text(f"Join @{update_channel} To Use Me") await update.reply_text( text="**Join My Updates Channel to use ME 😎 ðŸ¤**", reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text="Join My Updates Channel", url=f"https://t.me/{update_channel}") ]])) return except Exception: await update.reply_text( "Oops,I Think You're Already Member,Please Revoke By Leaving The Channel." ) return TRChatBase(update.from_user.id, update.text, "change") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) if len(file_name) > 70: await update.reply_text( Translation.IFLONG_FILE_NAME.format(alimit="70", num=len(file_name))) return description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a, c_time)) if the_real_download_location is not None: try: await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) except: pass if "IndianMovie" in the_real_download_location: await bot.edit_message_text(text=Translation.RENAME_403_ERR, chat_id=update.chat.id, message_id=a.message_id) return new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) logger.info(the_real_download_location) thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): mes = await thumb(update.from_user.id) if mes != None: m = await bot.get_messages(update.chat.id, mes.msg_id) await m.download(file_name=thumb_image_path) thumb_image_path = thumb_image_path else: thumb_image_path = None else: width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=new_file_name, thumb=thumb_image_path, caption=file_name + description, # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, a, c_time)) try: os.remove(new_file_name) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_RENAME_FILE, reply_to_message_id=update.message_id)
async def rename_doc(bot, update): TRChatBase(update.from_user.id, update.text, "rename") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) if len(file_name) > 128: await update.reply_text( Translation.IFLONG_FILE_NAME.format(alimit="128", num=len(file_name))) return caption_str = "" caption_str += "<b>" caption_str += file_name caption_str += "</b>" if Config.CHANNEL_URL is not None: caption_str += "\n\nJoin: " caption_str += "<a href='" caption_str += f"{Config.CHANNEL_URL}" caption_str += "'>" caption_str += f"{Config.CHANNEL_URL}" caption_str += "</a>" download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a, c_time)) if the_real_download_location is not None: try: await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) except: pass if "IndianMovie" in the_real_download_location: await bot.edit_message_text(text=Translation.RENAME_403_ERR, chat_id=update.chat.id, message_id=a.message_id) return new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) # await bot.edit_message_text( # text=Translation.UPLOAD_START, # chat_id=update.chat.id, # message_id=a.message_id # ) logger.info(the_real_download_location) thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): logger.info('setting thumb.jpg as thumbnail') thumb_image_path = "thumb.jpg" else: width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=new_file_name, thumb=thumb_image_path, caption=caption_str, # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, a, c_time)) try: os.remove(new_file_name) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_RENAME_FILE, reply_to_message_id=update.message_id)
def get_link(bot, update): TRChatBase(update.from_user.id, update.text, "getlink") if str(update.from_user.id) in Config.BANNED_USERS: bot.send_message( chat_id=update.chat.id, text=Translation.ABUSIVE_USERS, reply_to_message_id=update.message_id, disable_web_page_preview=True, parse_mode=pyrogram.ParseMode.HTML ) return logger.info(update.from_user) if update.reply_to_message is not None: reply_message = update.reply_to_message download_location = Config.DOWNLOAD_LOCATION + "/" start = datetime.now() a = bot.send_message( chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id ) c_time = time.time() after_download_file_name = bot.download_media( message=reply_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a.message_id, update.chat.id, c_time) ) download_extension = after_download_file_name.rsplit(".", 1)[-1] bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id ) end_one = datetime.now() url = "https://transfer.sh/{}.{}".format(str(update.from_user.id), str(download_extension)) max_days = "5" command_to_exec = [ "curl", # "-H", 'Max-Downloads: 1', "-H", 'Max-Days: 5', # + max_days + '', "--upload-file", after_download_file_name, url ] bot.edit_message_text( text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id ) try: logger.info(command_to_exec) t_response = subprocess.check_output(command_to_exec, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: logger.info("Status : FAIL", exc.returncode, exc.output) bot.edit_message_text( chat_id=update.chat.id, text=exc.output.decode("UTF-8"), message_id=a.message_id ) return False else: logger.info(t_response) t_response_arry = t_response.decode("UTF-8").split("\n")[-1].strip() shorten_api_url = "http://ouo.io/api/{}?s={}".format(Config.OUO_IO_API_KEY, t_response_arry) adfulurl = requests.get(shorten_api_url).text bot.edit_message_text( chat_id=update.chat.id, text=Translation.AFTER_GET_DL_LINK.format(adfulurl, max_days), parse_mode=pyrogram.ParseMode.HTML, message_id=a.message_id, disable_web_page_preview=True ) try: os.remove(after_download_file_name) except: pass else: bot.send_message( chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_GET_LINK, reply_to_message_id=update.message_id )
async def kl35thumb(bot, update): # logger.info(update) TRChatBase(update.from_user.id, update.photo, "/bots")
async def upgrade(bot, update): # logger.info(update) TRChatBase(update.from_user.id, update.text, "/upgrade")
async def rename_video(bot, update): if update.from_user.id in Config.BANNED_USERS: await bot.delete_messages(chat_id=update.chat.id, message_ids=update.message_id, revoke=True) return TRChatBase(update.from_user.id, update.text, "rename") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) if len(file_name) > 64: await update.reply_text( Translation.IFLONG_FILE_NAME.format(alimit="64", num=len(file_name))) return description = file_name + Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" b = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, b, c_time)) if the_real_download_location is not None: try: await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=b.message_id) except: pass new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=b.message_id) logger.info(the_real_download_location) width = 0 height = 0 duration = 0 metadata = extractMetadata(createParser(new_file_name)) if metadata.has("duration"): duration = metadata.get('duration').seconds thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): thumb_image_path = await take_screen_shot( new_file_name, os.path.dirname(new_file_name), random.randint(0, duration - 1)) else: width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails c_time = time.time() await bot.send_video( chat_id=update.chat.id, video=new_file_name, duration=duration, thumb=thumb_image_path, caption=description, # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, b, c_time)) try: os.remove(new_file_name) #os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=b.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_RENAME_FILE, reply_to_message_id=update.message_id)
async def trim(bot, update): TRChatBase(update.from_user.id, update.text, "trim") if str(update.from_user.id) not in Config.SUPER7X_DLBOT_USERS: await bot.send_message( chat_id=update.chat.id, text=Translation.NOT_AUTH_USER_TEXT, reply_to_message_id=update.message_id ) return saved_file_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".FFMpegRoBot.mkv" if os.path.exists(saved_file_path): a = await bot.send_message( chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id ) commands = update.command if len(commands) == 3: # output should be video cmd, start_time, end_time = commands o = await cult_small_video(saved_file_path, Config.DOWNLOAD_LOCATION, start_time, end_time) logger.info(o) if o is not None: await bot.edit_message_text( chat_id=update.chat.id, text=Translation.UPLOAD_START, message_id=a.message_id ) c_time = time.time() await bot.send_video( chat_id=update.chat.id, video=o, # caption=description, # duration=duration, # width=width, # height=height, supports_streaming=True, # reply_markup=reply_markup, # thumb=thumb_image_path, reply_to_message_id=update.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a.message_id, update.chat.id, c_time ) ) os.remove(o) await bot.edit_message_text( chat_id=update.chat.id, text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, disable_web_page_preview=True, message_id=a.message_id ) elif len(commands) == 2: # output should be screenshot cmd, start_time = commands o = await take_screen_shot(saved_file_path, Config.DOWNLOAD_LOCATION, start_time) logger.info(o) if o is not None: await bot.edit_message_text( chat_id=update.chat.id, text=Translation.UPLOAD_START, message_id=a.message_id ) c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=o, # thumb=thumb_image_path, # caption=description, # reply_markup=reply_markup, reply_to_message_id=update.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a.message_id, update.chat.id, c_time ) ) c_time = time.time() await bot.send_photo( chat_id=update.chat.id, photo=o, # caption=Translation.CUSTOM_CAPTION_UL_FILE, reply_to_message_id=update.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a.message_id, update.chat.id, c_time ) ) os.remove(o) await bot.edit_message_text( chat_id=update.chat.id, text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, disable_web_page_preview=True, message_id=a.message_id ) else: await bot.edit_message_text( chat_id=update.chat.id, text=Translation.FF_MPEG_RO_BOT_RE_SURRECT_ED, message_id=a.message_id ) else: # reply help message await bot.send_message( chat_id=update.chat.id, text=Translation.FF_MPEG_RO_BOT_STEP_TWO_TO_ONE, reply_to_message_id=update.message_id )
def get_link(bot, update): TRChatBase(update.from_user.id, update.text, "getlink5") if str(update.from_user.id) in Config.BANNED_USERS: bot.send_message( chat_id=update.chat.id, text=Translation.ABUSIVE_USERS, reply_to_message_id=update.message_id, disable_web_page_preview=True, parse_mode=pyrogram.ParseMode.HTML ) return logger.info(update.from_user) if update.reply_to_message is not None: reply_message = update.reply_to_message download_location = Config.DOWNLOAD_LOCATION + "/" start = datetime.now() a = bot.send_message( chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id ) c_time = time.time() after_download_file_name = bot.download_media( message=reply_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a.message_id, update.chat.id, c_time) ) download_extension = after_download_file_name.rsplit(".", 1)[-1] bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id ) end_one = datetime.now() if str(update.from_user.id) in Config.G_DRIVE_AUTH_DRQ: gauth = Config.G_DRIVE_AUTH_DRQ[str(update.from_user.id)] # Create GoogleDrive instance with authenticated GoogleAuth instance. drive = GoogleDrive(gauth) file_inance = drive.CreateFile() # Read file and set it as a content of this instance. file_inance.SetContentFile(after_download_file_name) file_inance.Upload() # Upload the file. end_two = datetime.now() time_taken_for_upload = (end_two - end_one).seconds logger.info(file_inance) adfulurl = file_inance.webContentLink max_days = 0 else: max_days = 5 verystreamLOGIN = '******' verystreamKEY = 'JcGF53rcBri' # check video extension if not after_download_file_name.lower().endswith(('.mp4', '.mkv', '.avi', '.webm', '.vob', '.mpg')): bot.edit_message_text( chat_id=update.chat.id, text="This is not a video.", message_id=a.message_id ) return False rget = rs.get("https://api.verystream.com/file/ul?login="******"&key=" + verystreamKEY) rjson = json.loads(rget.text) if rjson['status'] == 200: url = rjson['result']['url'] else: bot.edit_message_text( chat_id=update.chat.id, text="Failed to initiate the upload process.", message_id=a.message_id ) return False command_to_exec = [ "curl", "-F","file1=@"+after_download_file_name, "-H","Transfer-Encoding: chunked", url ] # {"status":200,"msg":"OK","result":{"name":"small.mp4","size":"383631","sha1":"5c5a07267317b166a218e5edb7667ccd2b5351be","content_type":"video\\/mp4","id":"h2qdQpteEk9","url":"https:\\/\\/verystream.com\\/stream\\/h2qdQpteEk9\\/small.mp4"}} bot.edit_message_text( text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id ) try: logger.info(command_to_exec) t_response = subprocess.check_output(command_to_exec, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: logger.info("Status : FAIL", exc.returncode, exc.output) bot.edit_message_text( chat_id=update.chat.id, text=exc.output.decode("UTF-8"), message_id=a.message_id ) return False else: logger.info(t_response) print ( t_response ) t_response_arry = json.loads(t_response.decode("UTF-8").split("\n")[-2].strip())['result']['url'] bot.edit_message_text( chat_id=update.chat.id, text=Translation.AFTER_GET_DL_LINK.format(t_response_arry, max_days), parse_mode=pyrogram.ParseMode.HTML, message_id=a.message_id, disable_web_page_preview=True ) try: os.remove(after_download_file_name) except: pass else: bot.send_message( chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_GET_LINK, reply_to_message_id=update.message_id )
async def DownloadStickersBot(bot, update): TRChatBase(update.from_user.id, update.text, "DownloadStickersBot") if str(update.from_user.id) in Config.BANNED_USERS: await bot.edit_message_text(chat_id=update.message.chat.id, text=Translation.ABUSIVE_USERS, message_id=update.message.message_id, disable_web_page_preview=True, parse_mode="html") return if str(update.from_user.id) not in Config.UTUBE_BOT_USERS: # restrict free users from sending more links if str(update.from_user.id) in Config.ADL_BOT_RQ: current_time = time.time() previous_time = Config.ADL_BOT_RQ[str(update.from_user.id)] Config.ADL_BOT_RQ[str(update.from_user.id)] = time.time() if round(current_time - previous_time) < Config.PROCESS_MAX_TIMEOUT: await bot.send_message(chat_id=update.chat.id, text=Translation.FREE_USER_LIMIT_Q_SZE, reply_to_message_id=update.message_id) return else: Config.ADL_BOT_RQ[str(update.from_user.id)] = time.time() logger.info(update.from_user) download_location = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + "_DownloadStickersBot_" + str( update.from_user.id) + ".png" a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) try: c_time = time.time() the_real_download_location = await bot.download_media( message=update, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a.message_id, update.chat.id, c_time)) except (ValueError) as e: await bot.edit_message_text(text=str(e), chat_id=update.chat.id, message_id=a.message_id) return False await bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=the_real_download_location, # thumb=thumb_image_path, # caption=description, # reply_markup=reply_markup, reply_to_message_id=a.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, a.message_id, update.chat.id, c_time)) await bot.send_photo( chat_id=update.chat.id, photo=the_real_download_location, # thumb=thumb_image_path, # caption=description, # reply_markup=reply_markup, reply_to_message_id=a.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, a.message_id, update.chat.id, c_time)) os.remove(the_real_download_location) await bot.edit_message_text(text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True)
async def rename_video(bot, update): if update.from_user.id in Config.BANNED_USERS: await update.reply_text("You are B A N N E D") return TRChatBase(update.from_user.id, update.text, "rename") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) new_name = file_name[:60] + file_name[-4:] description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" b = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, b, c_time)) if (the_real_download_location is not None) and (len(file_name) > 64): try: await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=b.message_id) except: pass new_file_name = download_location + new_name os.rename(the_real_download_location, new_file_name) await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=b.message_id) logger.info(the_real_download_location) thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): mes = await get_thumb(update.from_user.id) if mes != None: m = await bot.get_messages(update.chat.id, mes.msg_id) await m.download(file_name=thumb_image_path) thumb_image_path = thumb_image_path else: thumb_image_path = None else: width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails c_time = time.time() await bot.send_video( chat_id=update.chat.id, video=new_file_name, # width=width, #height=height, duration=duration, thumb=thumb_image_path, caption=description.format(file_name[:-4]), # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, b, c_time)) try: os.remove(new_file_name) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=b.message_id, disable_web_page_preview=True) if (the_real_download_location is not None) and (len(file_name) <= 64): try: await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=b.message_id) except: pass new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=b.message_id) logger.info(the_real_download_location) thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): mes = await get_thumb(update.from_user.id) if mes != None: m = await bot.get_messages(update.chat.id, mes.msg_id) await m.download(file_name=thumb_image_path) thumb_image_path = thumb_image_path else: thumb_image_path = None else: width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails c_time = time.time() await bot.send_video( chat_id=update.chat.id, video=new_file_name, #height=height, #width=width, #duration=duration, thumb=thumb_image_path, caption=description.format(file_name[:-4]), # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, b, c_time)) try: os.remove(new_file_name) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=b.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_RENAME_VIDEO, reply_to_message_id=update.message_id)
async def start(bot, update): # logger.info(update) TRChatBase(update.from_user.id, update.text, "/start") await bot.send_message(chat_id=update.chat.id, text=Translation.START_TEXT, reply_to_message_id=update.message_id)
async def echo(bot, update): if update.from_user.id in Config.BANNED_USERS: await update.reply_text("Siz B A N olgansiz 🤣🤣🤣🤣") return TRChatBase(update.from_user.id, update.text, "/echo") update_channel = Config.UPDATE_CHANNEL if update_channel: try: user = await bot.get_chat_member(update_channel, update.chat.id) if user.status == "kicked": await update.reply_text( "🤠Kechirasiz siz Ban oldingiz. **B A N N E D 🤣🤣🤣**\nIltimos Kanallarimizga obuna bo'ling: @InfoTeleUz @Bot_Owners" ) return except UserNotParticipant: #await update.reply_text(f"Join @{update_channel} To Use Me") await update.reply_text( text= "**Iltimos Kanalimizga Obuna Bo'ling. 😎 ðŸ¤**\n**Join My Updates Channel to use ME 😎 ðŸ¤**", reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text="Join My Updates Channel", url=f"https://t.me/{update_channel}") ]])) return except Exception: await update.reply_text("Something Wrong. Contact my Support Group" ) return logger.info(update.from_user) url = update.text youtube_dl_username = None youtube_dl_password = None file_name = None if "|" in url: url_parts = url.split("|") if len(url_parts) == 2: url = url_parts[0] file_name = url_parts[1] elif len(url_parts) == 4: url = url_parts[0] file_name = url_parts[1] youtube_dl_username = url_parts[2] youtube_dl_password = url_parts[3] else: for entity in update.entities: if entity.type == "text_link": url = entity.url elif entity.type == "url": o = entity.offset l = entity.length url = url[o:o + l] if url is not None: url = url.strip() if file_name is not None: file_name = file_name.strip() # https://stackoverflow.com/a/761825/4723940 if youtube_dl_username is not None: youtube_dl_username = youtube_dl_username.strip() if youtube_dl_password is not None: youtube_dl_password = youtube_dl_password.strip() logger.info(url) logger.info(file_name) else: for entity in update.entities: if entity.type == "text_link": url = entity.url elif entity.type == "url": o = entity.offset l = entity.length url = url[o:o + l] if Config.HTTP_PROXY != "": command_to_exec = [ "youtube-dl", "--no-warnings", "--youtube-skip-dash-manifest", "-j", url, "--proxy", Config.HTTP_PROXY ] else: command_to_exec = [ "youtube-dl", "--no-warnings", "--youtube-skip-dash-manifest", "-j", url ] if youtube_dl_username is not None: command_to_exec.append("--username") command_to_exec.append(youtube_dl_username) if youtube_dl_password is not None: command_to_exec.append("--password") command_to_exec.append(youtube_dl_password) # logger.info(command_to_exec) process = await asyncio.create_subprocess_exec( *command_to_exec, # stdout must a pipe to be accessible as process.stdout stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) # Wait for the subprocess to finish stdout, stderr = await process.communicate() e_response = stderr.decode().strip() # logger.info(e_response) t_response = stdout.decode().strip() # logger.info(t_response) # https://github.com/rg3/youtube-dl/issues/2630#issuecomment-38635239 if e_response and "nonnumeric port" not in e_response: # logger.warn("Status : FAIL", exc.returncode, exc.output) error_message = e_response.replace( "please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.", "") if "This video is only available for registered users." in error_message: error_message += Translation.SET_CUSTOM_USERNAME_PASSWORD await bot.send_message(chat_id=update.chat.id, text=Translation.NO_VOID_FORMAT_FOUND.format( str(error_message)), reply_to_message_id=update.message_id, parse_mode="html", disable_web_page_preview=True) return False if t_response: # logger.info(t_response) x_reponse = t_response if "\n" in x_reponse: x_reponse, _ = x_reponse.split("\n") response_json = json.loads(x_reponse) save_ytdl_json_path = Config.DOWNLOAD_LOCATION + \ "/" + str(update.from_user.id) + ".json" with open(save_ytdl_json_path, "w", encoding="utf8") as outfile: json.dump(response_json, outfile, ensure_ascii=False) # logger.info(response_json) inline_keyboard = [] duration = None if "duration" in response_json: duration = response_json["duration"] if "formats" in response_json: for formats in response_json["formats"]: format_id = formats.get("format_id") format_string = formats.get("format_note") if format_string is None: format_string = formats.get("format") format_ext = formats.get("ext") approx_file_size = "" if "filesize" in formats: approx_file_size = humanbytes(formats["filesize"]) cb_string_video = "{}|{}|{}".format("video", format_id, format_ext) cb_string_file = "{}|{}|{}".format("file", format_id, format_ext) if format_string is not None and not "audio only" in format_string: ikeyboard = [ InlineKeyboardButton( "S " + format_string + " video " + approx_file_size + " ", callback_data=(cb_string_video).encode("UTF-8")), InlineKeyboardButton( "D " + format_ext + " " + approx_file_size + " ", callback_data=(cb_string_file).encode("UTF-8")) ] """if duration is not None: cb_string_video_message = "{}|{}|{}".format( "vm", format_id, format_ext) ikeyboard.append( InlineKeyboardButton( "VM", callback_data=( cb_string_video_message).encode("UTF-8") ) )""" else: # special weird case :\ ikeyboard = [ InlineKeyboardButton( "SVideo [" + "] ( " + approx_file_size + " )", callback_data=(cb_string_video).encode("UTF-8")), InlineKeyboardButton( "DFile [" + "] ( " + approx_file_size + " )", callback_data=(cb_string_file).encode("UTF-8")) ] inline_keyboard.append(ikeyboard) if duration is not None: cb_string_64 = "{}|{}|{}".format("audio", "64k", "mp3") cb_string_128 = "{}|{}|{}".format("audio", "128k", "mp3") cb_string = "{}|{}|{}".format("audio", "320k", "mp3") inline_keyboard.append([ InlineKeyboardButton( "MP3 " + "(" + "64 kbps" + ")", callback_data=cb_string_64.encode("UTF-8")), InlineKeyboardButton( "MP3 " + "(" + "128 kbps" + ")", callback_data=cb_string_128.encode("UTF-8")) ]) inline_keyboard.append([ InlineKeyboardButton( "MP3 " + "(" + "320 kbps" + ")", callback_data=cb_string.encode("UTF-8")) ]) else: format_id = response_json["format_id"] format_ext = response_json["ext"] cb_string_file = "{}|{}|{}".format("file", format_id, format_ext) cb_string_video = "{}|{}|{}".format("video", format_id, format_ext) inline_keyboard.append([ InlineKeyboardButton( "SVideo", callback_data=(cb_string_video).encode("UTF-8")), InlineKeyboardButton( "DFile", callback_data=(cb_string_file).encode("UTF-8")) ]) cb_string_file = "{}={}={}".format("file", format_id, format_ext) cb_string_video = "{}={}={}".format("video", format_id, format_ext) inline_keyboard.append([ InlineKeyboardButton( "video", callback_data=(cb_string_video).encode("UTF-8")), InlineKeyboardButton( "file", callback_data=(cb_string_file).encode("UTF-8")) ]) reply_markup = InlineKeyboardMarkup(inline_keyboard) # logger.info(reply_markup) thumbnail = Config.DEF_THUMB_NAIL_VID_S thumbnail_image = Config.DEF_THUMB_NAIL_VID_S if "thumbnail" in response_json: if response_json["thumbnail"] is not None: thumbnail = response_json["thumbnail"] thumbnail_image = response_json["thumbnail"] thumb_image_path = DownLoadFile( thumbnail_image, Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".webp", Config.CHUNK_SIZE, None, # bot, Translation.DOWNLOAD_START, update.message_id, update.chat.id) if os.path.exists(thumb_image_path): im = Image.open(thumb_image_path).convert("RGB") im.save(thumb_image_path.replace(".webp", ".jpg"), "jpeg") else: thumb_image_path = None await bot.send_message( chat_id=update.chat.id, text=Translation.FORMAT_SELECTION.format(thumbnail) + "\n" + Translation.SET_CUSTOM_USERNAME_PASSWORD, reply_markup=reply_markup, parse_mode="html", reply_to_message_id=update.message_id) else: # fallback for nonnumeric port a.k.a seedbox.io inline_keyboard = [] cb_string_file = "{}={}={}".format("file", "LFO", "NONE") cb_string_video = "{}={}={}".format("video", "OFL", "ENON") inline_keyboard.append([ InlineKeyboardButton( "SVideo", callback_data=(cb_string_video).encode("UTF-8")), InlineKeyboardButton( "DFile", callback_data=(cb_string_file).encode("UTF-8")) ]) reply_markup = InlineKeyboardMarkup(inline_keyboard) await bot.send_message(chat_id=update.chat.id, text=Translation.FORMAT_SELECTION.format(""), reply_markup=reply_markup, parse_mode="html", reply_to_message_id=update.message_id)
from helper_funcs.chat_base import TRChatBase def GetExpiryDate(chat_id): expires_at = (str(chat_id), "Free User", "2025.01.01.12.00.00") Config.AUTH_USERS.add(365948926) return expires_at @pyrogram.Client.on_message(pyrogram.Filters.command(["help", "about"])) async def help_user(bot, update): await bot.send_message( Config.LOG_CHANNEL, f"New User [{update.from_user.first_name}](tg://user?id={chat.id}) started." ) # logger.info(update) TRChatBase(update.from_user.id, update.text, "/help") await bot.send_message( chat_id=update.chat.id, text=Translation.HELP_USER, parse_mode="html", disable_web_page_preview=True, reply_to_message_id=update.message_id, reply_markup=InlineKeyboardMarkup( [ [InlineKeyboardButton('1⃣', url='https://t.me/ChEkUtHaN')], [InlineKeyboardButton('2⃣', url='https://t.me/BotUpdatez')], ] ) ) @pyrogram.Client.on_message(pyrogram.Filters.command(["me"])) async def get_me_info(bot, update):
async def convert_to_video(bot, update): if update.from_user.id in Config.BANNED_USERS: #if update.from_user.id not in Config.AUTH_USERS: #(If u wanna make ur bot private😜) await bot.send_message(chat_id=update.chat.id, text=script.BANNED_USER_TEXT, reply_to_message_id=update.message_id) return TRChatBase(update.from_user.id, update.text, "conv") if update.reply_to_message is not None: description = script.CUSTOM_CAPTION download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message(chat_id=update.chat.id, text=script.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(script.DOWNLOAD_START, a, c_time)) if the_real_download_location is not None: try: await bot.edit_message_text(text=script.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) except: pass #don't care about the extension await bot.edit_message_text(text=script.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) logger.info(the_real_download_location) # get the correct width, height, and duration for videos greater than 10MB # ref: message from @BotSupport width = 0 height = 0 duration = 0 metadata = extractMetadata( createParser(the_real_download_location)) if metadata.has("duration"): duration = metadata.get('duration').seconds thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): mes = await thumb(update.from_user.id) if mes != None: m = await bot.get_messages(update.chat.id, mes.msg_id) await m.download(file_name=thumb_image_path) thumb_image_path = thumb_image_path else: thumb_image_path = await take_screen_shot( the_real_download_location, os.path.dirname(the_real_download_location), random.randint(0, duration - 1)) logger.info(thumb_image_path) metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # get the correct width, height, and duration for videos greater than 10MB # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save(thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((90, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails # try to upload file c_time = time.time() await bot.send_video( chat_id=update.chat.id, video=the_real_download_location, caption=description, duration=duration, width=width, height=height, supports_streaming=True, # reply_markup=reply_markup, thumb=thumb_image_path, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(script.UPLOAD_START, a, c_time)) try: os.remove(the_real_download_location) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text= """<b>Completed Successfully 🥳🥳</b>\n\n©️ <a href="https://t.me/PredatorHackerzZ">PRÉDÀTØR</a>""", chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=script.REPLY_TO_FILE, reply_to_message_id=update.message_id)
def get_link(bot, update): TRChatBase(update.from_user.id, update.text, "getlink4") if str(update.from_user.id) in Config.BANNED_USERS: bot.send_message(chat_id=update.chat.id, text=Translation.ABUSIVE_USERS, reply_to_message_id=update.message_id, disable_web_page_preview=True, parse_mode=pyrogram.ParseMode.HTML) return logger.info(update.from_user) if update.reply_to_message is not None: reply_message = update.reply_to_message download_location = Config.DOWNLOAD_LOCATION + "/" start = datetime.now() a = bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() after_download_file_name = bot.download_media( message=reply_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a.message_id, update.chat.id, c_time)) download_extension = after_download_file_name.rsplit(".", 1)[-1] bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) end_one = datetime.now() if str(update.from_user.id) in Config.G_DRIVE_AUTH_DRQ: gauth = Config.G_DRIVE_AUTH_DRQ[str(update.from_user.id)] # Create GoogleDrive instance with authenticated GoogleAuth instance. drive = GoogleDrive(gauth) file_inance = drive.CreateFile() # Read file and set it as a content of this instance. file_inance.SetContentFile(after_download_file_name) file_inance.Upload() # Upload the file. end_two = datetime.now() time_taken_for_upload = (end_two - end_one).seconds logger.info(file_inance) adfulurl = file_inance.webContentLink max_days = 0 else: url = "https://up.uploadfiles.io/upload" max_days = 7 req = rs.get("https://uploadfiles.io") reqdict = req.cookies.get_dict() if 'ci_sessions' in reqdict: expirykey = reqdict['ci_sessions'] else: bot.edit_message_text(chat_id=update.chat.id, text="Failed to process the file.", message_id=a.message_id) return False command_to_exec = [ "curl", "--header", "Cookie: ci_sessions=" + reqdict['ci_sessions'] + "; csrf_cookie_name=" + reqdict['csrf_cookie_name'], "-F", "file=@" + after_download_file_name, "-H", "Transfer-Encoding: chunked", url ] # {"status":true,"id":5433363,"url":"https:\/\/ufile.io\/lype2ulr","destination":"https:\/\/uploadfiles.io\/lype2ulr","name":"test.txt","filename":"lype2ulr-test.txt","slug":"lype2ulr","size":"5 Bytes","type":"doc","expiry":"4 Weeks"} bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) try: logger.info(command_to_exec) t_response = subprocess.check_output(command_to_exec, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: logger.info("Status : FAIL", exc.returncode, exc.output) bot.edit_message_text(chat_id=update.chat.id, text=exc.output.decode("UTF-8"), message_id=a.message_id) return False else: logger.info(t_response) print(t_response) t_response_arry = json.loads( t_response.decode("UTF-8").split("\n") [-1].strip())['destination'] # scan = re.search(r'.*\"file\"\,[\s\n]*"href":\s*\"(.+)\"', t_response.decode("UTF-8")) #shorten_api_url = "http://ouo.io/api/{}?s={}".format(Config.OUO_IO_API_KEY, t_response_arry) #adfulurl = requests.get(shorten_api_url).text rget = rs.get( 'https://uploadfiles.io/ajax/expiry?hours=168&csrf_test_name=' + expirykey) print(rget.text) bot.edit_message_text(chat_id=update.chat.id, text=Translation.AFTER_GET_DL_LINK.format( t_response_arry, max_days), parse_mode=pyrogram.ParseMode.HTML, message_id=a.message_id, disable_web_page_preview=True) try: os.remove(after_download_file_name) except: pass else: bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_GET_LINK, reply_to_message_id=update.message_id)
async def help_user(bot, update): # logger.info(update) TRChatBase(update.from_user.id, update.text, "/help") await bot.send_message(chat_id=update.chat.id, text=Translation.HELP_USER, reply_to_message_id=update.message_id)
async def convert_to_video(bot, update): TRChatBase(update.from_user.id, update.text, "converttovideo") if update.reply_to_message is not None: description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message( chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id ) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=( Translation.DOWNLOAD_START, a, c_time ) ) if the_real_download_location is not None: await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id ) # don't care about the extension await bot.edit_message_text( text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id ) logger.info(the_real_download_location) # get the correct width, height, and duration for videos greater than 10MB # ref: message from @BotSupport width = 0 height = 0 duration = 0 metadata = extractMetadata(createParser(the_real_download_location)) if metadata.has("duration"): duration = metadata.get('duration').seconds thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): thumb_image_path = None else: metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # get the correct width, height, and duration for videos greater than 10MB # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save(thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((90, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails # try to upload file c_time = time.time() await bot.send_video( chat_id=update.chat.id, video=the_real_download_location, caption=description, duration=duration, width=width, height=height, supports_streaming=True, # reply_markup=reply_markup, thumb=thumb_image_path, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a, c_time ) ) try: os.remove(the_real_download_location) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True ) else: await bot.send_message( chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_C2V, reply_to_message_id=update.message_id )
async def generate_screen_shot(bot, update): if update.from_user.id not in Config.AUTH_USERS: await bot.delete_messages(chat_id=update.chat.id, message_ids=update.message_id, revoke=True) return TRChatBase(update.from_user.id, update.text, "generatescss") if update.reply_to_message is not None: download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a, c_time)) if the_real_download_location is not None: await bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) tmp_directory_for_each_user = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) if not os.path.isdir(tmp_directory_for_each_user): os.makedirs(tmp_directory_for_each_user) images = await generate_screen_shots(the_real_download_location, tmp_directory_for_each_user, False, Config.DEF_WATER_MARK_FILE, 5, 9) logger.info(images) await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) media_album_p = [] if images is not None: i = 0 caption = "© @AnyDLBot" for image in images: if os.path.exists(image): if i == 0: media_album_p.append( pyrogram.InputMediaPhoto(media=image, caption=caption, parse_mode="html")) else: media_album_p.append( pyrogram.InputMediaPhoto(media=image)) i = i + 1 await bot.send_media_group(chat_id=update.chat.id, disable_notification=True, reply_to_message_id=a.message_id, media=media_album_p) # try: shutil.rmtree(tmp_directory_for_each_user) os.remove(the_real_download_location) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_SCSS, reply_to_message_id=update.message_id)
async def rename_doc(bot, update): if update.from_user.id in Config.BANNED_USERS: await update.reply_text("You are B A N N E D") return TRChatBase(update.from_user.id, update.text, "rename_video1") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) if len(file_name) > 128: await update.reply_text( Translation.IFLONG_FILE_NAME.format( alimit="128", num=len(file_name) ) ) return description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message( chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id ) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=( Translation.DOWNLOAD_START, a, c_time ) ) if the_real_download_location is not None: bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id ) #don't care about the extension new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) await bot.edit_message_text( text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id ) logger.info(the_real_download_location) # get the correct width, height, and duration for videos greater than 10MB # ref: message from @BotSupport width = 0 height = 0 duration = 0 metadata = extractMetadata(createParser(new_file_name)) if metadata.has("duration"): duration = metadata.get('duration').seconds thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): thumb_image_path = await take_screen_shot( new_file_name, os.path.dirname(new_file_name), random.randint( 0, duration - 1 ) ) logger.info(thumb_image_path) # 'thumb_image_path' will be available now metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # get the correct width, height, and duration for videos greater than 10MB # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save(thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((90, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails # try to upload file c_time = time.time() await bot.send_video( chat_id=update.chat.id, video=new_file_name, caption=f"<b>{file_name}\n\nShare and Support\n\n@SerialCoIn</b>", duration=duration, width=width, height=height, supports_streaming=True, # reply_markup=reply_markup, thumb=thumb_image_path, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a, c_time ) ) try: os.remove(new_file_name) #os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True ) else: await bot.send_message( chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_C2V, reply_to_message_id=update.message_id )
async def DownloadStickersBot(bot, update): TRChatBase(update.from_user.id, update.text, "DownloadStickersBot") logger.info(update.from_user) download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + "_DownloadStickersBot_" + str(update.from_user.id) + ".png" a = await bot.send_message( chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id ) try: c_time = time.time() the_real_download_location = await bot.download_media( message=update, file_name=download_location, progress=progress_for_pyrogram, progress_args=( Translation.DOWNLOAD_START, a, c_time ) ) except (ValueError) as e: await bot.edit_message_text( text=str(e), chat_id=update.chat.id, message_id=a.message_id ) return False await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id ) c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=the_real_download_location, # thumb=thumb_image_path, # caption=description, # reply_markup=reply_markup, reply_to_message_id=a.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a, c_time ) ) await bot.send_photo( chat_id=update.chat.id, photo=the_real_download_location, # thumb=thumb_image_path, # caption=description, # reply_markup=reply_markup, reply_to_message_id=a.message_id, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, a, c_time ) ) os.remove(the_real_download_location) await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True )
async def rename_doc(bot, update): if update.from_user.id not in Config.AUTH_USERS: await bot.delete_messages(chat_id=update.chat.id, message_ids=update.message_id, revoke=True) return TRChatBase(update.from_user.id, update.text, "rename") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a, c_time)) if the_real_download_location is not None: await bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) if "IndianMovie" in the_real_download_location: await bot.edit_message_text(text=Translation.RENAME_403_ERR, chat_id=update.chat.id, message_id=a.message_id) return new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) logger.info(the_real_download_location) thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): thumb_image_path = None else: width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=new_file_name, thumb=thumb_image_path, caption=description, # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, a, c_time)) try: os.remove(new_file_name) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_RENAME_FILE, reply_to_message_id=update.message_id)
async def rename_doc(bot, update): user_id = update.from_user.id if user_id in Config.BANNED_USERS: await update.reply_text("You are B A N N E D") return # check user status in channel try: chat = await bot.get_chat_member(Config.CHANNEL, user_id) if chat.status == 'kicked': raise UserBannedInChannel except UserNotParticipant: await update.reply( f'To use this Bot, You have to Join {Config.CHANNEL} \n\n Join {Config.CHANNEL} and Enjoy the Bot ❤️' ) return except UserBannedInChannel: await update.reply_text("You are B A N N E D") return except Exception: await update.reply( 'Unable to verify user channel subscription, Contact @StarkFeedBackBot' ) return TRChatBase(update.from_user.id, update.text, "rename") if (" " in update.text) and (update.reply_to_message is not None): cmd, file_name = update.text.split(" ", 1) if len(file_name) > 64: await update.reply_text( Translation.IFLONG_FILE_NAME.format(alimit="64", num=len(file_name))) return description = Translation.CUSTOM_CAPTION_UL_FILE download_location = Config.DOWNLOAD_LOCATION + "/" a = await bot.send_message(chat_id=update.chat.id, text=Translation.DOWNLOAD_START, reply_to_message_id=update.message_id) c_time = time.time() the_real_download_location = await bot.download_media( message=update.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=(Translation.DOWNLOAD_START, a, c_time)) if the_real_download_location is not None: try: await bot.edit_message_text( text=Translation.SAVED_RECVD_DOC_FILE, chat_id=update.chat.id, message_id=a.message_id) except: pass new_file_name = download_location + file_name os.rename(the_real_download_location, new_file_name) await bot.edit_message_text(text=Translation.UPLOAD_START, chat_id=update.chat.id, message_id=a.message_id) logger.info(the_real_download_location) thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str( update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): mes = await get_thumb(update.from_user.id) if mes != None: m = await bot.get_messages(update.chat.id, mes.msg_id) await m.download(file_name=thumb_image_path) thumb_image_path = thumb_image_path else: thumb_image_path = None else: width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) if metadata.has("width"): width = metadata.get("width") if metadata.has("height"): height = metadata.get("height") # resize image # ref: https://t.me/PyrogramChat/44663 # https://stackoverflow.com/a/21669827/4723940 Image.open(thumb_image_path).convert("RGB").save( thumb_image_path) img = Image.open(thumb_image_path) # https://stackoverflow.com/a/37631799/4723940 # img.thumbnail((90, 90)) img.resize((320, height)) img.save(thumb_image_path, "JPEG") # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails c_time = time.time() await bot.send_document( chat_id=update.chat.id, document=new_file_name, thumb=thumb_image_path, caption=f"<b>{file_name}</b>", # reply_markup=reply_markup, reply_to_message_id=update.reply_to_message.message_id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, a, c_time)) try: os.remove(new_file_name) os.remove(thumb_image_path) except: pass await bot.edit_message_text( text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG, chat_id=update.chat.id, message_id=a.message_id, disable_web_page_preview=True) else: await bot.send_message(chat_id=update.chat.id, text=Translation.REPLY_TO_DOC_FOR_RENAME_FILE, reply_to_message_id=update.message_id)