Esempio n. 1
0
async def status_message_f(client, message):
    aria_i_p = await aria_start()
    # Show All Downloads
    downloads = aria_i_p.get_downloads()
    #
    DOWNLOAD_ICON = "๐Ÿ“ฅ"
    UPLOAD_ICON = "๐Ÿ“ค"
    #
    msg = ""
    for download in downloads:
        downloading_dir_name = "NA"
        try:
            downloading_dir_name = str(download.name)
        except:
            pass
        total_length_size = str(download.total_length_string())
        progress_percent_string = str(download.progress_string())
        down_speed_string = str(download.download_speed_string())
        up_speed_string = str(download.upload_speed_string())
        download_current_status = str(download.status)
        e_t_a = str(download.eta_string())
        current_gid = str(download.gid)
        #
        msg += f"<u>{downloading_dir_name}</u>"
        msg += " | "
        msg += f"{total_length_size}"
        msg += " | "
        msg += f"{progress_percent_string}"
        msg += " | "
        msg += f"{DOWNLOAD_ICON} {down_speed_string}"
        msg += " | "
        msg += f"{UPLOAD_ICON} {up_speed_string}"
        msg += " | "
        msg += f"{e_t_a}"
        msg += " | "
        msg += f"{download_current_status}"
        msg += " | "
        msg += f"<code>/cancel {current_gid}</code>"
        msg += " | "
        msg += "\n\n"
    LOGGER.info(msg)

    if msg == "":
        msg = "๐Ÿคทโ€โ™‚๏ธ No Active, Queued or Paused TORRENTs"

    currentTime = time.strftime(
        "%H:%M:%S",
        time.gmtime(time.time() - BOT_START_TIME))  #ctrl-c & ctrl-v ๐Ÿ˜‘
    total, used, free = shutil.disk_usage(".")
    total = humanbytes(total)
    used = humanbytes(used)
    free = humanbytes(free)

    #ms_g = f"<b>Bot Uptime</b>: <code>{currentTime}</code>\n" \
    #f"<b>Total disk space</b>: <code>{total}</code>\n" \
    #f"<b>Used</b>: <code>{used}</code>\n" \
    #f"<b>Free</b>: <code>{free}</code>\n"

    msg = ms_g + "\n" + msg
    await message.reply_text(msg, quote=True)
Esempio n. 2
0
async def status_message_f(client, message):
    aria_i_p = await aria_start()
    # Show All Downloads
    downloads = aria_i_p.get_downloads()
    #
    DOWNLOAD_ICON = "๐Ÿ“ฅ"
    UPLOAD_ICON = "๐Ÿ“ค"
    #
    msg = ""
    for download in downloads:
        downloading_dir_name = "NA"
        try:
            downloading_dir_name = str(download.name)
        except:
            pass
        total_length_size = str(download.total_length_string())
        progress_percent_string = str(download.progress_string())
        down_speed_string = str(download.download_speed_string())
        up_speed_string = str(download.upload_speed_string())
        download_current_status = str(download.status)
        e_t_a = str(download.eta_string())
        current_gid = str(download.gid)
        #
        msg += f"<u>{downloading_dir_name}</u>"
        msg += " | "
        msg += f"{total_length_size}"
        msg += " | "
        msg += f"{progress_percent_string}"
        msg += " | "
        msg += f"{DOWNLOAD_ICON} {down_speed_string}"
        msg += " | "
        msg += f"{UPLOAD_ICON} {up_speed_string}"
        msg += " | "
        msg += f"{e_t_a}"
        msg += " | "
        msg += f"{download_current_status}"
        msg += " | "
        msg += f"<code>{Commandi.CANCEL} {current_gid}</code>"
        msg += " | "
        msg += "\n\n"
    LOGGER.info(msg)

    if msg == "":
        msg = Loilacaztion.NO_TOR_STATUS

    currentTime = time_formatter((time.time() - BOT_START_TIME))
    total, used, free = shutil.disk_usage(".")
    total = humanbytes(total)
    used = humanbytes(used)
    free = humanbytes(free)

    ms_g = f"<b>Bot Uptime</b>: <code>{currentTime}</code>\n" \
        f"<b>Total disk space</b>: <code>{total}</code>\n" \
        f"<b>Used</b>: <code>{used}</code>\n" \
        f"<b>Free</b>: <code>{free}</code>\n"

    msg = ms_g + "\n" + msg
    await message.reply_text(msg, quote=True)
Esempio n. 3
0
async def status_message_f(client, message):
    aria_i_p = await aria_start()
    # Show All Downloads
    downloads = aria_i_p.get_downloads()
    #
    #
    msg = ""
    for download in downloads:
        downloading_dir_name = "NA"
        try:
            downloading_dir_name = str(download.name)
        except:
            pass
        if download.status == "active":
            total_length_size = str(download.total_length_string())
            progress_length = str(download.completed_length_string())
            down_speed_string = str(download.download_speed_string())
            up_speed_string = str(download.upload_speed_string())
            download_current_status = str(download.status)
            e_t_a = str(download.eta_string())
            msg += f"<b>Name</b>: <u>{downloading_dir_name}</u> \n<b>Speed</b>: D: {down_speed_string} U: {up_speed_string} \n<b>Progress</b>: {progress_length} of {total_length_size} \n<b>ETA</b>: {e_t_a}\n\n"
        # LOGGER.info(msg)

        if msg == "":
            msg = "ยญะชั†ะธะ ั’ะ‡ะ ะŽั“โ„–ะ˜ะˆ No Active, Queued or Paused TORRENTs"

    hr, mi, se = up_time(time.time() - BOT_START_TIME)
    total, used, free = shutil.disk_usage(".")
    total = humanbytes(total)
    used = humanbytes(used)
    free = humanbytes(free)

    ms_g = (f"<b>Bot Uptime</b>: {hr}:{mi}:{se}\n"
            f"<b>Used</b>: {used}\n"
            f"<b>Free</b>: {free}\n"
            f"<b>Total disk space</b>: {total}\n")
    # LOGGER.info(ms_g)

    msg = ms_g + "\n" + msg
    LOGGER.info(msg)
    if len(msg) > MAX_MESSAGE_LENGTH:
        with io.BytesIO(str.encode(msg)) as out_file:
            out_file.name = "status.text"
            await client.send_document(
                chat_id=message.chat.id,
                document=out_file,
            )
    else:
        await message.reply_text(msg, quote=True)
