diff --git a/nyaa/template_utils.py b/nyaa/template_utils.py
index 3fc11fa..f7e64af 100644
--- a/nyaa/template_utils.py
+++ b/nyaa/template_utils.py
@@ -1,15 +1,13 @@
import os.path
import re
-from base64 import b32encode
from datetime import datetime
from email.utils import formatdate
-from urllib.parse import urlencode
import flask
from werkzeug.urls import url_encode
from nyaa.backend import get_category_id_map
-from nyaa.torrents import get_default_trackers
+from nyaa.torrents import create_magnet
app = flask.current_app
bp = flask.Blueprint('template-utils', __name__)
@@ -20,20 +18,9 @@ _static_cache = {} # For static_cachebuster
# For processing ES links
@bp.app_context_processor
-def create_magnet_from_es_info():
- def _create_magnet_from_es_info(display_name, info_hash, max_trackers=5, trackers=None):
- if trackers is None:
- trackers = get_default_trackers()
-
- magnet_parts = [
- ('dn', display_name)
- ]
- for tracker in trackers[:max_trackers]:
- magnet_parts.append(('tr', tracker))
-
- b32_info_hash = b32encode(bytes.fromhex(info_hash)).decode('utf-8')
- return 'magnet:?xt=urn:btih:' + b32_info_hash + '&' + urlencode(magnet_parts)
- return dict(create_magnet_from_es_info=_create_magnet_from_es_info)
+def create_magnet_from_es_torrent():
+ # Since ES entries look like ducks, we can use the create_magnet as-is
+ return dict(create_magnet_from_es_torrent=create_magnet)
# ######################### TEMPLATE GLOBALS #########################
diff --git a/nyaa/templates/rss.xml b/nyaa/templates/rss.xml
index d9c8732..0b38019 100644
--- a/nyaa/templates/rss.xml
+++ b/nyaa/templates/rss.xml
@@ -12,7 +12,7 @@
{% if torrent.has_torrent and not magnet_links %}
{{ url_for('torrents.download', torrent_id=torrent.meta.id, _external=True) }}
{% else %}
- {{ create_magnet_from_es_info(torrent.display_name, torrent.info_hash) }}
+ {{ create_magnet_from_es_torrent(torrent) }}
{% endif %}