mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 11:40:01 +00:00
finished up rss, changed rss behavior to include pre-defined trackers only, also cleaned up debug statements
This commit is contained in:
parent
899aa01473
commit
2005174358
|
@ -178,7 +178,7 @@ def home(rss):
|
|||
query_args['term'] = ''
|
||||
else: # Otherwise, use db search for everything
|
||||
query_args['term'] = term or ''
|
||||
print(query_args)
|
||||
|
||||
query = search_db(**query_args)
|
||||
if rss:
|
||||
return render_rss('/', query, use_elastic=False)
|
||||
|
@ -287,7 +287,6 @@ def _jinja2_filter_rfc822(datestr, fmt=None):
|
|||
|
||||
|
||||
def render_rss(label, query, use_elastic):
|
||||
print(query)
|
||||
rss_xml = flask.render_template('rss.xml',
|
||||
use_elastic=use_elastic,
|
||||
term=label,
|
||||
|
|
|
@ -177,8 +177,8 @@ def search_elastic(term='', user=None, sort='id', order='desc',
|
|||
s = s.highlight("display_name")
|
||||
|
||||
# Return query, uncomment print line to debug query
|
||||
from pprint import pprint
|
||||
print(json.dumps(s.to_dict()))
|
||||
# from pprint import pprint
|
||||
# print(json.dumps(s.to_dict()))
|
||||
return s.execute()
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<item>
|
||||
<title>{{ torrent.display_name }}</title>
|
||||
{% if use_elastic %}
|
||||
<link>{{ torrent.info_hash }}</link>
|
||||
<link>{{ create_magnet_from_info(torrent.display_name, torrent.info_hash) }}</link>
|
||||
<guid isPermaLink="true">{{ url_for('view_torrent', torrent_id=torrent.meta.id, _external=True) }}</guid>
|
||||
<pubDate>{{ torrent.created_time|rfc822_es }}</pubDate>
|
||||
{% else %}
|
||||
|
|
|
@ -66,7 +66,11 @@
|
|||
{% endif %}
|
||||
<td style="white-space: nowrap;text-align: center;">
|
||||
{% if torrent.has_torrent %}<a href="{{ url_for('download_torrent', torrent_id=torrent.id) }}"><i class="fa fa-fw fa-download"></i></a>{% endif %}
|
||||
{% if use_elastic %}
|
||||
<a href="{{ create_magnet_from_info(torrent.display_name, torrent.info_hash) }}"><i class="fa fa-fw fa-magnet"></i></a>
|
||||
{% else %}
|
||||
<a href="{{ torrent.magnet_uri }}"><i class="fa fa-fw fa-magnet"></i></a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-center">{{ torrent.filesize | filesizeformat(True) }}</td>
|
||||
{% if use_elastic %}
|
||||
|
|
|
@ -3,6 +3,7 @@ import base64
|
|||
import time
|
||||
from urllib.parse import urlencode
|
||||
from orderedset import OrderedSet
|
||||
from nyaa import app
|
||||
|
||||
from nyaa import bencode
|
||||
from nyaa import app
|
||||
|
@ -53,10 +54,23 @@ def get_trackers(torrent):
|
|||
|
||||
return list(trackers)
|
||||
|
||||
def get_trackers_magnet():
|
||||
trackers = OrderedSet()
|
||||
|
||||
# Our main one first
|
||||
main_announce_url = app.config.get('MAIN_ANNOUNCE_URL')
|
||||
if main_announce_url:
|
||||
trackers.add(main_announce_url)
|
||||
|
||||
# and finally our tracker list
|
||||
trackers.update(default_trackers())
|
||||
|
||||
return list(trackers)
|
||||
|
||||
|
||||
def create_magnet(torrent, max_trackers=5, trackers=None):
|
||||
if trackers is None:
|
||||
trackers = get_trackers(torrent)
|
||||
trackers = get_trackers_magnet()
|
||||
|
||||
magnet_parts = [
|
||||
('dn', torrent.display_name)
|
||||
|
@ -68,6 +82,24 @@ def create_magnet(torrent, max_trackers=5, trackers=None):
|
|||
return 'magnet:?xt=urn:btih:' + b32_info_hash + '&' + urlencode(magnet_parts)
|
||||
|
||||
|
||||
# For processing ES links
|
||||
@app.context_processor
|
||||
def create_magnet_from_info():
|
||||
def _create_magnet_from_info(display_name, info_hash, max_trackers=5, trackers=None):
|
||||
if trackers is None:
|
||||
trackers = get_trackers_magnet()
|
||||
|
||||
magnet_parts = [
|
||||
('dn', display_name)
|
||||
]
|
||||
for tracker in trackers[:max_trackers]:
|
||||
magnet_parts.append(('tr', tracker))
|
||||
|
||||
b32_info_hash = base64.b32encode(bytes.fromhex(info_hash)).decode('utf-8')
|
||||
return 'magnet:?xt=urn:btih:' + b32_info_hash + '&' + urlencode(magnet_parts)
|
||||
return dict(create_magnet_from_info=_create_magnet_from_info)
|
||||
|
||||
|
||||
def create_default_metadata_base(torrent, trackers=None):
|
||||
if trackers is None:
|
||||
trackers = get_trackers(torrent)
|
||||
|
|
Loading…
Reference in a new issue