Esempio n. 1
0
def _mirror(bot, update, isTar=False):
    message_args = update.message.text.split(' ')
    try:
        link = message_args[1]
    except IndexError:
        link = ''
    LOGGER.info(link)
    link = link.strip()
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        file = None
        tag = reply_to.from_user.username
        media_array = [reply_to.document, reply_to.video, reply_to.audio]
        for i in media_array:
            if i is not None:
                file = i
                break

        if len(link) == 0:
            if file is not None:
                if file.mime_type != "application/x-bittorrent":
                    listener = MirrorListener(bot, update, isTar, tag)
                    tg_downloader = TelegramDownloadHelper(listener)
                    tg_downloader.add_download(
                        reply_to, f'{DOWNLOAD_DIR}{listener.uid}/')
                    sendStatusMessage(update, bot)
                    if len(Interval) == 0:
                        Interval.append(
                            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL,
                                        update_all_messages))
                    return
                else:
                    link = file.get_file().file_path
    else:
        tag = None
    if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
        sendMessage('No download source provided', bot, update)
        return

    try:
        link = direct_link_generator(link)
    except DirectDownloadLinkException as e:
        LOGGER.info(f'{link}: {e}')
    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    try:
        sup_link = ydl.extractMetaData(link)
    except Exception as e:
        sup_link = None
    if sup_link:
        ydl.add_download(link, f'{DOWNLOAD_DIR}{listener.uid}')
    else:
        aria = aria2_download.AriaDownloadHelper(listener)
        aria.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/')
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 2
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    try:
        link = args[0]
    except IndexError:
        msg = f"<b>/{BotCommands.WatchCommand} or /{BotCommands.TarWatchCommand}  [ʏᴛ_ᴅʟ sᴜᴘᴘᴏʀᴛᴇᴅ ʟɪɴᴋ] ⛽ᴛᴏ ᴍɪʀʀᴏʀ ᴡɪᴛʜ Yᴏᴜʀ ʏᴏᴜᴛᴜʙᴇ_ᴅʟ</b>.\n\n"
        msg += "<b>Exᴀᴍᴘʟᴇ Oꜰ Qᴜᴀʟɪᴛʏ :- Aᴜᴅɪᴏ, 144, 360, 720, 1080.\ɴNᴏᴛᴇ :- Qᴜᴀʟɪᴛʏ Is Oᴘᴛɪᴏɴᴀʟ</b>"
        sendMessage(msg, bot, update)
        return
    try:
        qual = args[1]
        if qual != "audio":
            qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
        qual = "bestvideo+bestaudio/best"
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None

    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}',
                           qual)).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 3
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    try:
        link = args[0]
    except IndexError:
        sendMessage(f'/{BotCommands.WatchCommand} [yt_dl supported link] to mirror with youtube_dl', bot, update)
        return
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None

    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(
        target=ydl.add_download,args=(
            link,
            os.path.join(
                DOWNLOAD_DIR,
                str(listener.uid)
            )
        )
    ).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 4
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    try:
        link = args[0]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [yt_dl supported link] [quality] to mirror with youtube_dl.\n\n"
        msg += "Example of quality :- audio, 144, 360, 720, 1080.\nNote :- Quality is optional"
        sendMessage(msg, bot, update)
        return
    try:
        qual = args[1]
        if qual != "audio":
            qual = f'best[height<={qual}]/bestvideo[height<={qual}]+bestaudio'
    except IndexError:
        qual = "best/bestvideo+bestaudio"
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None

    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}',
                           qual)).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 5
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    if update.message.from_user.last_name:
        last_name = f" {update.message.from_user.last_name}"
    else:
        last_name = ""
    if update.message.from_user.username:
        username = f"- @{update.message.from_user.username}"
    else:
        username = "******"
    name = f'<a href="tg://user?id={update.message.from_user.id}">{update.message.from_user.first_name}{last_name}</a>'

    try:
        link = args[0]
    except IndexError:
        sendMessage(
            f'/{BotCommands.WatchCommand} [yt_dl supported link] to mirror with youtube_dl',
            bot, update)
        return
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None

    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}')).start()
    msg = f"User: {name} {username} (<code>{update.message.from_user.id}</code>)\n" \
          f"Message: {update.message.text}"
    sendMessage(msg, bot, update)
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 6
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    try:
        link = args[0]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} (link yt) (kualitas) perintah biar bot nge mirror dari link yy.\n\n"
        msg += "Contoh Kualitas : 144,240,360,480,720,1080,2160p sama audio.\nNote :- Kualitas cuma tambahan doang"
        sendMessage(msg, bot, update)
        return
    try:
        qual = args[1]
        if qual != "audio":
            qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
        qual = "bestvideo+bestaudio/best"
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None

    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}',
                           qual)).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 7
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    try:
        link = args[0]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [yt_dl supported link] [quality] to mirror with youtube_dl.\n\n"
        msg += "Example of quality :- audio, 144, 360, 720, 1080.\n<b>Note :- Quality is optional</b> \n<i><u>If you didn't mention Quality, Highest Quality will be Uploaded To Google Drive.</u></i> \n\n<b> Type #watch_quality for example.</b>"
        sendMessage(msg, bot, update)
        return
    try:
      qual = args[1]
      if qual != "audio":
        qual = f'best[height<={qual}]/bestvideo[height<={qual}]+bestaudio'
    except IndexError:
      qual = "best/bestvideo+bestaudio"
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None

    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual)).start()
    msg = f"<b>Your Requested YT-DL Link has been added to the </b><b>/{BotCommands.StatusCommand}</b>"
    sendMessage(msg, bot, update)
    if len(Interval) == 0:
        Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 8