Esempio n. 4
0
async def upload_to_tg(message, local_file_name, from_user,
                       dict_contatining_uploaded_files):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = "๐Ÿ˜Ž For Daily Movies/Series Uploads "
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    caption_str += "\n Read Here for more "
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = await message.reply_text(
            "๐Ÿ˜ƒFound๐Ÿ›ƒ {} files".format(len(directory_contents)),
            quote=True
            # reply_to_message_id=message.message_id
        )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name, single_file),
                               from_user, dict_contatining_uploaded_files)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Unfortunately, Telegram does not support or allow ๐Ÿ˜Ž uploading this amount of file size\n."
                f"Detected ๐Ÿ“File Size: {d_f_s} \n"
                "\n๐Ÿ˜ฉ..trying to split the files ")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected ๐Ÿ“File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "Let ๐Ÿ˜ฉ me try to upload to Telegram, now ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    return dict_contatining_uploaded_files
Esempio n. 5
0
async def upload_to_tg(message, local_file_name, from_user,
                       dict_contatining_uploaded_files):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Disini berkas yang kamu kirim berupa link tadi"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = await message.reply_text(
            "Found {} files".format(len(directory_contents)),
            quote=True
            # reply_to_message_id=message.message_id
        )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name, single_file),
                               from_user, dict_contatining_uploaded_files)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Mohon maaf berkas berukuran lebih dari 1.5,GB tidak bisa di upload.\n"
                f"Terdeteksi ukuran berkas: {d_f_s} \n"
                "\nMencoba membagi beberapa berkas ๐Ÿ˜")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Terdeteksi ukuran berkas: {d_f_s} \n"
                f"<code>{ba_se_file_name}</code> Mencoba membagi {number_of_files} berkas.\n"
                "Mencoba meng-upload kembali ke Telegram, Sekarang ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    return dict_contatining_uploaded_files
Esempio n. 6
0
async def upload_to_tg(message, local_file_name, from_user,
                       dict_contatining_uploaded_files):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = await message.reply_text(
            "{} ta fayl yuborilmoqda...".format(len(directory_contents)),
            quote=True
            # reply_to_message_id=message.message_id
        )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name, single_file),
                               from_user, dict_contatining_uploaded_files)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram ushbu faylni qollamaydi.\n"
                f"Fayl xajmi juda katta: {d_f_s} รฐลธหœยก\n"
                "\nรฐลธยคโ€“ fayllarni ajratishga harakat qilinmoqda...")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Fayl xajmi juda katta: {d_f_s} รฐลธหœยก\n"
                f"<code>{ba_se_file_name}</code> fayllari {number_of_files} ga ajratildi\n"
                "Telegramga yuklanmoqda, kuting ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    return dict_contatining_uploaded_files
Esempio n. 7
0
async def upload_to_tg(message,
                       local_file_name,
                       from_user,
                       dict_contatining_uploaded_files,
                       edit_media=False):
    LOGGER.info(local_file_name)
    LOGGER.info(message.command)
    if message.reply_to_message is not None:
        txt = getattr(message.reply_to_message, 'text', '')
        if txt is not None and txt.find("rename") > -1 and len(
                txt[txt.find("rename") +
                    7:]) > 0 and os.path.isfile(local_file_name):
            rename_text = txt[txt.find("rename") + 7:]
            rename_text = await sanitize_text(rename_text)
            print("BAJ LocFileName Before : " + local_file_name)
            absName = os.path.join(os.path.dirname(local_file_name),
                                   rename_text + Path(local_file_name).suffix)
            os.rename(local_file_name, absName)
            local_file_name = absName
            print("BAJ LocFileName After : " + local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    if CHANNEL_URL is not None:
        caption_str += "\n\nJoin and Support: "
        caption_str += "<a href='"
        caption_str += f"{CHANNEL_URL}"
        caption_str += "'>"
        caption_str += f"{CHANNEL_URL}"
        caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                "Found {} files".format(len(directory_contents)),
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name,
                                            single_file), from_user,
                               dict_contatining_uploaded_files, edit_media)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– trying to split the files ๐ŸŒ๐ŸŒ๐ŸŒš")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "trying to upload to Telegram, now ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user,
                                                    edit_media)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 8
0
async def upload_to_tg(
    message,
    local_file_name,
    from_user,
    dict_contatining_uploaded_files,
    client,
    edit_media=False,
    yt_thumb=None,
):
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                f"Found {len(directory_contents)} files <a href='tg://user?id={from_user}'>๐Ÿค’</a>",
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(
                new_m_esg,
                os.path.join(local_file_name, single_file),
                from_user,
                dict_contatining_uploaded_files,
                client,
                edit_media,
                yt_thumb,
            )
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– trying to split the files ๐ŸŒ๐ŸŒ๐ŸŒš"
            )
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "trying to upload to Telegram, now ..."
            )
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(
                    message,
                    os.path.join(splitted_dir, le_file),
                    from_user,
                    dict_contatining_uploaded_files,
                    client,
                    edit_media,
                    yt_thumb,
                )
        else:
            sizze = os.path.getsize(local_file_name)
            sent_message = await upload_single_file(
                message,
                local_file_name,
                caption_str,
                from_user,
                client,
                edit_media,
                yt_thumb,
            )
            if sent_message is not None:
                dict_contatining_uploaded_files[
                    os.path.basename(local_file_name)
                ] = sent_message.message_id
            else:
                return
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 9
0
async def status_message_f(client, message):
    aria_i_p = await aria_start()
    # Show All Downloads
    downloads = aria_i_p.get_downloads()
    #
    DOWNLOAD_ICON = "๐Ÿ“ฅ"
    UPLOAD_ICON = "๐Ÿ“ค"
    #
    msg = ""
    for download in downloads:
        downloading_dir_name = "NA"
        try:
            downloading_dir_name = str(download.name)
        except:
            pass
        if download.status == "active":
            total_length_size = str(download.total_length_string())
            progress_percent_string = str(download.progress_string())
            down_speed_string = str(download.download_speed_string())
            up_speed_string = str(download.upload_speed_string())
            download_current_status = str(download.status)
            e_t_a = str(download.eta_string())
            current_gid = str(download.gid)
            #
            msg += f"<u>{downloading_dir_name}</u>"
            msg += " | "
            msg += f"{total_length_size}"
            msg += " | "
            msg += f"{progress_percent_string}"
            msg += " | "
            msg += f"{DOWNLOAD_ICON} {down_speed_string}"
            msg += " | "
            msg += f"{UPLOAD_ICON} {up_speed_string}"
            msg += " | "
            msg += f"{e_t_a}"
            msg += " | "
            msg += f"{download_current_status}"
            msg += " | "
            msg += f"<code>/cancel {current_gid}</code>"
            msg += " | "
            msg += "\n\n"
        # LOGGER.info(msg)

        if msg == "":
            msg = "๐Ÿคทโ€โ™‚๏ธ No Active, Queued or Paused TORRENTs \n I'm just chilling here ๐Ÿ˜Ž"

    hr, mi, se = up_time(time.time() - BOT_START_TIME)
    total, used, free = shutil.disk_usage(".")
    total = humanbytes(total)
    used = humanbytes(used)
    free = humanbytes(free)

    ms_g = (f"<b>STATUS</b>๐Ÿ“Š\n"
            f"<b>Bot Uptime</b>: <code>{hr} : {mi} : {se}</code>\n๐Ÿ“‚๐Ÿ’พ\n"
            f"<b>Total disk space</b>: <code>{total}</code>\n"
            f"<b>Used</b>: <code>{used}</code>\n"
            f"<b>Free</b>: <code>{free}</code>\n")
    # LOGGER.info(ms_g)

    msg = ms_g + "\n" + msg
    LOGGER.info(msg)
    if len(msg) > MAX_MESSAGE_LENGTH:
        with io.BytesIO(str.encode(msg)) as out_file:
            out_file.name = "status.text"
            await client.send_document(
                chat_id=message.chat.id,
                document=out_file,
            )
    else:
        await message.reply_text(msg, quote=True)
