def get_link(bot, update):
    TRChatBase(update.from_user.id, update.text, "getlink")
    if str(update.from_user.id) not in Config.SUPER3X_DLBOT_USERS:
        bot.send_message(chat_id=update.from_user.id,
                         text=Translation.NOT_AUTH_USER_TEXT,
                         reply_to_message_id=update.message_id)
        return
    if update.reply_to_message is not None:
        reply_message = update.reply_to_message
        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)
        after_download_file_name = bot.download_media(
            message=reply_message, file_name=download_location)
        download_extension = after_download_file_name.rsplit(".", 1)[-1]
        bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE,
                              chat_id=update.from_user.id,
                              message_id=a.message_id)
        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.from_user.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.from_user.id,
                                  text=exc.output.decode("UTF-8"),
                                  message_id=a.message_id)
        else:
            t_response_arry = t_response.decode("UTF-8").split(
                "\n")[-1].strip()
            bot.edit_message_text(chat_id=update.from_user.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.from_user.id,
                         text=Translation.REPLY_TO_DOC_GET_LINK,
                         reply_to_message_id=update.message_id)
def save_photo(bot, update):
    TRChatBase(update.from_user.id, update.text, "save_photo")
    download_location = Config.DOWNLOAD_LOCATION + "/" + str(
        update.from_user.id) + ".jpg"
    bot.download_media(message=update, file_name=download_location)
    bot.send_message(chat_id=update.from_user.id,
                     text=Translation.SAVED_CUSTOM_THUMB_NAIL,
                     reply_to_message_id=update.message_id)
Beispiel #3
0
def upgrade(bot, update):
    # logger.info(update)
    TRChatBase(update.from_user.id, update.text, "/upgrade")
    bot.send_message(chat_id=update.from_user.id,
                     text=Translation.UPGRADE_TEXT,
                     parse_mode=pyrogram.ParseMode.HTML,
                     reply_to_message_id=update.message_id,
                     disable_web_page_preview=True)
Beispiel #4
0
def help_user(bot, update):
    # logger.info(update)
    TRChatBase(update.from_user.id, update.text, "/help")
    bot.send_message(chat_id=update.from_user.id,
                     text=Translation.HELP_USER,
                     parse_mode=pyrogram.ParseMode.HTML,
                     disable_web_page_preview=True,
                     reply_to_message_id=update.message_id)
def extract_sub_title(bot, update):
    TRChatBase(update.from_user.id, update.text, "extract_sub_title")
    if str(update.from_user.id) not in Config.SUPER7X_DLBOT_USERS:
        bot.send_message(chat_id=update.from_user.id,
                         text=Translation.NOT_AUTH_USER_TEXT,
                         reply_to_message_id=update.message_id)
        return
    download_location = Config.DOWNLOAD_LOCATION + "/"
    if update.reply_to_message is not None:
        text = update.reply_to_message.text
        if text.startswith("http"):
            a = bot.send_message(chat_id=update.from_user.id,
                                 text=Translation.UPLOAD_START,
                                 reply_to_message_id=update.message_id)
            sub_title_file_name = extractsubtitle(text, download_location)
            bot.send_document(
                chat_id=update.from_user.id,
                document=sub_title_file_name,
                # thumb=thumb_image_path,
                # caption=description,
                # reply_markup=reply_markup,
                reply_to_message_id=update.reply_to_message.message_id)
            os.remove(sub_title_file_name)
            bot.edit_message_text(text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG,
                                  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_OR_LINK_FOR_RARX_SRT,
                reply_to_message_id=update.message_id)
    else:
        bot.send_message(chat_id=update.from_user.id,
                         text=Translation.REPLY_TO_DOC_OR_LINK_FOR_RARX_SRT,
                         reply_to_message_id=update.message_id)
def get_doc(bot, update):
    TRChatBase(update.from_user.id, update.text, "converttovideo")
    if str(update.from_user.id) not in Config.SUPER_DLBOT_USERS:
        bot.send_message(chat_id=update.from_user.id,
                         text=Translation.NOT_AUTH_USER_TEXT,
                         reply_to_message_id=update.message_id)
        return
    if update.reply_to_message is not None:
        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)
            # don't care about the extension
            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)
            # 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
                new_img = img.resize((90, 90))
                new_img.save(thumb_image_path, "JPEG", optimize=True)
            # try to upload file
            bot.send_video(
                chat_id=update.from_user.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)
            try:
                os.remove(the_real_download_location)
                os.remove(thumb_image_path)
            except:
                pass
            bot.edit_message_text(text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG,
                                  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_C2V,
                         reply_to_message_id=update.message_id)