0
def select_format(update, context):
    query = update.callback_query
    user_id = query.from_user.id
    data = query.data
    msg = query.message
    data = data.split(" ")
    task_id = int(data[1])
    try:
        task_info = listener_dict[task_id]
    except:
        return editMessage("This is old task", msg)
    uid = task_info[1]
    if user_id != uid:
        return query.answer(text="Don't waste your time!", show_alert=True)
    elif data[2] == "dict":
        query.answer()
        qual = data[3]
        return _qual_subbuttons(task_id, qual, msg)
    elif data[2] == "back":
        query.answer()
        return editMessage('Choose Video Quality:', msg, task_info[4])
    elif data[2] == "audio":
        query.answer()
        if len(data) == 4:
            playlist = True
        else:
            playlist = False
        return _audio_subbuttons(task_id, msg, playlist)
    elif data[2] != "cancel":
        query.answer()
        listener = task_info[0]
        link = task_info[2]
        name = task_info[3]
        args = task_info[5]
        qual = data[2]
        if qual.startswith(
                'bv*['
        ):  # To not exceed telegram button bytes limits. Temp solution.
            height = resplit(r'\[|\]', qual, maxsplit=2)[1]
            qual = qual + f"+ba/b[{height}]"
        if len(data) == 4:
            playlist = True
        else:
            playlist = False
        ydl = YoutubeDLHelper(listener)
        Thread(target=ydl.add_download,
               args=(link, f'{DOWNLOAD_DIR}{task_id}', name, qual, playlist,
                     args)).start()
    del listener_dict[task_id]
    query.message.delete()
Esempio n. 9
0
def _watch(bot: Bot, update, isTar=False):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|')
    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [yt_dl supported link] [quality] |[CustomName] to mirror with youtube_dl.\n\n"
        msg += "<b>Note :- Quality and custom name are optional</b>\n\nExample of quality :- audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\nIf you want to use custom filename, plz enter it after |"
        msg += f"\n\nExample :-\n<code>/{BotCommands.WatchCommand} https://youtu.be/XsX3ATc3FbA 720 |Hello World</code>\n\n"
        msg += "This file will be downloaded in 720p quality and it's name will be <b>Hello World</b>"
        sendMessage(msg, bot, update)
        return
    try:
        if "|" in mssg:
            mssg = mssg.split("|")
            qual = mssg[0].split(" ")[2]
            if qual == "":
                raise IndexError
        else:
            qual = message_args[2]
        if qual != "audio":
            qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
        qual = "bestvideo+bestaudio/best"
    try:
        name = name_args[1]
    except IndexError:
        name = ""
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None
    pswd = ""
    listener = MirrorListener(bot, update, pswd, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual,
                           name)).start()
    sendMessage(
        f"<b>Your YouTube Link has been ADDED for Mirror 😋</b>\n👉 Check /{BotCommands.StatusCommand}",
        bot, update)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 10
