forked from zaclys/searxng
[fix] piratebay: missing torrent link
This commit is contained in:
parent
b8e9f5105c
commit
52d243f7af
|
@ -1,4 +1,4 @@
|
||||||
## Piratebay (Videos, Music, Files)
|
# Piratebay (Videos, Music, Files)
|
||||||
#
|
#
|
||||||
# @website https://thepiratebay.se
|
# @website https://thepiratebay.se
|
||||||
# @provide-api no (nothing found)
|
# @provide-api no (nothing found)
|
||||||
|
@ -78,7 +78,11 @@ def response(resp):
|
||||||
leech = 0
|
leech = 0
|
||||||
|
|
||||||
magnetlink = result.xpath(magnet_xpath)[0]
|
magnetlink = result.xpath(magnet_xpath)[0]
|
||||||
torrentfile = result.xpath(torrent_xpath)[0]
|
torrentfile_links = result.xpath(torrent_xpath)
|
||||||
|
if torrentfile_links:
|
||||||
|
torrentfile_link = torrentfile_links[0].attrib.get('href')
|
||||||
|
else:
|
||||||
|
torrentfile_link = None
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
results.append({'url': href,
|
results.append({'url': href,
|
||||||
|
@ -87,7 +91,7 @@ def response(resp):
|
||||||
'seed': seed,
|
'seed': seed,
|
||||||
'leech': leech,
|
'leech': leech,
|
||||||
'magnetlink': magnetlink.attrib.get('href'),
|
'magnetlink': magnetlink.attrib.get('href'),
|
||||||
'torrentfile': torrentfile.attrib.get('href'),
|
'torrentfile': torrentfile_link,
|
||||||
'template': 'torrent.html'})
|
'template': 'torrent.html'})
|
||||||
|
|
||||||
# return results sorted by seeder
|
# return results sorted by seeder
|
||||||
|
|
|
@ -65,12 +65,39 @@ class TestPiratebayEngine(SearxTestCase):
|
||||||
<td align="right">13</td>
|
<td align="right">13</td>
|
||||||
<td align="right">334</td>
|
<td align="right">334</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="vertTh">
|
||||||
|
<center>
|
||||||
|
<a href="#" title="More from this category">Anime</a><br/>
|
||||||
|
(<a href="#" title="More from this category">Anime</a>)
|
||||||
|
</center>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="detName">
|
||||||
|
<a href="/this.is.the.link" class="detLink" title="Title">
|
||||||
|
This is the title
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a href="magnet:?xt=urn:btih:MAGNETLINK" title="Download this torrent using magnet">
|
||||||
|
<img src="/static/img/icon-magnet.gif" alt="Magnet link"/>
|
||||||
|
</a>
|
||||||
|
<a href="/user/HorribleSubs">
|
||||||
|
<img src="/static/img/vip.gif" alt="VIP" title="VIP" style="width:11px;" border='0'/>
|
||||||
|
</a>
|
||||||
|
<img src="/static/img/11x11p.png"/>
|
||||||
|
<font class="detDesc">
|
||||||
|
This is the content <span>and should be</span> OK
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td align="right">13</td>
|
||||||
|
<td align="right">334</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
"""
|
"""
|
||||||
response = mock.Mock(text=html)
|
response = mock.Mock(text=html)
|
||||||
results = piratebay.response(response)
|
results = piratebay.response(response)
|
||||||
self.assertEqual(type(results), list)
|
self.assertEqual(type(results), list)
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 2)
|
||||||
self.assertEqual(results[0]['title'], 'This is the title')
|
self.assertEqual(results[0]['title'], 'This is the title')
|
||||||
self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link')
|
self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link')
|
||||||
self.assertEqual(results[0]['content'], 'This is the content and should be OK')
|
self.assertEqual(results[0]['content'], 'This is the content and should be OK')
|
||||||
|
@ -79,6 +106,8 @@ class TestPiratebayEngine(SearxTestCase):
|
||||||
self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK')
|
self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK')
|
||||||
self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent')
|
self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent')
|
||||||
|
|
||||||
|
self.assertEqual(results[1]['torrentfile'], None)
|
||||||
|
|
||||||
html = """
|
html = """
|
||||||
<table id="searchResult">
|
<table id="searchResult">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in New Issue