Esempio n. 1
0
def add_from_magnet(update: Update, context: CallbackContext):
    logger.info('magnet url from %s', update.effective_user.first_name)

    magnet_link = update.message.text
    qb.download_from_link(magnet_link)
    # always returns an empty json:
    # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link

    torrent_hash = u.hash_from_magnet(magnet_link)
    logger.info('torrent hash from regex: %s', torrent_hash)

    torrent_keyboard_markup = kb.short_markup(torrent_hash)
    update.message.reply_html('Magnet added',
                              reply_markup=torrent_keyboard_markup,
                              quote=True)

    target_chat_id = notify_addition(update.effective_chat.id)
    if not target_chat_id:
        return

    text = "User {} [{}] added a magnet link, hash: <code>{}</code>".format(
        update.effective_user.full_name, update.effective_user.id,
        torrent_hash)
    context.bot.send_message(target_chat_id,
                             text,
                             reply_markup=torrent_keyboard_markup,
                             parse_mode=ParseMode.HTML,
                             disable_web_page_preview=True)
Esempio n. 2
0
def add_from_url(_, update):
    logger.info('url from %s', update.effective_user.first_name)

    magnet_link = update.message.text
    qb.download_from_link(magnet_link)
    # always returns an empty json:
    # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link

    update.message.reply_text('Torrent url added', quote=True)
Esempio n. 3
0
def add_from_magnet(_, update):
    logger.info('magnet url from %s', update.effective_user.first_name)

    magnet_link = update.message.text
    qb.download_from_link(magnet_link)
    # always returns an empty json:
    # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link

    torrent_hash = re.search(r'magnet:\?xt=urn:btih:([a-z0-9]+)(?:&.*)?',
                             magnet_link, re.I).group(1)
    logger.info('torrent hash from regex: %s', torrent_hash)

    update.message.reply_html('Magnet added',
                              reply_markup=kb.short_markup(torrent_hash),
                              quote=True)
Esempio n. 4
0
def add_from_url(update: Update, context: CallbackContext):
    logger.info('url from %s', update.effective_user.first_name)

    torrent_url = update.message.text

    kwargs = get_qbt_request_kwargs()

    qb.download_from_link(torrent_url, **kwargs)
    # always returns an empty json:
    # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link

    update.message.reply_text('Torrent url added', quote=True)

    notify_addition(update.effective_chat.id, context.bot,
                    update.effective_user, torrent_url)
Esempio n. 5
0
def add_from_url(update: Update, context: CallbackContext):
    logger.info('url from %s', update.effective_user.first_name)

    torrent_url = update.message.text
    qb.download_from_link(torrent_url)
    # always returns an empty json:
    # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link

    update.message.reply_text('Torrent url added', quote=True)

    target_chat_id = notify_addition(update.effective_chat.id)
    if not target_chat_id:
        return

    text = "User {} [{}] added a torrent from an url: {}".format(
        update.effective_user.full_name, update.effective_user.id, torrent_url)
    context.bot.send_message(target_chat_id,
                             text,
                             disable_web_page_preview=True)
Esempio n. 6
0
def add_from_magnet(update: Update, context: CallbackContext):
    logger.info('magnet url from %s', update.effective_user.first_name)

    magnet_link = update.message.text

    kwargs = get_qbt_request_kwargs()

    qb.download_from_link(magnet_link, **kwargs)
    # always returns an empty json:
    # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link

    torrent_hash = u.hash_from_magnet(magnet_link)
    logger.info('torrent hash from regex: %s', torrent_hash)

    update.message.reply_html('Magnet added',
                              reply_markup=kb.short_markup(torrent_hash),
                              quote=True)

    notify_addition(update.effective_chat.id, context.bot,
                    update.effective_user, torrent_hash)
Esempio n. 7
0
def add_from_url(update: Update, context: CallbackContext):
    logger.info('url from %s', update.effective_user.first_name)

    torrent_url = update.message.text

    kwargs = dict()
    if config.qbittorrent.get("added_torrents_tag", None):
        kwargs["tags"] = config.qbittorrent.added_torrents_tag

    qb.download_from_link(torrent_url, **kwargs)
    # always returns an empty json:
    # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link

    update.message.reply_text('Torrent url added', quote=True)

    target_chat_id = notify_addition(update.effective_chat.id)
    if not target_chat_id:
        return

    text = "User {} [{}] added a torrent from an url: {}".format(
        update.effective_user.full_name, update.effective_user.id,
        torrent_url
    )
    context.bot.send_message(target_chat_id, text)