0
def _watch(bot: Bot, update, isTar=False, isZip=False, isLeech=False):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|')

    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [youtube-dl supported link] [quality] |[CustomName] to mirror with youtube-dl.\n\n"
        msg += "<b>Note: Quality and custom name are optional</b>\n\nExample of quality: audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\nIf you want to use custom filename, enter it after |"
        msg += f"\n\nExample:\n<code>/{BotCommands.WatchCommand} https://youtu.be/Pk_TthHfLeE 720 |Slam</code>\n\n"
        msg += "This file will be downloaded in 720p quality and it's name will be <b>Slam</b>"
        sendMessage(msg, bot, update)
        return

    try:
        if "|" in mssg:
            mssg = mssg.split("|")
            qual = mssg[0].split(" ")[2]
            if qual == "":
                raise IndexError
        else:
            qual = message_args[2]
        if qual != "audio":
            qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
        qual = "bestvideo+bestaudio/best"

    try:
        name = name_args[1]
    except IndexError:
        name = ""

    pswd = ""
    listener = MirrorListener(bot,
                              update,
                              pswd,
                              isTar,
                              isZip=isZip,
                              isLeech=isLeech)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual,
                           name)).start()
    sendStatusMessage(update, bot)
Esempio n. 11
0
def _watch(bot: Bot, update, isTar=False):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|')
    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [Bisa pake link youtube] [Kualitas] |[Kustomnama] Biar di mirror in pake link youtube.\n\n"
        msg += "<b>Note :- Kualitas dan kustom nama itu pelengkap aja ya</b>\n\nMisalkan aja :- audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\nKalo pengen pake Nama kustom bisa dipake sehabis |"
        msg += f"\n\nExample :-\n<code>/{BotCommands.WatchCommand} https://youtu.be/ocX2FN1nguA 720 |Ini videoku</code>\n\n"
        msg += "File yanh kamu minta bakalan diupload dengan kualitas 720p dengan nama<b>Ini videoku</b>"
        sendMessage(msg, bot, update)
        return
    try:
        if "|" in mssg:
            mssg = mssg.split("|")
            qual = mssg[0].split(" ")[2]
            if qual == "":
                raise IndexError
        else:
            qual = message_args[2]
        if qual != "audio":
            qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
        qual = "bestvideo+bestaudio/best"
    try:
        name = name_args[1]
    except IndexError:
        name = ""
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None
    pswd = ""
    listener = MirrorListener(bot, update, pswd, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual,
                           name)).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 12
0
def _watch(bot: Bot, update, isTar=False):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|')
    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [yt_dl supported link] [quality] |[CustomName] tải nhanh với youtube_dl.\n\n"
        msg += "<b>Note :- Chất lượng và tên tùy chỉnh là tùy chọn</b>\n\nVí dụ về chất lượng :- audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\nNếu bạn muốn sử dụng tên tệp tùy chỉnh, vui lòng nhập nó sau |"
        msg += f"\n\nVD :-\n<code>/{BotCommands.WatchCommand} https://youtu.be/UnyLfqpyi94 720 |My video</code>\n\n"
        msg += "Tệp này sẽ được tải xuống ở chất lượng 720p và tên của nó sẽ là <b>My video </b>"
        sendMessage(msg, bot, update)
        return
    try:
        if "|" in mssg:
            mssg = mssg.split("|")
            qual = mssg[0].split(" ")[2]
            if qual == "":
                raise IndexError
        else:
            qual = message_args[2]
        if qual != "audio":
            qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
        qual = "bestvideo+bestaudio/best"
    try:
        name = name_args[1]
    except IndexError:
        name = ""
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None
    pswd = ""
    listener = MirrorListener(bot, update, pswd, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual,
                           name)).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 13
