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()

    if len(link) == 0:
        if update.message.reply_to_message is not None:
            document = update.message.reply_to_message.document
            if document is not None and document.mime_type == "application/x-bittorrent":
                link = document.get_file().file_path
            else:
                sendMessage('Only torrent files can be mirrored from telegram', bot, update)
                return
    if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
        sendMessage('No download source provided', bot, update)
        return
    listener = MirrorListener(bot, update, isTar)
    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 _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:
        tag = reply_to.from_user.username
        if len(link) == 0:
            if reply_to.document is not None and reply_to.document.mime_type == "application/x-bittorrent":
                link = reply_to.document.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.error}')
    listener = MirrorListener(bot, update, isTar, tag)
    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. 3
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. 4
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('๐๐จ ๐๐จ๐ฐ๐ง๐ฅ๐จ๐š๐ ๐ฌ๐จ๐ฎ๐ซ๐œ๐ž ๐ฉ๐ซ๐จ๐ฏ๐ข๐๐ž๐. ๐…๐จ๐ซ๐ฆ๐š๐ญ /๐š–๐š’๐š›๐š›๐š˜๐š›๐šƒ๐š˜๐š›๐š›๐šŽ๐š—๐š๐šœ๐š๐š˜๐š›๐šŽ๐š‹๐š˜๐š ๐ฆ๐š๐ ๐ง๐ž๐ญ๐ฅ๐ข๐ง๐ค', bot, update)
        return

    try:
        link = direct_link_generator(link)
    except DirectDownloadLinkException as e:
        LOGGER.info(f'{link}: {e}')
    listener = MirrorListener(bot, update, isTar, tag)
    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))