Esempio n. 10
0
async def extract_youtube_dl_formats(url, user_working_dir):
    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")
        command_to_exec.append("--proxy")
        command_to_exec.append("socks5://43.224.8.124:6667/")
    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:
        # 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)
        inline_keyboard = []
        thumb_image = "http://archive.is/wrODY/683dbe9224405f0f889018b84e425b6b05bfc350.jpg"
        for current_r_json in response_json:
            #
            # thumb_image = current_r_json["thumbnail"]
            #
            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")
                    format_ext = formats.get("ext")
                    approx_file_size = ""
                    if "filesize" in formats:
                        approx_file_size = humanbytes(formats["filesize"])
                    dipslay_str_uon = " " + format_string + " (" + format_ext.upper(
                    ) + ") " + approx_file_size + " "
                    cb_string_video = "{}|{}|{}|{}".format(
                        url, "video", format_id, format_ext)
                    ikeyboard = []
                    if "drive.google.com" in url:
                        if format_id == "source":
                            ikeyboard = [
                                pyrogram.InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(
                                        cb_string_video).encode("UTF-8"))
                            ]
                    else:
                        if format_string is not None and not "audio only" in format_string:
                            ikeyboard = [
                                pyrogram.InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(
                                        cb_string_video).encode("UTF-8"))
                            ]
                        else:
                            # special weird case :\
                            ikeyboard = [
                                pyrogram.InlineKeyboardButton(
                                    "SVideo [" + "] ( " + approx_file_size +
                                    " )",
                                    callback_data=(
                                        cb_string_video).encode("UTF-8"))
                            ]
                    inline_keyboard.append(ikeyboard)
                if duration is not None:
                    cb_string_64 = "{}|{}|{}|{}".format(
                        url, "audio", "64k", "mp3")
                    cb_string_128 = "{}|{}|{}|{}".format(
                        url, "audio", "128k", "mp3")
                    cb_string = "{}|{}|{}|{}".format(url, "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 = current_r_json["format_id"]
                format_ext = current_r_json["ext"]
                cb_string_video = "{}|{}|{}|{}".format(url, "video", format_id,
                                                       format_ext)
                inline_keyboard.append([
                    pyrogram.InlineKeyboardButton(
                        "SVideo",
                        callback_data=(cb_string_video).encode("UTF-8"))
                ])
            break
        reply_markup = pyrogram.InlineKeyboardMarkup(inline_keyboard)
        # LOGGER.info(reply_markup)
        succss_mesg = """Select the desired format: รฐลธโ€˜โ€ก
<u>mentioned</u> <i>file size might be approximate</i>"""
        return thumb_image, succss_mesg, reply_markup
Esempio n. 11
0
async def upload_to_tg(
    message,
    local_file_name,
    from_user,
    dict_contatining_uploaded_files
):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = "@movieserieshub."
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    caption_str += "\nHub: @movieserieshub\nSeries Archives: @allseriesarchive\nMovie Collection Archives: @allmoviesarchive\nRequest: @requestmoviesseries\nGallery๐ŸŽฌ: @movieseriesGallery ๐ŸŽฅ๐Ÿฟ \nJoin ๐Ÿ’ž Share ๐Ÿ’Support:https://t.me/joinchat/AAAAAErmWA5JzEmHS-DhYA"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = await message.reply_text(
            "Found {} files".format(len(directory_contents)),
            quote=True
            # reply_to_message_id=message.message_id
        )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(
                new_m_esg,
                os.path.join(local_file_name, single_file),
                from_user,
                dict_contatining_uploaded_files
            )
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support or allow ๐Ÿ˜Ž uploading this amount of file size.n"
                f"Detected File Size: {d_f_s} \n"
                "\n..trying to split the files "
            )
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "Let me try to upload to Telegram, now ..."
            )
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(
                    message,
                    os.path.join(splitted_dir, le_file),
                    from_user,
                    dict_contatining_uploaded_files
                )
        else:
            sent_message = await upload_single_file(
                message,
                local_file_name,
                caption_str,
                from_user
            )
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(local_file_name)] = sent_message.message_id
    return dict_contatining_uploaded_files
Esempio n. 12
0
async def upload_to_tg(message,
                       local_file_name,
                       from_user,
                       dict_contatining_uploaded_files,
                       edit_media=False):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                "Found {} files".format(len(directory_contents)),
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name,
                                            single_file), from_user,
                               dict_contatining_uploaded_files, edit_media)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                f"<B>Detected File Size:</B> {d_f_s}\n"
                f"The File Size Is More Then Telegram's Limit\n"
                f"<i>Attempting To Split The Files...</i>")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"<B>Detected File Size:</B> {d_f_s}\n"
                f"<code>{ba_se_file_name}</code> Splitted Into <i>{number_of_files}</i> Files.\n"
                "<i>Uploading To Telegram...</i>")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user,
                                                    edit_media)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 13