0
def _watch(bot: Bot, update, isTar=False):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|')
    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} : [yt_dl supported link] [quality] |[Custom Name] to mirror with youtube_dl.\n\n"
        msg += "<b>Note :- Quality and Custom Name are optional</b>\n\nExample of quality :- audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\n• <b>If you want to use Custom Filename</b>, enter it after |"
        msg += f"\n\nExample :-\n<code>/{BotCommands.WatchCommand} https://youtu.be/QMOadtGpwlw 720 |Ikson - New Day </code>\n\n"
        msg += "This file will be downloaded in 720p quality and it's name will be <b>Ikson - Alive</b>\n\n"
        msg += "• <b>if you want to convert to .mp3 / music</b>"
        msg += f"\n\nExample :-\n<code>/{BotCommands.WatchCommand} https://youtu.be/QMOadtGpwlw audio |Ikson - New Day </code>\n\n"
        msg += "This file will be downloaded in .mp3/audio and it's name will be <b>Ikson - Alive.mp3</b>\n\n"
        sendMessage(msg, bot, update)
        return
    try:
      if "|" in mssg:
        mssg = mssg.split("|")
        qual = mssg[0].split(" ")[2]
        if qual == "":
          raise IndexError
      else:
        qual = message_args[2]
      if qual != "audio":
        qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
      qual = "bestvideo+bestaudio/best"
    try:
      name = name_args[1]
    except IndexError:
      name = ""
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None
    pswd = ""
    listener = MirrorListener(bot, update, pswd, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual, name)).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 14
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    try:
        link = args[0]
    except IndexError:
        sendMessage(
            f'/{BotCommands.WatchCommand} Give Youtube Video Link Or Playlist Link',
            bot, update)
        return
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None

    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}')).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Esempio n. 15
