Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo 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 ..."
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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