0
async def upload_to_tg(message,
                       local_file_name,
                       from_user,
                       dict_contatining_uploaded_files,
                       edit_media=False,
                       custom_caption=None):

    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    base_new_name = os.path.splitext(base_file_name)[0]
    extension_new_name = os.path.splitext(base_file_name)[1]
    b = base_new_name
    if local_file_name.upper().endswith(
        ("MP3", "M4A", "M4B", "FLAC", "WAV", "RAR", "7Z", "ZIP")):
        caption_str = f"<code>{base_new_name}{extension_new_name}</code>\n\n<b>{m3}</b>"
    elif b[:3] == "KDG" and local_file_name.lower().endswith(".mp4"):
        caption_str = f"<b>{base_new_name}{extension_new_name}\n\n@kdg_166 @korea_drama\n@kdgfiles</b>"
    elif b[:3] == "KDG" and local_file_name.lower().endswith(".mkv"):
        caption_str = f"<b>{base_new_name}{extension_new_name}\n\n@kdg_166 @korea_drama\n@kdgfiles\n\nMuxed English Subtitles\nPlay it via external player</b>"
    else:
        caption_str = f"{base_new_name}{extension_new_name}"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                "Found {} files".format(len(directory_contents)),
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name, single_file),
                               from_user, dict_contatining_uploaded_files,
                               edit_media, caption_str)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– trying to split the files ๐ŸŒ๐ŸŒ๐ŸŒš")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "trying to upload to Telegram, now ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user,
                                                    edit_media)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 14
0
async def upload_to_tg(
    message,
    local_file_name,
    from_user,
    dict_contatining_uploaded_files,
    client,
    edit_media=False,
    yt_thumb=None,
):
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                f"Ditemukan {len(directory_contents)} file <a href='tg://user?id={from_user}'>๐Ÿค’</a>",
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(
                new_m_esg,
                os.path.join(local_file_name, single_file),
                from_user,
                dict_contatining_uploaded_files,
                client,
                edit_media,
                yt_thumb,
            )
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram tidak bisa mengupload file ini.\n"
                f"Ukuran file yang terdeteksi: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– Mencoba memecah file... ๐ŸŒ๐ŸŒ๐ŸŒš")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Ukuran file terdeteksi: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> dipecah menjadi {number_of_files} file.\n"
                "Mencoba mengupload ke Telegram sekarang ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(
                    message,
                    os.path.join(splitted_dir, le_file),
                    from_user,
                    dict_contatining_uploaded_files,
                    client,
                    edit_media,
                    yt_thumb,
                )
        else:
            sizze = os.path.getsize(local_file_name)
            sent_message = await upload_single_file(
                message,
                local_file_name,
                caption_str,
                from_user,
                client,
                edit_media,
                yt_thumb,
            )
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
            else:
                return
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 15
0
async def upload_to_tg(
    message,
    local_file_name,
    from_user,
    dict_contatining_uploaded_files,
    edit_media=False
):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                "**Found** `{}` **Files ๐Ÿ“ก**".format(len(directory_contents)),
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(
                new_m_esg,
                os.path.join(local_file_name, single_file),
                from_user,
                dict_contatining_uploaded_files,
                edit_media
            )
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"**File Size: {d_f_s} ๐Ÿ˜ก**\n"
                "\n**๐Ÿค– Tying To Split The Files ๐ŸŒ๐ŸŒ๐ŸŒš**"
            )
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"**File Size : {d_f_s} ๐Ÿ˜ก**\n"
                f"<code>{ba_se_file_name}</code> **Splitted Into** `{number_of_files}` **Files.**\n"
                "**Starting Upload To Telegram Now ๐Ÿค—**"
            )
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(
                    message,
                    os.path.join(splitted_dir, le_file),
                    from_user,
                    dict_contatining_uploaded_files
                )
        else:
            sent_message = await upload_single_file(
                message,
                local_file_name,
                caption_str,
                from_user,
                edit_media
            )
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 16
0
async def status_message_f(client, message):
    aria_i_p = await aria_start()
    # Show All Downloads
    downloads = aria_i_p.get_downloads()
    #
    DOWNLOAD_ICON = "๐Ÿ“ฅ"
    UPLOAD_ICON = "๐Ÿ“ค"
    #
    msg = ""
    for download in downloads:
        downloading_dir_name = "NA"
        try:
            downloading_dir_name = str(download.name)
        except:
            pass
        if download.status == 'active':
            total_length_size = str(download.total_length_string())
            progress_percent_string = str(download.progress_string())
            down_speed_string = str(download.download_speed_string())
            up_speed_string = str(download.upload_speed_string())
            download_current_status = str(download.status)
            e_t_a = str(download.eta_string())
            current_gid = str(download.gid)
            #
            msg += f"<u>{downloading_dir_name}</u>"
            msg += " | "
            msg += f"{total_length_size}"
            msg += " | "
            msg += f"{progress_percent_string}"
            msg += " | "
            msg += f"{DOWNLOAD_ICON} {down_speed_string}"
            msg += " | "
            msg += f"{UPLOAD_ICON} {up_speed_string}"
            msg += " | "
            msg += f"{e_t_a}"
            msg += " | "
            msg += f"{download_current_status}"
            msg += " | "
            msg += f"<code>/cancel {current_gid}</code>"
            msg += " | "
            msg += "\n\n"
        #LOGGER.info(msg)

        if msg == "":
            msg = "๐Ÿคทโ€โ™‚๏ธ No Active, Queued or Paused TORRENTs"

    currentTime = time.strftime(
        "%H:%M:%S",
        time.gmtime(time.time() - BOT_START_TIME))  #ctrl-c & ctrl-v ๐Ÿ˜‘
    total, used, free = shutil.disk_usage(".")
    total = humanbytes(total)
    used = humanbytes(used)
    free = humanbytes(free)

    ms_g = f"<b>โžฝ ๐˜ฝ๐™ค๐™ฉ ๐™๐™ฅ๐™ฉ๐™ž๐™ข๐™š</b>: <code>{currentTime}</code>\n\n" \
        f"<b>โžฝ ๐™๐™ค๐™ฉ๐™–๐™ก ๐™™๐™ž๐™จ๐™  ๐™จ๐™ฅ๐™–๐™˜๐™š</b>: <code>{total}</code>\n\n" \
        f"<b>โžฝ ๐™๐™จ๐™š๐™™</b>: <code>{used}</code>\n\n" \
        f"<b>โžฝ ๐™๐™ง๐™š๐™š</b>: <code>{free}</code>\n"
    #LOGGER.info(ms_g)

    msg = ms_g + "\n" + msg
    LOGGER.info(msg)
    if len(msg) > MAX_MESSAGE_LENGTH:
        with io.BytesIO(str.encode(msg)) as out_file:
            out_file.name = "status.text"
            await client.send_document(
                chat_id=message.chat.id,
                document=out_file,
            )
    else:
        await message.reply_text(msg, quote=True)