0
def _watch(bot, update, isZip=False, isLeech=False):
    mssg = update.message.text
    user_id = update.message.from_user.id
    msg_id = update.message.message_id

    try:
        link = mssg.split(' ')[1].strip()
        if link.startswith(("|", "pswd:", "args:")):
            link = ''
    except IndexError:
        link = ''
    try:
        name_arg = mssg.split('|', maxsplit=1)
        if 'args: ' in name_arg[0]:
            raise IndexError
        else:
            name = name_arg[1]
        name = resplit(r' pswd: | args: ', name)[0]
        name = name.strip()
    except IndexError:
        name = ''
    try:
        pswd = mssg.split(' pswd: ')[1]
        pswd = pswd.split(' args: ')[0]
    except IndexError:
        pswd = None

    try:
        args = mssg.split(' args: ')[1]
    except IndexError:
        args = None

    if update.message.from_user.username:
        tag = f"@{update.message.from_user.username}"
    else:
        tag = update.message.from_user.mention_html(
            update.message.from_user.first_name)

    reply_to = update.message.reply_to_message
    if reply_to is not None:
        if len(link) == 0:
            link = reply_to.text.strip()
        if reply_to.from_user.username:
            tag = f"@{reply_to.from_user.username}"
        else:
            tag = reply_to.from_user.mention_html(
                reply_to.from_user.first_name)

    if not is_url(link):
        help_msg = "<b>Send link along with command line:</b>"
        help_msg += "\n<code>/command</code> {link} |newname pswd: mypassword [𝚣𝚒𝚙] args: x:y|x1:y1"
        help_msg += "\n\n<b>By replying to link:</b>"
        help_msg += "\n<code>/command</code> |newname pswd: mypassword [𝚣𝚒𝚙] args: x:y|x1:y1"
        help_msg += "\n\n<b>Args Example:</b> args: playliststart:^10|match_filter:season_number=18|matchtitle:S1"
        help_msg += "\n\n<b>NOTE:</b> Add `^` before integer, some values must be integer and some string."
        help_msg += " Like playlist_items:10 works with string so no need to add `^` before the number"
        help_msg += " but playlistend works only with integer so you must add `^` before the number like example above."
        help_msg += "\n\nCheck all arguments from this <a href='https://github.com/yt-dlp/yt-dlp/blob/a3125791c7a5cdf2c8c025b99788bf686edd1a8a/yt_dlp/YoutubeDL.py#L194'>FILE</a>."
        return sendMessage(help_msg, bot, update)

    listener = MirrorListener(bot,
                              update,
                              isZip,
                              isLeech=isLeech,
                              pswd=pswd,
                              tag=tag)
    buttons = button_build.ButtonMaker()
    best_video = "bv*+ba/b"
    best_audio = "ba/b"
    ydl = YoutubeDLHelper(listener)
    try:
        result = ydl.extractMetaData(link, name, True)
    except Exception as e:
        msg = str(e).replace('<', ' ').replace('>', ' ')
        return sendMessage(tag + " " + msg, bot, update)
    if 'entries' in result:
        for i in ['144', '240', '360', '480', '720', '1080', '1440', '2160']:
            video_format = f"bv*[height<={i}][ext=mp4]"
            buttons.sbutton(f"{i}-mp4", f"qu {msg_id} {video_format} t")
            video_format = f"bv*[height<={i}][ext=webm]"
            buttons.sbutton(f"{i}-webm", f"qu {msg_id} {video_format} t")
        buttons.sbutton("Audios", f"qu {msg_id} audio t")
        buttons.sbutton("Best Videos", f"qu {msg_id} {best_video} t")
        buttons.sbutton("Best Audios", f"qu {msg_id} {best_audio} t")
        buttons.sbutton("Cancel", f"qu {msg_id} cancel")
        YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(3))
        listener_dict[msg_id] = [
            listener, user_id, link, name, YTBUTTONS, args
        ]
        bmsg = sendMarkup('Choose Playlist Videos Quality:', bot, update,
                          YTBUTTONS)
    else:
        formats = result.get('formats')
        formats_dict = {}
        if formats is not None:
            for frmt in formats:
                if not frmt.get('tbr') or not frmt.get('height'):
                    continue

                if frmt.get('fps'):
                    quality = f"{frmt['height']}p{frmt['fps']}-{frmt['ext']}"
                else:
                    quality = f"{frmt['height']}p-{frmt['ext']}"

                if frmt.get('filesize'):
                    size = frmt['filesize']
                elif frmt.get('filesize_approx'):
                    size = frmt['filesize_approx']
                else:
                    size = 0

                if quality in formats_dict:
                    formats_dict[quality][frmt['tbr']] = size
                else:
                    subformat = {}
                    subformat[frmt['tbr']] = size
                    formats_dict[quality] = subformat

            for forDict in formats_dict:
                if len(formats_dict[forDict]) == 1:
                    qual_fps_ext = resplit(r'p|-', forDict, maxsplit=2)
                    height = qual_fps_ext[0]
                    fps = qual_fps_ext[1]
                    ext = qual_fps_ext[2]
                    if fps != '':
                        video_format = f"bv*[height={height}][fps={fps}][ext={ext}]"
                    else:
                        video_format = f"bv*[height={height}][ext={ext}]"
                    size = list(formats_dict[forDict].values())[0]
                    buttonName = f"{forDict} ({get_readable_file_size(size)})"
                    buttons.sbutton(str(buttonName),
                                    f"qu {msg_id} {video_format}")
                else:
                    buttons.sbutton(str(forDict),
                                    f"qu {msg_id} dict {forDict}")
        buttons.sbutton("Audios", f"qu {msg_id} audio")
        buttons.sbutton("Best Video", f"qu {msg_id} {best_video}")
        buttons.sbutton("Best Audio", f"qu {msg_id} {best_audio}")
        buttons.sbutton("Cancel", f"qu {msg_id} cancel")
        YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2))
        listener_dict[msg_id] = [
            listener, user_id, link, name, YTBUTTONS, args, formats_dict
        ]
        bmsg = sendMarkup('Choose Video Quality:', bot, update, YTBUTTONS)

    Thread(target=_auto_cancel, args=(bmsg, msg_id)).start()
