Exemple #1
0
def on_expand_magnet_button(update: Update, context: CallbackContext):
    logger.info('%d: magnet with trackers button', update.effective_user.id)

    release_id = context.match[1]
    release = db.release_by_id(release_id)

    reply_markup = InlineKeyboard.collapse_magnet_button(release_id)
    update.callback_query.edit_message_text(MAGNET_TEXT.format(
        hash=release['hash'], trackers_list='&tr='.join(TRACKERS)),
                                            disable_web_page_preview=True,
                                            reply_markup=reply_markup,
                                            parse_mode=ParseMode.HTML)
    update.callback_query.answer(Strings.CB_ANSWER_TRACKERS)
def on_expand_magnet_button(update: Update, context: CallbackContext):
    logger.info('%d: magnet with trackers button', update.effective_user.id)

    release_id = context.match[1]
    release = db.get_release(release_id, raw=True)

    # if available, use the magnet we fetched from the forum page. Otherwise build it from the hash
    if not release['magnet'] and not release['hash'] and release['torrent_url']:
        # this happens when we haven't been able to fecth the forum page to scrape the magnet
        text = Strings.TORRENT_URL_NO_MAGNET.format(**release)
    elif not release['magnet'] and release['hash']:
        text = MAGNET_TEXT.format(hash=release['hash'],
                                  trackers_list='&tr='.join(TRACKERS))
    elif release['magnet']:
        text = '<code>{}</code>'.format(release['magnet'])
    else:
        text = Strings.MAGNET_NOT_AVAILABLE

    reply_markup = InlineKeyboard.collapse_magnet_button(release_id)
    update.callback_query.edit_message_text(text,
                                            disable_web_page_preview=True,
                                            reply_markup=reply_markup,
                                            parse_mode=ParseMode.HTML)
    update.callback_query.answer(Strings.CB_ANSWER_TRACKERS)