Esempio n. 17
0
async def upload_to_tg(message,
                       local_file_name,
                       from_user,
                       dict_contatining_uploaded_files,
                       edit_media=False):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                f"Found {len(directory_contents)} files <a href='tg://user?id={from_user}'>๐Ÿค’</a>",
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name,
                                            single_file), from_user,
                               dict_contatining_uploaded_files, edit_media)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "๐™๐™š๐™ก๐™š๐™œ๐™ง๐™–๐™ข ๐™™๐™ค๐™š๐™จ ๐™ฃ๐™ค๐™ฉ ๐™จ๐™ช๐™ฅ๐™ฅ๐™ค๐™ง๐™ฉ ๐™ช๐™ฅ๐™ก๐™ค๐™–๐™™๐™ž๐™ฃ๐™œ ๐™ฉ๐™๐™ž๐™จ ๐™›๐™ž๐™ก๐™š.\n"
                f"๐˜ฟ๐™š๐™ฉ๐™š๐™˜๐™ฉ๐™š๐™™ ๐™๐™ž๐™ก๐™š ๐™Ž๐™ž๐™ฏ๐™š: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– ๐™๐™ง๐™ฎ๐™ž๐™ฃ๐™œ ๐™ฉ๐™ค ๐™จ๐™ฅ๐™ก๐™ž๐™ฉ ๐™ฉ๐™๐™š ๐™›๐™ž๐™ก๐™š๐™จ ๐ŸŒ๐ŸŒ๐ŸŒš")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"๐˜ฟ๐™š๐™ฉ๐™š๐™˜๐™ฉ๐™š๐™™ ๐™๐™ž๐™ก๐™š ๐™Ž๐™ž๐™ฏ๐™š: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "๐™๐™ง๐™ฎ๐™ž๐™ฃ๐™œ ๐™ฉ๐™ค ๐™ช๐™ฅ๐™ก๐™ค๐™–๐™™ ๐™ฉ๐™ค ๐™๐™š๐™ก๐™š๐™œ๐™ง๐™–๐™ข, ๐™ฃ๐™ค๐™ฌ ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user,
                                                    edit_media)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 18
0
async def extract_youtube_dl_formats(url, yt_dl_user_name, yt_dl_pass_word,
                                     user_working_dir):
    info_dict = {}
    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_country": "IN",
        })
    try:
        info = await yt_extract_info(
            video_url=url,
            download=False,
            ytdl_opts=info_dict,
            ie_key=None,
        )
    except yt_dlp.utils.DownloadError as ytdl_error:
        return None, str(ytdl_error), None

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

        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")
                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 = (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(
                    "SVideo",
                    callback_data=f"video|{extractor_key}|{format_id}|DL"))
            # LOGGER.info(ikeyboard)
    succss_mesg = "Select the desired format: รฐลธโ€˜โ€ก<br> <u>mentioned</u> <i>file size might be approximate</i>"
    return thumbnail, succss_mesg, ikeyboard
Esempio n. 19
0
             # reply_to_message_id=message.message_id
         )
     for single_file in directory_contents:
         # recursion: will this FAIL somewhere?
         await upload_to_tg(
             new_m_esg,
             os.path.join(local_file_name, single_file),
             from_user,
             dict_contatining_uploaded_files,
             edit_media,
             caption_str
         )
 else:
     if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
         LOGGER.info("TODO")
         d_f_s = humanbytes(os.path.getsize(local_file_name))
         i_m_s_g = await message.reply_text(
             "Large File ...!\n"
             f"๐Ÿคฉ Detected File Size: {d_f_s} ๐Ÿ˜‰\n"
             "\nSplitting the files ..."
         )
         splitted_dir = await split_large_files(local_file_name)
         totlaa_sleif = os.listdir(splitted_dir)
         totlaa_sleif.sort()
         number_of_files = len(totlaa_sleif)
         LOGGER.info(totlaa_sleif)
         ba_se_file_name = os.path.basename(local_file_name)
         await i_m_s_g.edit_text(
             f"Detected File Size: {d_f_s} ๐Ÿ˜‰\n"
             f"<code>{ba_se_file_name}</code> ๐Ÿ’ฅ Splitted into {number_of_files} Files\n"
             "๐Ÿš€ Trying To Upload ..."
Esempio n. 20
0
async def status_message_f(client, message):
    aria_i_p = await aria_start()
    # Show All Downloads
    downloads = aria_i_p.get_downloads()
    #
    DOWNLOAD_ICON = "๐Ÿ“ฅ"
    UPLOAD_ICON = "๐Ÿ“ค"
    #
    msg = ""
    for download in downloads:
        downloading_dir_name = "NA"
        try:
            downloading_dir_name = str(download.name)
        except:
            pass
        total_length_size = str(download.total_length_string())
        progress_percent_string = str(download.progress_string())
        down_speed_string = str(download.download_speed_string())
        up_speed_string = str(download.upload_speed_string())
        download_current_status = str(download.status)
        e_t_a = str(download.eta_string())
        current_gid = str(download.gid)
        #
        msg += f"<u>{downloading_dir_name}</u>"
        msg += " | "
        msg += f"{total_length_size}"
        msg += " | "
        msg += f"{progress_percent_string}"
        msg += " | "
        msg += f"{DOWNLOAD_ICON} {down_speed_string}"
        msg += " | "
        msg += f"{UPLOAD_ICON} {up_speed_string}"
        msg += " | "
        msg += f"{e_t_a}"
        msg += " | "
        msg += f"{download_current_status}"
        msg += " | "
        msg += f"<code>/cancel {current_gid}</code>"
        msg += " | "
        msg += "\n\n"
    LOGGER.info(msg)

    if msg == "":
        msg = "๐Ÿคทโ€โ™‚๏ธ No Active, Queued or Paused TORRENTs"

    currentTime = TimeFormatterr((time.time() - BOT_TIME))
    total, used, free = shutil.disk_usage(".")
    total = humanbytes(total)
    used = humanbytes(used)
    free = humanbytes(free)
    sent = humanbytes(psutil.net_io_counters().bytes_sent)
    recv = humanbytes(psutil.net_io_counters().bytes_recv)

    ms_g = f"<b>Bot Uptime</b>: <code>{currentTime}</code>\n" \
        f"<b>Total disk space</b>: <code>{total}</code>\n" \
        f"<b>Used</b>: <code>{used}</code>\n" \
        f"<b>Free</b>: <code>{free}</code>\n" \
        f"<b>Total Downloaded Data</b>: <code>{recv}</code>\n"
    #LOGGER.info(ms_g)

    msg = ms_g + "\n" + msg
    LOGGER.info(msg)
    if len(msg) > MAX_MSG_LENGTH:
        with io.BytesIO(str.encode(msg)) as out_file:
            out_file.name = "status.text"
            await client.send_document(
                chat_id=message.chat.id,
                document=out_file,
            )
    else:
        await message.reply_text(msg, quote=True)
Esempio n. 21
0
async def upload_to_tg(message, local_file_name, from_user,
                       dict_contatining_uploaded_files):
    LOGGER.info(local_file_name)
    #local_file_name = os.path.join(DOWNLOAD_LOCATION,local_file_name);
    #base_file_name = os.path.basename(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"LOGGER.info(directory_contents)
    LOGGER.info(local_file_name)
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                "Found {} files".format(len(directory_contents)),
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name, single_file),
                               from_user, dict_contatining_uploaded_files)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            #if os.path.getsize(local_file_name) > 150000000:

            LOGGER.info("TODO - Going to split")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"Detected File Size: {d_f_s} รฐลธหœยก\n"
                "\nรฐลธยคโ€“ Trying to split the files รขล“โ€žรขล“โ€šรฐลธโ€œยฆ")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)

            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} รฐลธหœยก\n"
                f"**{ba_se_file_name}**\n"
                f"Splitted into **{number_of_files} files**.\n"
                "Trying to upload to Telegram, now ...")
            akcpart = 1
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
                upprog = ""
                dwnprog = ""
                for aki in range(akcpart):
                    upprog += "รฐลธโ€ยด"
                for aki in range(number_of_files - akcpart):
                    dwnprog += "รขยญโ€ข"
                prog = upprog + dwnprog
                await i_m_s_g.edit_text(
                    f"Uploaded part **[ {akcpart}/{number_of_files} ]** รฐลธโ€œยค\n"
                    f"{prog}")
                akcpart = akcpart + 1
            await i_m_s_g.edit_text("All parts are uploaded รขล“โ€ฆ\n")
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 22
0
async def upload_to_tg(message,
                       local_file_name,
                       from_user,
                       dict_contatining_uploaded_files,
                       edit_media=False):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<b>"
    caption_str += base_file_name
    caption_str += "</b>"
    # caption_str += "\n\n๐Ÿ’ฌ @DamienHelp"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                f"Found {len(directory_contents)} files <a href='tg://user?id={from_user}'>๐Ÿค’</a>",
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name,
                                            single_file), from_user,
                               dict_contatining_uploaded_files, edit_media)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram Does Not Support Uploading This File.\n"
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– Trying To Split The Files ๐ŸŒ๐ŸŒš")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<b>{ba_se_file_name}</b> Splitted Into {number_of_files} files.\n"
                "๐Ÿ’ฌ Trying To Upload To Telegram,Now ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user,
                                                    edit_media)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 23