Beispiel #7
0
def rename_doc(bot, update):
    TRChatBase(update.from_user.id, update.text, "rename")
    if str(update.from_user.id) not in Config.SUPER3X_DLBOT_USERS:
        bot.send_message(chat_id=update.from_user.id,
                         text=Translation.NOT_AUTH_USER_TEXT,
                         reply_to_message_id=update.message_id)
        return
    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,
                                  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)
Beispiel #8
0
def echo(bot, update):
    # logger.info(update)
    TRChatBase(update.from_user.id, update.text, "/echo")
    bot.send_chat_action(chat_id=update.from_user.id, action="typing")
    text = update.text
    if (text.startswith("http")):
        url = text
        if "|" in url:
            if str(update.from_user.id) not in Config.SUPER_DLBOT_USERS:
                bot.send_message(chat_id=update.from_user.id,
                                 text=Translation.NOT_AUTH_USER_TEXT,
                                 reply_to_message_id=update.message_id)
                return
            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)
            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)
            a = bot.send_message(chat_id=update.from_user.id,
                                 text=Translation.DOWNLOAD_START,
                                 reply_to_message_id=update.message_id)
            after_download_path = DownLoadFile(
                url, Config.DOWNLOAD_LOCATION + "/" + file_name)
            description = Translation.CUSTOM_CAPTION_UL_FILE
            bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE,
                                  chat_id=update.from_user.id,
                                  message_id=a.message_id)
            bot.edit_message_text(text=Translation.UPLOAD_START,
                                  chat_id=update.from_user.id,
                                  message_id=a.message_id)
            file_size = os.stat(after_download_path).st_size
            if file_size > Config.TG_MAX_FILE_SIZE:
                bot.edit_message_text(text=Translation.RCHD_TG_API_LIMIT,
                                      chat_id=update.from_user.id,
                                      message_id=a.message_id)
            else:
                # try to upload file
                bot.send_document(
                    chat_id=update.from_user.id,
                    document=after_download_path,
                    caption=description,
                    # reply_markup=reply_markup,
                    thumb=thumb_image_path,
                    reply_to_message_id=update.message_id)
                bot.edit_message_text(
                    text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG,
                    chat_id=update.from_user.id,
                    message_id=a.message_id,
                    disable_web_page_preview=True)
            try:
                os.remove(after_download_path)
                os.remove(thumb_image_path)
            except:
                pass
        else:
            try:
                if "hotstar.com" in url:
                    command_to_exec = [
                        "youtube-dl", "--no-warnings", "-j", url, "--proxy",
                        Config.HTTP_PROXY
                    ]
                else:
                    command_to_exec = [
                        "youtube-dl", "--no-warnings", "-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)
                bot.send_message(chat_id=update.from_user.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)
                # logger.info(response_json)
                inline_keyboard = []
                if "formats" in response_json:
                    for formats in response_json["formats"]:
                        format_id = formats["format_id"]
                        format_string = formats["format"]
                        format_ext = formats["ext"]
                        approx_file_size = ""
                        if "filesize" in formats:
                            approx_file_size = humanbytes(formats["filesize"])
                        cb_string = "{}|{}|{}".format("video", format_id,
                                                      format_ext)
                        if not "audio only" in format_string:
                            ikeyboard = [
                                pyrogram.InlineKeyboardButton(
                                    "[" + format_string + "] (" + format_ext +
                                    " - " + approx_file_size + ")",
                                    callback_data=(cb_string).encode("UTF-8"))
                            ]
                            inline_keyboard.append(ikeyboard)
                    cb_string = "{}|{}|{}".format("audio", "5", "mp3")
                    inline_keyboard.append([
                        pyrogram.InlineKeyboardButton(
                            "MP3 " + "(" + "medium" + ")",
                            callback_data=cb_string.encode("UTF-8"))
                    ])
                    cb_string = "{}|{}|{}".format("audio", "0", "mp3")
                    inline_keyboard.append([
                        pyrogram.InlineKeyboardButton(
                            "MP3 " + "(" + "best" + ")",
                            callback_data=cb_string.encode("UTF-8"))
                    ])
                else:
                    format_id = response_json["format_id"]
                    format_ext = response_json["ext"]
                    cb_string = "{}|{}|{}".format("file", format_id,
                                                  format_ext)
                    inline_keyboard.append([
                        pyrogram.InlineKeyboardButton(
                            "unknown video format",
                            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:
                    thumbnail = response_json["thumbnail"]
                    thumbnail_image = response_json["thumbnail"]
                thumb_image_path = DownLoadFile(
                    thumbnail_image, Config.DOWNLOAD_LOCATION + "/" +
                    str(update.from_user.id) + ".jpg")
                bot.send_message(
                    chat_id=update.from_user.id,
                    text=Translation.FORMAT_SELECTION.format(thumbnail),
                    reply_markup=reply_markup,
                    parse_mode=pyrogram.ParseMode.HTML,
                    reply_to_message_id=update.message_id)
    elif "===" in text:
        logger.info("cult_small_video")
        if str(update.from_user.id) not in Config.SUPER7X_DLBOT_USERS:
            bot.send_message(chat_id=update.from_user.id,
                             text=Translation.NOT_AUTH_USER_TEXT,
                             reply_to_message_id=update.message_id)
            return
        if update.reply_to_message is not None:
            a = bot.send_message(chat_id=update.from_user.id,
                                 text=Translation.DOWNLOAD_START,
                                 reply_to_message_id=update.message_id)
            url = update.reply_to_message.text
            for entity in update.reply_to_message.entities:
                if entity.type == "text_link":
                    url = entity.url
            start_time, end_time = text.split("===")
            mp4_file = cult_small_video(url, Config.DOWNLOAD_LOCATION,
                                        start_time, end_time)
            bot.edit_message_text(text=Translation.SAVED_RECVD_DOC_FILE,
                                  chat_id=update.from_user.id,
                                  message_id=a.message_id)
            thumb_image_path = Config.DOWNLOAD_LOCATION + \
                "/" + str(update.from_user.id) + ".jpg"
            # 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(mp4_file))
            if metadata.has("duration"):
                duration = metadata.get('duration').seconds
            # get the correct width, height, and duration for videos greater than 10MB
            if os.path.exists(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")
                # 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)
            else:
                thumb_image_path = None
            # try to upload file
            bot.edit_message_text(text=Translation.UPLOAD_START,
                                  chat_id=update.from_user.id,
                                  message_id=a.message_id)
            bot.send_video(
                chat_id=update.from_user.id,
                video=mp4_file,
                # 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)
            os.remove(mp4_file)
            bot.edit_message_text(text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG,
                                  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.START_TEXT,
                             reply_to_message_id=update.message_id)
    elif ":" in text:
        logger.info("take_screen_shot")
        if str(update.from_user.id) not in Config.SUPER7X_DLBOT_USERS:
            bot.send_message(chat_id=update.from_user.id,
                             text=Translation.FF_MPEG_RO_BOT_RE_SURRECT_ED,
                             reply_to_message_id=update.message_id)
            return
        if update.reply_to_message is not None:
            a = bot.send_message(chat_id=update.from_user.id,
                                 text=Translation.DOWNLOAD_START,
                                 reply_to_message_id=update.message_id)
            url = update.reply_to_message.text
            for entity in update.reply_to_message.entities:
                if entity.type == "text_link":
                    url = entity.url
            img_file = take_screen_shot(url, Config.DOWNLOAD_LOCATION, text)
            # try to upload file
            bot.edit_message_text(text=Translation.UPLOAD_START,
                                  chat_id=update.from_user.id,
                                  message_id=a.message_id)
            bot.send_document(
                chat_id=update.from_user.id,
                document=img_file,
                # caption=description,
                # reply_markup=reply_markup,
                # thumb=thumb_image_path,
                reply_to_message_id=update.message_id)
            bot.send_photo(
                chat_id=update.from_user.id,
                photo=img_file,
                # caption=description,
                # reply_markup=reply_markup,
                # thumb=thumb_image_path,
                reply_to_message_id=update.message_id)
            os.remove(img_file)
            bot.edit_message_text(text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG,
                                  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.FF_MPEG_RO_BOT_RE_SURRECT_ED,
                             reply_to_message_id=update.message_id)
Beispiel #9
0
def start(bot, update):
    # logger.info(update)
    TRChatBase(update.from_user.id, update.text, "/start")
    bot.send_message(chat_id=update.from_user.id,
                     text=Translation.START_TEXT,
                     reply_to_message_id=update.message_id)