Esempio n. 16
0
def _watch(bot, update, isZip=False, isLeech=False, pswd=None, tag=None):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|', maxsplit=1)
    user_id = update.message.from_user.id
    msg_id = update.message.message_id

    try:
        link = message_args[1].strip()
        if link.startswith("|") or link.startswith("pswd: "):
            link = ''
    except IndexError:
        link = ''

    try:
        name = name_args[1]
        name = name.split(' pswd: ')[0]
        name = name.strip()
    except IndexError:
        name = ''

    pswdMsg = mssg.split(' pswd: ')
    if len(pswdMsg) > 1:
        pswd = pswdMsg[1]

    if update.message.from_user.username:
        tag = f"@{update.message.from_user.username}"
    else:
        tag = update.message.from_user.mention_html(update.message.from_user.first_name)

    reply_to = update.message.reply_to_message
    if reply_to is not None:
        link = reply_to.text.strip()
        if reply_to.from_user.username:
            tag = f"@{reply_to.from_user.username}"
        else:
            tag = reply_to.from_user.mention_html(reply_to.from_user.first_name)

    if not is_url(link):
        help_msg = "<b>Send link along with command line:</b>"
        help_msg += "\n<code>/command</code> {link} |newname pswd: mypassword [𝚣𝚒𝚙]"
        help_msg += "\n\n<b>By replying to link:</b>"
        help_msg += "\n<code>/command</code> |newname pswd: mypassword [𝚣𝚒𝚙]"
        return sendMessage(help_msg, bot, update)

    LOGGER.info(link)
    listener = MirrorListener(bot, update, isZip, isLeech=isLeech, pswd=pswd, tag=tag)
    buttons = button_build.ButtonMaker()
    best_video = "bv*+ba/b"
    best_audio = "ba/b"
    ydl = YoutubeDLHelper(listener)
    try:
        result = ydl.extractMetaData(link, name, True)
    except Exception as e:
        return sendMessage(str(e), bot, update)
    if 'entries' in result:
        for i in ['144', '240', '360', '480', '720', '1080', '1440', '2160']:
            video_format = f"bv*[height<={i}][ext=mp4]+ba/b"
            buttons.sbutton(f"{i}-mp4", f"qu {msg_id} {video_format} t")
            video_format = f"bv*[height<={i}][ext=webm]+ba/b"
            buttons.sbutton(f"{i}-webm", f"qu {msg_id} {video_format} t")
        buttons.sbutton("Audios", f"qu {msg_id} audio t")
        buttons.sbutton("Best Videos", f"qu {msg_id} {best_video} t")
        buttons.sbutton("Best Audios", f"qu {msg_id} {best_audio} t")
        buttons.sbutton("Cancel", f"qu {msg_id} cancel")
        YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(3))
        listener_dict[msg_id] = [listener, user_id, link, name, YTBUTTONS]
        bmsg = sendMarkup('Choose Playlist Videos Quality:', bot, update, YTBUTTONS)
    else:
        formats = result.get('formats')
        formats_dict = {}
        if formats is not None:
            for frmt in formats:
                if not frmt.get('tbr') or not frmt.get('height'):
                    continue

                if frmt.get('fps'):
                    quality = f"{frmt['height']}p{frmt['fps']}-{frmt['ext']}"
                else:
                    quality = f"{frmt['height']}p-{frmt['ext']}"

                if frmt.get('filesize'):
                    size = frmt['filesize']
                elif frmt.get('filesize_approx'):
                    size = frmt['filesize_approx']
                else:
                    size = 0

                if quality in formats_dict:
                    formats_dict[quality][frmt['tbr']] = size
                else:
                    subformat = {}
                    subformat[frmt['tbr']] = size
                    formats_dict[quality] = subformat

            for forDict in formats_dict:
                if len(formats_dict[forDict]) == 1:
                    qual_fps_ext = resplit(r'p|-', forDict, maxsplit=2)
                    height = qual_fps_ext[0]
                    fps = qual_fps_ext[1]
                    ext = qual_fps_ext[2]
                    if fps != '':
                        video_format = f"bv*[height={height}][fps={fps}][ext={ext}]+ba/b"
                    else:
                        video_format = f"bv*[height={height}][ext={ext}]+ba/b"
                    size = list(formats_dict[forDict].values())[0]
                    buttonName = f"{forDict} ({get_readable_file_size(size)})"
                    buttons.sbutton(str(buttonName), f"qu {msg_id} {video_format}")
                else:
                    buttons.sbutton(str(forDict), f"qu {msg_id} dict {forDict}")
        buttons.sbutton("Audios", f"qu {msg_id} audio")
        buttons.sbutton("Best Video", f"qu {msg_id} {best_video}")
        buttons.sbutton("Best Audio", f"qu {msg_id} {best_audio}")
        buttons.sbutton("Cancel", f"qu {msg_id} cancel")
        YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2))
        listener_dict[msg_id] = [listener, user_id, link, name, YTBUTTONS, formats_dict]
        bmsg = sendMarkup('Choose Video Quality:', bot, update, YTBUTTONS)

    Thread(target=_auto_cancel, args=(bmsg, msg_id)).start()