예제 #1
0
 async def help_btn_generator():
     help_list = [
         InlineKeyboardButton(cmd.capitalize(),
                              callback_data="ihelp_" + cmd)
         for cmd in list(_COMMANDS)
     ]
     return InlineKeyboardMarkup(sublists(help_list))
예제 #2
0
async def upload_image_grp(results, message: Message, doc: bool = False):
    key_ = list(results[0])[0]
    medias_ = results[0][key_]
    if message.process_is_canceled:
        await message.client.stop_transmission()
    if len(medias_) == 0:
        await message.err(f"No result Found `'{key_}'`", del_in=7)
    if len(medias_) == 1:
        path_ = Path(medias_[0])
        if doc:
            await doc_upload(message=message, path=path_, del_path=True)
        else:
            await photo_upload(message=message, path=path_, del_path=True)
    else:
        mgroups = sublists(
            [(InputMediaDocument(media=x) if doc else InputMediaPhoto(media=x))
             for x in medias_
             if x.endswith((".jpg", ".jpeg", ".png", ".bmp"))],
            width=10,
        )
        for num, m_ in enumerate(mgroups, start=1):
            try:
                await message.edit(
                    f"Uploading **{round(num / len(mgroups) * 100)} %** ...")
                await message.client.send_media_group(message.chat.id,
                                                      media=m_)
                await asyncio.sleep(len(m_))
            except FloodWait as f:
                await asyncio.sleep(f.x + 5)
예제 #3
0
 def help_btn_generator():
     help_list = [
         InlineKeyboardButton(cmd.capitalize(),
                              callback_data="ihelp_" + cmd)
         for cmd in list(COMMANDS.keys())
     ]
     return sublists(help_list)
예제 #4
0
def download_button(vid: str, body: bool = False):
    try:
        vid_data = youtube_dl.YoutubeDL({
            "no-playlist": True
        }).extract_info(BASE_YT_URL + vid, download=False)
    except ExtractorError:
        vid_data = {"formats": []}
    buttons = [[
        InlineKeyboardButton("⭐️ BEST - 📹 MKV",
                             callback_data=f"ytdl_download_{vid}_mkv_v"),
        InlineKeyboardButton(
            "⭐️ BEST - 📹 WebM/MP4",
            callback_data=f"ytdl_download_{vid}_mp4_v",
        ),
    ]]
    # ------------------------------------------------ #
    qual_dict = defaultdict(lambda: defaultdict(int))
    qual_list = ["144p", "240p", "360p", "480p", "720p", "1080p", "1440p"]
    audio_dict = {}
    # ------------------------------------------------ #
    for video in vid_data["formats"]:

        fr_note = video.get("format_note")
        fr_id = int(video.get("format_id"))
        fr_size = video.get("filesize")
        if video.get("ext") == "mp4":
            for frmt_ in qual_list:
                if fr_note in (frmt_, frmt_ + "60"):
                    qual_dict[frmt_][fr_id] = fr_size
        if video.get("acodec") != "none":
            bitrrate = int(video.get("abr", 0))
            if bitrrate != 0:
                audio_dict[
                    bitrrate] = f"🎵 {bitrrate}Kbps ({humanbytes(fr_size) or 'N/A'})"

    video_btns = []
    for frmt in qual_list:
        frmt_dict = qual_dict[frmt]
        if len(frmt_dict) != 0:
            frmt_id = sorted(list(frmt_dict))[-1]
            frmt_size = humanbytes(frmt_dict.get(frmt_id)) or "N/A"
            video_btns.append(
                InlineKeyboardButton(
                    f"📹 {frmt} ({frmt_size})",
                    callback_data=f"ytdl_download_{vid}_{frmt_id}_v",
                ))
    buttons += sublists(video_btns, width=2)
    buttons += [[
        InlineKeyboardButton("⭐️ BEST - 🎵 320Kbps - MP3",
                             callback_data=f"ytdl_download_{vid}_mp3_a")
    ]]
    buttons += sublists(
        [
            InlineKeyboardButton(audio_dict.get(key_),
                                 callback_data=f"ytdl_download_{vid}_{key_}_a")
            for key_ in sorted(audio_dict.keys())
        ],
        width=2,
    )
    if body:
        vid_body = f"<b>[{vid_data.get('title')}]({vid_data.get('webpage_url')})</b>"
        return vid_body, InlineKeyboardMarkup(buttons)
    return InlineKeyboardMarkup(buttons)
예제 #5
0
def download_button(vid: str, body: bool = False):
    x = youtube_dl.YoutubeDL({
        "no-playlist": True
    }).extract_info(BASE_YT_URL + vid, download=False)
    ###
    (
        format_144,
        format_240,
        format_360,
        format_720,
        format_1080,
        format_1440,
        format_2160,
    ) = [0 for _ in range(7)]
    btn = [[
        InlineKeyboardButton("⭐️  BEST (Video + Audio)",
                             callback_data=f"ytdl_download_{vid}_best_v")
    ]]
    audio, format_data = {}, {}
    ###
    for video in x["formats"]:
        if video.get("ext") == "mp4":
            f_note = video.get("format_note")
            fr_id = int(video.get("format_id"))
            if f_note in ("2160p", "2160p60") and fr_id > format_2160:
                format_2160 = fr_id
            if f_note in ("1440p", "1440p60") and fr_id > format_1440:
                format_1440 = fr_id
            if f_note in ("1080p", "1080p60") and fr_id > format_1080:
                format_1080 = fr_id
            if f_note in ("720p", "720p60") and fr_id > format_720:
                format_720 = fr_id
            if f_note in ("360p", "360p60") and fr_id > format_360:
                format_360 = fr_id
            if f_note in ("240p", "240p60") and fr_id > format_240:
                format_240 = fr_id
            if f_note in ("144p", "144p60") and fr_id > format_144:
                format_144 = fr_id
            format_data[
                fr_id] = f'📹 {f_note} ({humanbytes(video.get("filesize")) or "N/A"})'

        if video.get("acodec") != "none":
            bitrrate = int(video.get("abr"))
            # if bitrrate >= 70:
            audio[
                bitrrate] = f'🎵 {bitrrate}Kbps ({humanbytes(video.get("filesize")) or "N/A"})'

    btn += sublists(
        [
            InlineKeyboardButton(
                format_data.get(qual_),
                callback_data=f"ytdl_download_{vid}_{qual_}_v") for qual_ in [
                    format_144,
                    format_240,
                    format_360,
                    format_720,
                    format_1080,
                    format_1440,
                    format_2160,
                ] if qual_ != 0
        ],
        width=2,
    )
    btn += sublists(
        [
            InlineKeyboardButton(audio.get(key_),
                                 callback_data=f"ytdl_download_{vid}_{key_}_a")
            for key_ in sorted(audio.keys())
        ],
        width=2,
    )
    if body:
        vid_body = f"<b>[{x.get('title')}]({x.get('webpage_url')})</b>"

        # ERROR Media Caption Too Long
        # <code>{x.get("description")}</code>
        # ❯  <b>Duration:</b> {x.get('duration')}
        # ❯  <b>Views:</b> {x.get('view_count')}
        # ❯  <b>Upload date:</b> {x.get('upload_date')}
        # ❯  <b>Uploader:</b> [{x.get('uploader')}]({x.get('uploader_url')})

        return vid_body, InlineKeyboardMarkup(btn)
    return InlineKeyboardMarkup(btn)