0
async def upload_to_tg(
    message,
    local_file_name,
    from_user,
    dict_contatining_uploaded_files,
    edit_media=False
):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                "๐—™๐—ผ๐˜‚๐—ป๐—ฑ {} ๐—ณ๐—ถ๐—น๐—ฒ๐˜€".format(len(directory_contents)),
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(
                new_m_esg,
                os.path.join(local_file_name, single_file),
                from_user,
                dict_contatining_uploaded_files,
                edit_media
            )
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "๐—ง๐—ฒ๐—น๐—ฒ๐—ด๐—ฟ๐—ฎ๐—บ ๐—ฑ๐—ผ๐—ฒ๐˜€ ๐—ป๐—ผ๐˜ ๐˜€๐˜‚๐—ฝ๐—ฝ๐—ผ๐—ฟ๐˜ ๐—จ๐—ฝ๐—น๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐— ๐—ผ๐—ฟ๐—ฒ ๐—ง๐—ต๐—ฒ๐—ป ๐Ÿฎ๐—š๐—•\n"
                f"๐——๐—ฒ๐˜๐—ฒ๐—ฐ๐˜๐—ฒ๐—ฑ ๐—™๐—ถ๐—น๐—ฒ ๐—ฆ๐—ถ๐˜‡๐—ฒ: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– ๐˜๐—ฟ๐˜†๐—ถ๐—ป๐—ด ๐˜๐—ผ ๐˜€๐—ฝ๐—น๐—ถ๐˜ ๐˜๐—ต๐—ฒ ๐—ณ๐—ถ๐—น๐—ฒ๐˜€ ๐ŸŒ๐ŸŒ๐ŸŒš"
            )
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"๐——๐—ฒ๐˜๐—ฒ๐—ฐ๐˜๐—ฒ๐—ฑ ๐—™๐—ถ๐—น๐—ฒ ๐—ฆ๐—ถ๐˜‡๐—ฒ: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> ๐——๐—ถ๐˜ƒ๐—ถ๐—ฑ๐—ฒ๐˜€ ๐—ถ๐—ป๐˜๐—ผ {number_of_files} files.\n"
                "๐—ง๐—ฟ๐˜†๐—ถ๐—ป๐—ด ๐Ÿฎ ๐—จ๐—ฝ๐—น๐—ผ๐—ฎ๐—ฑ ๐Ÿฎ ๐—ง๐—ฒ๐—น๐—ฒ๐—ด๐—ฟ๐—ฎ๐—บ, ๐—ป๐—ผ๐˜„ ..."
            )
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(
                    message,
                    os.path.join(splitted_dir, le_file),
                    from_user,
                    dict_contatining_uploaded_files
                )
        else:
            sent_message = await upload_single_file(
                message,
                local_file_name,
                caption_str,
                from_user,
                edit_media
            )
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 24
0
async def upload_to_tg(message,
                       local_file_name,
                       from_user,
                       dict_contatining_uploaded_files,
                       edit_media=False):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    caption_str += "<code>"
    caption_str += base_file_name
    caption_str += "</code>"
    caption_str += "\n\n"
    caption_str += "<a href='tg://user?id="
    caption_str += str(from_user)
    caption_str += "'>"
    caption_str += "Here is the file to the link you sent"
    caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                "I've Found Only {} File(s).๐Ÿ“".format(len(directory_contents)),
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name,
                                            single_file), from_user,
                               dict_contatining_uploaded_files, edit_media)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram Does Not Support Uploading File Size Greater Than 1.96GB And Your File is {d_f_s}.\n"
                f"Your File Size โ€ข {d_f_s} \n"
                "\nSo I'm Trying To Split This File")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Your File Size โ€ข {d_f_s}\n"
                f"Your File โ€ข <code>{ba_se_file_name}</code> Splitted Into {number_of_files} Files.\n"
                "Uploading To Telegram")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user,
                                                    edit_media)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 25
