mirror of https://github.com/searxng/searxng.git
[enh] improve torrent results
This commit is contained in:
parent
4e2dae30f0
commit
830f70a6bc
|
@ -24,6 +24,7 @@ search_url = url + 'search/{search_term}/{pageno}/'
|
||||||
|
|
||||||
# specific xpath variables
|
# specific xpath variables
|
||||||
magnet_xpath = './/a[@title="Torrent magnet link"]'
|
magnet_xpath = './/a[@title="Torrent magnet link"]'
|
||||||
|
torrent_xpath = './/a[@title="Download torrent file"]'
|
||||||
content_xpath = './/span[@class="font11px lightgrey block"]'
|
content_xpath = './/span[@class="font11px lightgrey block"]'
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +61,9 @@ def response(resp):
|
||||||
method="text"))
|
method="text"))
|
||||||
seed = result.xpath('.//td[contains(@class, "green")]/text()')[0]
|
seed = result.xpath('.//td[contains(@class, "green")]/text()')[0]
|
||||||
leech = result.xpath('.//td[contains(@class, "red")]/text()')[0]
|
leech = result.xpath('.//td[contains(@class, "red")]/text()')[0]
|
||||||
|
filesize = result.xpath('.//td[contains(@class, "nobr")]/text()')[0]
|
||||||
|
filesize_multiplier = result.xpath('.//td[contains(@class, "nobr")]//span/text()')[0]
|
||||||
|
files = result.xpath('.//td[contains(@class, "center")][2]/text()')[0]
|
||||||
|
|
||||||
# convert seed to int if possible
|
# convert seed to int if possible
|
||||||
if seed.isdigit():
|
if seed.isdigit():
|
||||||
|
@ -73,7 +77,31 @@ def response(resp):
|
||||||
else:
|
else:
|
||||||
leech = 0
|
leech = 0
|
||||||
|
|
||||||
|
# convert filesize to byte if possible
|
||||||
|
try:
|
||||||
|
filesize = float(filesize)
|
||||||
|
|
||||||
|
# convert filesize to byte
|
||||||
|
if filesize_multiplier == 'TB':
|
||||||
|
filesize = int(filesize * 1024*1024*1024*1024)
|
||||||
|
elif filesize_multiplier == 'GB':
|
||||||
|
filesize = int(filesize * 1024*1024*1024)
|
||||||
|
elif filesize_multiplier == 'MB':
|
||||||
|
filesize = int(filesize * 1024*1024)
|
||||||
|
elif filesize_multiplier == 'kb':
|
||||||
|
filesize = int(filesize * 1024)
|
||||||
|
except:
|
||||||
|
filesize = None
|
||||||
|
|
||||||
|
# convert files to int if possible
|
||||||
|
if files.isdigit():
|
||||||
|
files = int(files)
|
||||||
|
else:
|
||||||
|
files = None
|
||||||
|
|
||||||
magnetlink = result.xpath(magnet_xpath)[0].attrib['href']
|
magnetlink = result.xpath(magnet_xpath)[0].attrib['href']
|
||||||
|
|
||||||
|
torrentfile = result.xpath(torrent_xpath)[0].attrib['href']
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
results.append({'url': href,
|
results.append({'url': href,
|
||||||
|
@ -81,7 +109,10 @@ def response(resp):
|
||||||
'content': content,
|
'content': content,
|
||||||
'seed': seed,
|
'seed': seed,
|
||||||
'leech': leech,
|
'leech': leech,
|
||||||
|
'filesize': filesize,
|
||||||
|
'files': files,
|
||||||
'magnetlink': magnetlink,
|
'magnetlink': magnetlink,
|
||||||
|
'torrentfile':torrentfile,
|
||||||
'template': 'torrent.html'})
|
'template': 'torrent.html'})
|
||||||
|
|
||||||
# return results sorted by seeder
|
# return results sorted by seeder
|
||||||
|
|
|
@ -5,9 +5,19 @@
|
||||||
{% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
|
{% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
|
||||||
<small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
|
<small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
|
||||||
|
|
||||||
<p class="result-content">{{ icon('transfer') }} {{ _('Seeder') }} <span class="badge">{{ result.seed }}</span>, {{ _('Leecher') }} <span class="badge">{{ result.leech }}</span>
|
<p class="result-content">{{ icon('transfer') }} {{ _('Seeder') }} <span class="badge">{{ result.seed }}</span> • {{ _('Leecher') }} <span class="badge">{{ result.leech }}</span>
|
||||||
<br/>
|
{% if result.filesize %}</br>{{ icon('floppy-disk') }} {{ _('Filesize') }}
|
||||||
<a href="{{ result.magnetlink }}" class="magnetlink">{{ icon('magnet') }} magnet link</a></p>
|
<span class="badge">
|
||||||
|
{% if result.filesize < 1024 %}{{ result.filesize }} Byte
|
||||||
|
{% elif result.filesize < 1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024) }} kb
|
||||||
|
{% elif result.filesize < 1024*1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024/1024) }} MB
|
||||||
|
{% elif result.filesize < 1024*1024*1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024/1024/1024) }} GB{% endif %}
|
||||||
|
</span>{% endif %}
|
||||||
|
{% if result.files %}</br>{{ icon('file') }} {{ _('Number of Files') }} <span class="badge">{{ result.files }}</span>{% endif %}</p>
|
||||||
|
<p class="result-content">
|
||||||
|
<a href="{{ result.magnetlink }}" class="magnetlink">{{ icon('magnet') }} magnet link</a>
|
||||||
|
{% if result.torrentfile %}</br><a href="{{ result.torrentfile }}" class="torrentfile">{{ icon('download-alt') }} torrent file</a>{% endif %}
|
||||||
|
</p>
|
||||||
|
|
||||||
{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
|
{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue