Example #1
0
async def inline_search(string, answers):
    query = string.split(None, 1)[1]
    async for message in app.search_global(query, limit=50):
        chat = message.chat
        keyboard = InlineKeyboard()
        keyboard.row(
            InlineKeyboardButton(
                'Message 🔗',
                url=message.link,
            ),
        )
        if chat.username:
            keyboard.row(
                InlineKeyboardButton(
                    'Chat 🔗',
                    url=f'https://t.me/{chat.username}',
                ),
            )
        try:
            text = message.text[:99] + '...'
        except TypeError:
            text = message.caption[:99] + '...'
        answers.append(
            InlineQueryResultArticle(
                title=f'Chat: {chat.title} | {chat.id} | {chat.type}',
                description=text,
                input_message_content=InputTextMessageContent(
                    f'**Chat:** `{chat.id}`\n\n' + text,
                    parse_mode='markdown',
                ),
                reply_markup=keyboard,
            ),
        )
Example #2
0
async def locale_button(_, query):
    lang_match = re.findall(
        r'en-US|hi|he|id|fa|el|dv|es|ja|de|ta|pt-br|ar|ku|tr',
        query.data,
    )
    if lang_match:
        if lang_match[0]:
            switch_to_locale(Owner, lang_match[0])
            await query.answer(
                text=tld('language_switch_success_pm').format(
                    list_locales[lang_match[0]],
                ),
                show_alert=True,
            )
        else:
            await query.answer(text='Error!', show_alert=True)
    try:
        LANGUAGE = prev_locale(Owner)
        locale = LANGUAGE.locale_name
        curr_lang = list_locales[locale]
    except Exception:
        curr_lang = 'English (US)'

    text = tld('language_select_language')
    text += tld('language_current_locale').format(curr_lang)
    buttons = InlineKeyboard()
    buttons.row(
        InlineKeyboardButton('US ­ЪЄ║­ЪЄИ', callback_data='set_lang_en-US'),
        InlineKeyboardButton('IN ­ЪЄ«­ЪЄ│', callback_data='set_lang_hi'),
        InlineKeyboardButton('HE ­ЪЄ«­ЪЄ▒', callback_data='set_lang_he'),
        InlineKeyboardButton('ID ­ЪЄ«­ЪЄЕ', callback_data='set_lang_id'),
        InlineKeyboardButton('FA ­ЪЄ«­ЪЄи', callback_data='set_lang_fa'),
    )
    buttons.row(
        InlineKeyboardButton('JA ­ЪЄ»­ЪЄх', callback_data='set_lang_ja'),
        InlineKeyboardButton('GR ­ЪЄг­ЪЄи', callback_data='set_lang_el'),
        InlineKeyboardButton('MV ­ЪЄ▓­ЪЄ╗', callback_data='set_lang_dv'),
        InlineKeyboardButton('ES ­ЪЄф­ЪЄИ', callback_data='set_lang_es'),
        InlineKeyboardButton('DE ­ЪЄЕ­ЪЄф', callback_data='set_lang_de'),
    )
    buttons.row(
        InlineKeyboardButton('TA ­ЪЈ┤заЂЕзаЂ«заЂ┤заЂ«заЂ┐', callback_data='set_lang_ta'),
        InlineKeyboardButton('BR ­ЪЄД­ЪЄи', callback_data='set_lang_pt-br'),
        InlineKeyboardButton('AR ­ЪЄИ­ЪЄд', callback_data='set_lang_pt-ar'),
        InlineKeyboardButton('CKB Рўђ№ИЈ', callback_data='set_lang_pt-ku'),
        InlineKeyboardButton('TR ­ЪЄ╣­ЪЄи', callback_data='set_lang_pt-tr'),
    ),
    buttons.row(
        InlineKeyboardButton('РЌђ№ИЈ', callback_data='language_back'),
    )
    try:
        await query.message.edit(
            text,
            parse_mode='markdown',
            reply_markup=buttons,
        )
        await query.answer()
    except errors.exceptions.bad_request_400.MessageNotModified:
        return
Example #3
0
async def get_markup(message: Message):
    ikeyboard = InlineKeyboard()
    ikeyboard.row(
        InlineKeyboardButton("leech", callback_data="leech"),
        InlineKeyboardButton("yt-dlp", callback_data="ytdl"),
    )
    ikeyboard.row(
        InlineKeyboardButton("leech archive", callback_data="leecha"),
        InlineKeyboardButton("yt-dlp archive", callback_data="ytdla"),
    )
    if Config.R_CLONE_CONF_URI:
        r_clone_conf_file = await get_r_clone_config(Config.R_CLONE_CONF_URI,
                                                     message._client)
        if r_clone_conf_file is not None:
            config = configparser.ConfigParser()
            config.read(r_clone_conf_file)
            remote_names = config.sections()
            it_r = 0
            for remote_name in remote_names:
                ikeyboard.row(
                    InlineKeyboardButton(
                        f"RClone LEECH {remote_name}",
                        callback_data=f"leech_rc_{it_r}".encode("UTF-8"),
                    ))
                # ikeyboard.append(InlineKeyboardButton(
                #     f"RClone YTDL {remote_name}",
                #     callback_data=(f"ytdl_rc_{it_r}").encode("UTF-8")
                # ))
                it_r = it_r + 1

    reply_text = "please select the required option"
    return reply_text, ikeyboard
Example #4
0
def row_inline_button_command(client, message):
    keyboard = InlineKeyboard()
    keyboard.row(InlineKeyboardButton('1', 'inline_keyboard#1'))
    keyboard.row(InlineKeyboardButton('2', 'inline_keyboard#2'),
                 InlineKeyboardButton('3', 'inline_keyboard#3'))
    keyboard.row(InlineKeyboardButton('4', 'inline_keyboard#4'))
    keyboard.row(InlineKeyboardButton('5', 'inline_keyboard#5'),
                 InlineKeyboardButton('6', 'inline_keyboard#6'))
    message.reply_text(
        '<b>Add button row:</b>\n\n'
        "<code>keyboard = InlineKeyboard()</code>\n"
        "<code>keyboard.row(InlineKeyboardButton('1', 'inline_keyboard#1'))</code>\n"
        "<code>keyboard.row(</code>\n"
        "<code>    InlineKeyboardButton('2', 'inline_keyboard#2'),</code>\n"
        "<code>    InlineKeyboardButton('3', 'inline_keyboard#3')</code>\n"
        "<code>)</code>\n"
        "<code>keyboard.row(InlineKeyboardButton('4', 'inline_keyboard#4'))</code>\n"
        "<code>keyboard.row(</code>\n"
        "<code>    InlineKeyboardButton('5', 'inline_keyboard#5'),</code>\n"
        "<code>    InlineKeyboardButton('6', 'inline_keyboard#6')</code>\n"
        "<code>)</code>\n",
        reply_markup=keyboard)
async def ffmpeg(client, message):
    try:
        message = message.reply_to_message
        chat_id = str(message.chat.id)
        message_id = str(message.message_id)
        keyboard = InlineKeyboard()
        keyboard.row(
            InlineKeyboardButton('240p', message_id + "#240#" + str(chat_id)),
            InlineKeyboardButton('360p', message_id + "#360#" + str(chat_id)))
        keyboard.row(
            InlineKeyboardButton('720p', message_id + "#720#" + str(chat_id)),
            InlineKeyboardButton('1080p',
                                 message_id + "#1080#" + str(chat_id)))
        keyboard.row(
            InlineKeyboardButton('Compress',
                                 message_id + "#Compressed#" + str(chat_id)))
        await message.reply("Select The Option You Want",
                            reply_markup=keyboard)
    except Exception as e:
        print("Error : " + str(e))
        await message.reply("Please Reply To A Valid Media File")
Example #6
0
async def echo(_, message):
    LOGGER.info(message.from_user)
    url, _, youtube_dl_username, youtube_dl_password = get_link(message)

    info_dict = {}
    if youtube_dl_username and youtube_dl_password:
        info_dict.update(
            {
                "username": youtube_dl_username,
                "password": youtube_dl_password,
            }
        )
    if "hotstar" in url:
        info_dict.update(
            {
                "geo_bypass_country": "IN",
            }
        )
    try:
        info = await yt_extract_info(
            video_url=url,
            download=False,
            ytdl_opts=info_dict,
            ie_key=None,
        )
    except youtube_dl.utils.DownloadError as ytdl_error:
        await message.reply_text(text=str(ytdl_error), quote=True)
        return False

    if info:
        ikeyboard = InlineKeyboard()

        thumb_image = info.get("thumbnail", None)
        thumbnail = thumb_image or Config.DEFAULT_THUMBNAIL

        extractor_key = info.get("extractor_key", "Generic")
        duration = info.get("duration", None)
        if "formats" in info:
            for formats in info.get("formats"):
                format_id = formats.get("format_id")
                format_string = formats.get("format_note", None)
                if format_string is None:
                    format_string = formats.get("format")
                # @SpEcHiDe/PublicLeech//helper_funcs/youtube_dl_extractor.py#L100
                if "DASH" in format_string.upper():
                    continue
                format_ext = formats.get("ext")
                av_codec = "empty"
                if formats.get("acodec") == "none" or formats.get("vcodec") == "none":
                    av_codec = "none"
                approx_file_size = (
                    humanbytes(formats.get("filesize"))
                    if formats.get("filesize")
                    else ""
                )
                display_str = (
                    f"{format_string} [{format_ext.upper()}] {approx_file_size}"
                )
                cb_string_video = f"video|{extractor_key}|{format_id}|{av_codec}"
                # GDrive gets special pass, acodec is not listed here, ie acodec=None
                if (
                    extractor_key == "GoogleDrive"
                    and format_id == "source"
                    or extractor_key != "GoogleDrive"
                    and format_string
                    and "audio only" not in format_string
                ):
                    ikeyboard.row(
                        InlineKeyboardButton(display_str, callback_data=cb_string_video)
                    )
                elif extractor_key != "GoogleDrive":
                    # special weird case :\
                    ikeyboard.row(
                        InlineKeyboardButton(
                            f"Video {approx_file_size}", cb_string_video
                        ),
                    )
            if duration:
                ikeyboard.row(
                    InlineKeyboardButton(
                        "MP3 (64 kbps)", callback_data=f"audio|{extractor_key}|64|mp3"
                    ),
                    InlineKeyboardButton(
                        "MP3 (128 kbps)", callback_data=f"audio|{extractor_key}|128|mp3"
                    ),
                )
                ikeyboard.row(
                    InlineKeyboardButton(
                        "MP3 (320 kbps)", callback_data=f"audio|{extractor_key}|320|mp3"
                    )
                )
        elif "entries" in info:
            for entries in info.get("entries"):
                for formats in entries.get("formats"):
                    format_id = formats.get("format_id")
                    format_ext = formats.get("ext")
                    cb_string_file = f"file|{extractor_key}|{format_id}|{format_ext}"
                    ikeyboard.row(
                        InlineKeyboardButton(
                            f"YTDL Generic File [{format_ext.upper()}]", callback_data=cb_string_file
                        ),
                    )
        else:
            format_id = info.get("format_id")
            format_ext = info.get("ext")
            cb_string_file = f"file={extractor_key}={format_id}={format_ext}"
            ikeyboard.row(
                InlineKeyboardButton(
                    f"File [{format_ext.upper()}]", callback_data=cb_string_file
                ),
            )

        save_thumbnail = os.path.join(
            Config.WORK_DIR, str(message.from_user.id) + ".jpg"
        )
        if not os.path.isdir(Config.WORK_DIR):
            os.makedirs(Config.WORK_DIR)

        if os.path.exists(save_thumbnail):
            thumb_image_path = save_thumbnail
        else:
            thumb_image_path = await get_thumbnail(thumbnail, save_thumbnail)
        await message.reply_photo(
            photo=thumb_image_path,
            quote=True,
            caption=String.FORMAT_SELECTION.format(thumbnail)
            + "\n"
            + String.SET_CUSTOM_USERNAME_PASSWORD,
            reply_markup=ikeyboard,
            parse_mode="html",
        )
    else:
        # fallback for nonnumeric port a.k.a seedbox.io
        ikeyboard = InlineKeyboard()
        cb_string_file = "file=LFO=NONE=NONE"
        ikeyboard.row(
            InlineKeyboardButton("File", callback_data=cb_string_file),
        )
        await message.reply_photo(
            photo=Config.DEFAULT_THUMBNAIL,
            quote=True,
            caption=String.FORMAT_SELECTION.format(""),
            reply_markup=ikeyboard,
            parse_mode="html",
            reply_to_message_id=message.message_id,
        )
async def extract_youtube_dl_formats(
    url, yt_dl_user_name, yt_dl_pass_word, user_working_dir
):
    info_dict = {"noplaylist": True}
    if yt_dl_user_name and yt_dl_pass_word:
        info_dict.update(
            {
                "username": yt_dl_user_name,
                "password": yt_dl_pass_word,
            }
        )
    if "hotstar" in url:
        info_dict.update(
            {
                "geo_bypass": True,
                "geo_bypass_country": "IN",
            }
        )
    try:
        info = await yt_extract_info(
            video_url=url,
            download=False,
            ytdl_opts=info_dict,
            ie_key=None,
        )
    except (DownloadError, ExtractorError) as ytdl_error:
        return None, str(ytdl_error), None

    ikeyboard = InlineKeyboard()
    #
    thumbnail = info.get("thumbnail", Config.DEFAULT_THUMBNAIL)
    # LOGGER.info(thumb_image)
    # YouTube acts weirdly,
    # and not in the same way as Telegram

    extractor_key = info.get("extractor_key", "Generic")
    duration = info.get("duration", None)
    if info.get("formats"):
        for formats in info.get("formats"):
            format_id = formats.get("format_id")
            format_string = formats.get("format_note", formats.get("format"))
            # don't display formats, without audio
            # https://t.me/c/1434259219/269937
            if "DASH" in format_string.upper():
                continue
            format_ext = formats.get("ext")
            approx_file_size = (
                humanbytes(formats.get("filesize")) if formats.get("filesize") else ""
            )
            av_codec = "empty"
            if formats.get("acodec") == "none" or formats.get("vcodec") == "none":
                av_codec = "none"
            dipslay_str_uon = (
                f"{format_string} [{format_ext.upper()}] {approx_file_size}"
            )
            cb_string_video = f"video|{extractor_key}|{format_id}|{av_codec}"
            # GDrive gets special pass, acodec is not listed here, ie acodec=None
            if (
                extractor_key == "GoogleDrive"
                and format_id == "source"
                or extractor_key != "GoogleDrive"
                and format_string
                and "audio only" not in format_string
            ):
                ikeyboard.row(
                    InlineKeyboardButton(dipslay_str_uon, callback_data=cb_string_video)
                )
            elif extractor_key != "GoogleDrive":
                # special weird case :\
                ikeyboard.row(
                    InlineKeyboardButton(
                        f"SVideo ({approx_file_size})",
                        callback_data=cb_string_video,
                    )
                )
        if duration:
            ikeyboard.row(
                InlineKeyboardButton(
                    "MP3 (64 kbps)", callback_data=f"audio|{extractor_key}|64|mp3"
                ),
                InlineKeyboardButton(
                    "MP3 (128 kbps)", callback_data=f"audio|{extractor_key}|128|mp3"
                ),
            )
            ikeyboard.row(
                InlineKeyboardButton(
                    "MP3 (320 kbps)", callback_data=f"audio|{extractor_key}|320|mp3"
                )
            )
    elif "entries" in info:
        for entries in info.get("entries"):
            for formats in entries.get("formats"):
                format_id = formats.get("format_id")
                format_ext = formats.get("ext")
                cb_string_file = f"generic|{extractor_key}|{format_id}|{format_ext}"
                ikeyboard.row(
                    InlineKeyboardButton(
                        f"YTDL Generic File [{format_ext.upper()}]",
                        callback_data=cb_string_file,
                    ),
                )
    else:
        format_id = info.get("format_id", None)
        # format_ext = info.get("ext", None)
        ikeyboard.row(
            InlineKeyboardButton(
                "YTDL Generic File",
                callback_data=f"video|{extractor_key}|{format_id}|DL",
            )
        )
        # LOGGER.info(ikeyboard)
    succss_mesg = (
        "Select the desired format: 👇\n"
        "<u>mentioned</u> <i>file size might be approximate</i>"
    )
    return thumbnail, succss_mesg, ikeyboard
async def extract_youtube_dl_formats(url, yt_dl_user_name, yt_dl_pass_word,
                                     user_working_dir):
    command_to_exec = [
        "youtube-dlc", "--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 yt_dl_user_name is not None:
        command_to_exec.append("--username")
        command_to_exec.append(yt_dl_user_name)
    if yt_dl_pass_word is not None:
        command_to_exec.append("--password")
        command_to_exec.append(yt_dl_pass_word)

    LOGGER.info(command_to_exec)
    t_response, e_response = await run_command(command_to_exec)
    # Wait for the subprocess to finish
    # LOGGER.info(e_response)
    # LOGGER.info(t_response)
    # https://github.com/rg3/youtube-dl/issues/2630#issuecomment-38635239
    if 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.",
            "")
        return None, error_message, None
    if t_response:
        # logger.info(t_response)
        x_reponse = t_response
        response_json = []
        if "\n" in x_reponse:
            for yu_r in x_reponse.split("\n"):
                response_json.append(json.loads(yu_r))
        else:
            response_json.append(json.loads(x_reponse))
        # response_json = json.loads(x_reponse)
        save_ytdl_json_path = user_working_dir + \
            "/" + str("ytdleech") + ".json"
        with open(save_ytdl_json_path, "w", encoding="utf8") as outfile:
            json.dump(response_json, outfile, ensure_ascii=False)
        # logger.info(response_json)
        ikeyboard = InlineKeyboard()
        #
        thumb_image = DEF_THUMB_NAIL_VID_S
        #
        for current_r_json in response_json:
            # LOGGER.info(current_r_json)
            #
            thumb_image = current_r_json.get("thumbnails", None)
            # LOGGER.info(thumb_image)
            if thumb_image is not None:
                # YouTube acts weirdly,
                # and not in the same way as Telegram
                thumb_image = thumb_image[-1]["url"]
            if thumb_image is None:
                thumb_image = DEF_THUMB_NAIL_VID_S

            duration = None
            if "duration" in current_r_json:
                duration = current_r_json["duration"]
            if "formats" in current_r_json:
                for formats in current_r_json["formats"]:
                    format_id = formats.get("format_id")
                    format_string = formats.get("format_note")
                    if format_string is None:
                        format_string = formats.get("format")
                    # don't display formats, without audio
                    # https://t.me/c/1434259219/269937
                    if "DASH" in format_string.upper():
                        continue
                    format_ext = formats.get("ext")
                    approx_file_size = ""
                    if "filesize" in formats:
                        approx_file_size = humanbytes(formats["filesize"])
                    n_ue_sc = bool("video only" in format_string)
                    scneu = "DL" if not n_ue_sc else "XM"
                    dipslay_str_uon = " " + format_string + " (" + format_ext.upper(
                    ) + ") " + approx_file_size + " "
                    cb_string_video = "{}|{}|{}|{}".format(
                        "video", format_id, format_ext, scneu)
                    if "drive.google.com" in url:
                        if format_id == "source":
                            ikeyboard.row(
                                InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(cb_string_video)))
                    else:
                        if format_string is not None and "audio only" not in format_string:
                            ikeyboard.row(
                                InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(cb_string_video)))
                        else:
                            # special weird case :\
                            ikeyboard.row(
                                InlineKeyboardButton(
                                    "SVideo [" + "] ( " + approx_file_size +
                                    " )",
                                    callback_data=(cb_string_video)))
                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")
                    ikeyboard.row(
                        InlineKeyboardButton("MP3 " + "(" + "64 kbps" + ")",
                                             callback_data=cb_string_64),
                        InlineKeyboardButton("MP3 " + "(" + "128 kbps" + ")",
                                             callback_data=cb_string_128))
                    ikeyboard.row(
                        InlineKeyboardButton("MP3 " + "(" + "320 kbps" + ")",
                                             callback_data=cb_string))
            else:
                format_id = current_r_json["format_id"]
                format_ext = current_r_json["ext"]
                cb_string_video = "{}|{}|{}|{}".format("video", format_id,
                                                       format_ext, "DL")
                ikeyboard.row(
                    InlineKeyboardButton("SVideo",
                                         callback_data=(cb_string_video)))
            # TODO: :\
            break
        # LOGGER.info(ikeyboard)
        succss_mesg = """Select the desired format: 👇
<u>mentioned</u> <i>file size might be approximate</i>"""
        return thumb_image, succss_mesg, ikeyboard