0
async def extract_youtube_dl_formats(url, user_working_dir):
    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")
    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:
        # logger.warn("Status : FAIL", exc.returncode, exc.output)
        error_message = e_response.replace(
            "แ‹ญแ‰…แˆญแ‰ณ แˆแŠ•แˆ แŠแŒˆแˆญ แŠจแˆ›แˆˆแ‰ณแ‰น แ‰ แŠแ‰ต แ‹จแˆ‹แŠฉแ‰ตแŠ• link แ‹ฐแŒ‹แŒแˆ˜แ‹ แ‹ญแ‹ฉ แˆŒแˆ‹ แ‰ฝแŒแˆญ แŠซแˆˆ แ‰€แŒแˆ แŠ แŠ“แŒแˆฉแŠ)
        return 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)
        inline_keyboard = []
        for current_r_json in response_json:
            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")
                    format_ext = formats.get("ext")
                    approx_file_size = ""
                    if "filesize" in formats:
                        approx_file_size = humanbytes(formats["filesize"])
                    dipslay_str_uon = " " + format_string + " (" + format_ext.upper() + ") " + approx_file_size + " "
                    cb_string_video = "{}|{}|{}".format(
                        "video", format_id, format_ext)
                    ikeyboard = []
                    if "drive.google.com" in url:
                        if format_id == "source":
                            ikeyboard = [
                                pyrogram.InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(cb_string_video).encode("UTF-8")
                                )
                            ]
                    else:
                        if format_string is not None and not "audio only" in format_string:
                            ikeyboard = [
                                pyrogram.InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(cb_string_video).encode("UTF-8")
                                )
                            ]
                        else:
                            # special weird case :\
                            ikeyboard = [
                                pyrogram.InlineKeyboardButton(
                                    "SVideo [" +
                                    "] ( " +
                                    approx_file_size + " )",
                                    callback_data=(cb_string_video).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 = current_r_json["format_id"]
                format_ext = current_r_json["ext"]
                cb_string_video = "{}|{}|{}".format(
                    "video", format_id, format_ext)
                inline_keyboard.append([
                    pyrogram.InlineKeyboardButton(
                        "SVideo",
                        callback_data=(cb_string_video).encode("UTF-8")
                    )
                ])
            break
        reply_markup = pyrogram.InlineKeyboardMarkup(inline_keyboard)
        # LOGGER.info(reply_markup)
        succss_mesg = """แ‹จแˆšแˆแˆแŒ‰แ‰ตแŠ• format: แ‹ญแˆแˆจแŒก ๐Ÿ‘‡
<u>mentioned</u> <i>file size might be approximate</i>"""
        return succss_mesg, reply_markup
Esempio n. 26
0
async def status_message_f(
        client, message):  # weird code but 'This is the way' @gautamajay52
    aria_i_p = await aria_start()
    # Show All Downloads
    to_edit = await message.reply(".......")
    chat_id = int(message.chat.id)
    mess_id = int(to_edit.message_id)
    async with _lock:
        if len(gid_dict[chat_id]) == 0:
            gid_dict[chat_id].append(mess_id)
        else:
            if not mess_id in gid_dict[chat_id]:
                await client.delete_messages(chat_id, gid_dict[chat_id])
                gid_dict[chat_id].pop()
                gid_dict[chat_id].append(mess_id)

    prev_mess = "By gautamajay52"
    await message.delete()
    while True:
        downloads = aria_i_p.get_downloads()
        msg = ""
        for file in downloads:
            downloading_dir_name = "NA"
            try:
                downloading_dir_name = str(file.name)
            except:
                pass
            if file.status == "active":
                is_file = file.seeder
                if is_file is None:
                    msgg = f"<b>Conn:</b> {file.connections}"
                else:
                    msgg = f"<b>Peers:</b> {file.connections} | <b>Seeders:</b> {file.num_seeders}"

                percentage = int(file.progress_string(0).split('%')[0])
                prog = "[{0}{1}]".format(
                    "".join([
                        FINISHED_PROGRESS_STR
                        for i in range(math.floor(percentage / 5))
                    ]), "".join([
                        UN_FINISHED_PROGRESS_STR
                        for i in range(20 - math.floor(percentage / 5))
                    ]))
                msg += f"<b>โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•</b>\n"
                msg += f"\n<b>{downloading_dir_name}</b>"
                msg += f"\n<b>{prog}</b>"
                msg += f"\n<b>Speed</b>: {file.download_speed_string()}"
                msg += f"\n<b>Status</b>: {file.progress_string()} <b>of</b> {file.total_length_string()}"
                msg += f"\n<b>ETA:</b> {file.eta_string()}"
                msg += f"\n{msgg}"
                msg += f"\n<b>To Cancel:</b> <code>/cancel {file.gid}</code>"
                msg += "\n"

        hr, mi, se = up_time(time.time() - BOT_START_TIME)
        total, used, free = shutil.disk_usage(".")
        ram = psutil.virtual_memory().percent
        cpu = psutil.cpu_percent()
        total = humanbytes(total)
        used = humanbytes(used)
        free = humanbytes(free)

        ms_g = (
            f"<b>Bot Uptime</b>: <code>{hr} : {mi} : {se}</code>\n"
            f"<b>T:</b> <code>{total}</code> <b>U:</b> <code>{used}</code> <b>F:</b> <code>{free}</code>\n"
            f"<b>RAM:</b> <code>{ram}%</code> <b>CPU:</b> <code>{cpu}%</code>\n"
        )
        if msg == "":
            msg = "๐Ÿคทโ€โ™‚๏ธ No Active, Queued or Paused TORRENTs"
            msg = ms_g + "\n" + msg
            await to_edit.edit(msg)
            break
        msg = msg + "\n" + ms_g
        if len(msg) > MAX_MESSAGE_LENGTH:  # todo - will catch later
            with io.BytesIO(str.encode(msg)) as out_file:
                out_file.name = "status.text"
                await client.send_document(
                    chat_id=message.chat.id,
                    document=out_file,
                )
            break
        else:
            if msg != prev_mess:
                try:
                    await to_edit.edit(msg, parse_mode="html")
                except MessageIdInvalid as df:
                    break
                except MessageNotModified as ep:
                    LOGGER.info(ep)
                    await asyncio.sleep(EDIT_SLEEP_TIME_OUT)
                except FloodWait as e:
                    LOGGER.info(e)
                    time.sleep(e.x)
                await asyncio.sleep(EDIT_SLEEP_TIME_OUT)
                prev_mess = msg
Esempio n. 27
0
async def extract_youtube_dl_formats(url, yt_dl_user_name, yt_dl_pass_word, user_working_dir):
    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 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)
    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:
        # 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)
        inline_keyboard = []
        #
        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
                    )
                    ikeyboard = []
                    if "drive.google.com" in url:
                        if format_id == "source":
                            ikeyboard = [
                                InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(cb_string_video).encode("UTF-8")
                                )
                            ]
                    else:
                        if format_string is not None and not "audio only" in format_string:
                            ikeyboard = [
                                InlineKeyboardButton(
                                    dipslay_str_uon,
                                    callback_data=(cb_string_video).encode("UTF-8")
                                )
                            ]
                        else:
                            # special weird case :\
                            ikeyboard = [
                                InlineKeyboardButton(
                                    "SVideo [" +
                                    "] ( " +
                                    approx_file_size + " )",
                                    callback_data=(cb_string_video).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 = current_r_json["format_id"]
                format_ext = current_r_json["ext"]
                cb_string_video = "{}|{}|{}|{}".format(
                    "video", format_id, format_ext, "DL"
                )
                inline_keyboard.append([
                    InlineKeyboardButton(
                        "SVideo",
                        callback_data=(cb_string_video).encode("UTF-8")
                    )
                ])
            # TODO: :\
            break
        reply_markup = InlineKeyboardMarkup(inline_keyboard)
        # LOGGER.info(reply_markup)
        succss_mesg = """Select the desired format: รฐลธโ€˜โ€ก
<u>mentioned</u> <i>file size might be approximate</i>"""
        return thumb_image, succss_mesg, reply_markup
Esempio n. 28
0
async def upload_to_tg(message, local_file_name, from_user,
                       dict_contatining_uploaded_files):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    #caption_str += "<code>"
    caption_str += base_file_name  # + local_file_name + from_user + dict_contatining_uploaded_files

    #caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        #for f in directory_contents:
        #   f_name , f_ext = os.path.splitext(f)
        #  f_name = '@GTMovise ' + f_name.strip()
        # new_name = '{}{}'.format(f_name, f_ext)
        #os.rename(f, new_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = await message.reply_text(
            "Found {} files".format(len(directory_contents)),
            quote=True
            # reply_to_message_id=message.message_id
        )

        for single_file in directory_contents:
            #os.rename(r'./' + local_file_name +'/' +single_file),r'./' + local_file_name +'/@GTMovise ' + single_file)
            #single_file = '@GTMovise ' + single_file
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name, single_file),
                               from_user, dict_contatining_uploaded_files)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– trying to split the files ๐ŸŒ๐ŸŒ๐ŸŒš")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "trying to upload to Telegram, now ...")
            for le_file in totlaa_sleif:

                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    return dict_contatining_uploaded_files
Esempio n. 29
0
async def upload_to_tg(message,
                       local_file_name,
                       from_user,
                       dict_contatining_uploaded_files,
                       edit_media=False,
                       custom_caption=None):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    LOGGER.info(base_file_name)
    caption_str = custom_caption
    if not (caption_str and edit_media):
        LOGGER.info("fall-back to default file_name")
        caption_str = "<code>"
        caption_str += base_file_name
        caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        # if not message.photo:
        new_m_esg = await message.reply_text(
            "Found {} files".format(len(directory_contents)),
            quote=True
            # reply_to_message_id=message.message_id
        )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?
            await upload_to_tg(new_m_esg,
                               os.path.join(local_file_name, single_file),
                               from_user, dict_contatining_uploaded_files,
                               edit_media, caption_str)
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– trying to split the files ๐ŸŒ๐ŸŒ๐ŸŒš")
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "trying to upload to Telegram, now ...")
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(message,
                                   os.path.join(splitted_dir, le_file),
                                   from_user, dict_contatining_uploaded_files)
        else:
            sent_message = await upload_single_file(message, local_file_name,
                                                    caption_str, from_user,
                                                    edit_media)
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(
                    local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files
Esempio n. 30
0
async def upload_to_tg(
    message,
    local_file_name,
    from_user,
    dict_contatining_uploaded_files,
    edit_media=False
):
    LOGGER.info(local_file_name)
    base_file_name = os.path.basename(local_file_name)
    caption_str = ""
    # caption_str += "<code>"
    caption_str += base_file_name
    # caption_str += "</code>"
    # caption_str += "\n\n"
    # caption_str += "<a href='tg://user?id="
    # caption_str += str(from_user)
    # caption_str += "'>"
    # caption_str += "Here is the file to the link you sent"
    # caption_str += "</a>"
    if os.path.isdir(local_file_name):
        directory_contents = os.listdir(local_file_name)
        directory_contents.sort()
        # number_of_files = len(directory_contents)
        LOGGER.info(directory_contents)
        new_m_esg = message
        if not message.photo:
            new_m_esg = await message.reply_text(
                f"Found {len(directory_contents)} files <a href='tg://user?id={from_user}'>๐Ÿค’</a>",
                quote=True
                # reply_to_message_id=message.message_id
            )
        for single_file in directory_contents:
            # recursion: will this FAIL somewhere?

            if CUSTOM_FILE_NAME:
                new_file_name = single_file
                if BLACKLISTED_WORDS:
                    for element in BLACKLISTED_WORDS:   
                        if element in new_file_name :
                            new_file_name = new_file_name.replace(element,'')
                    new_file_name = new_file_name.strip()
                os.rename(os.path.join(local_file_name, single_file), os.path.join(local_file_name, f"{CUSTOM_FILE_NAME}{new_file_name}"))
                single_file = f"{CUSTOM_FILE_NAME}{new_file_name}"

            await upload_to_tg(
                new_m_esg,
                os.path.join(local_file_name, single_file),
                from_user,
                dict_contatining_uploaded_files,
                edit_media
            )
    else:
        if os.path.getsize(local_file_name) > TG_MAX_FILE_SIZE:
            LOGGER.info("TODO")
            d_f_s = humanbytes(os.path.getsize(local_file_name))
            i_m_s_g = await message.reply_text(
                "Telegram does not support uploading this file.\n"
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                "\n๐Ÿค– trying to split the files ๐ŸŒ๐ŸŒ๐ŸŒš"
            )
            splitted_dir = await split_large_files(local_file_name)
            totlaa_sleif = os.listdir(splitted_dir)
            totlaa_sleif.sort()
            number_of_files = len(totlaa_sleif)
            LOGGER.info(totlaa_sleif)
            ba_se_file_name = os.path.basename(local_file_name)
            await i_m_s_g.edit_text(
                f"Detected File Size: {d_f_s} ๐Ÿ˜ก\n"
                f"<code>{ba_se_file_name}</code> splitted into {number_of_files} files.\n"
                "trying to upload to Telegram, now ..."
            )
            for le_file in totlaa_sleif:
                # recursion: will this FAIL somewhere?
                await upload_to_tg(
                    message,
                    os.path.join(splitted_dir, le_file),
                    from_user,
                    dict_contatining_uploaded_files
                )
        else:
            sent_message = await upload_single_file(
                message,
                local_file_name,
                caption_str,
                from_user,
                edit_media
            )
            if sent_message is not None:
                dict_contatining_uploaded_files[os.path.basename(local_file_name)] = sent_message.message_id
    # await message.delete()
    return dict_contatining_uploaded_files