on master help sign in
[fix] piratebay: missing torrent link
commit52d243f7af259bb888ead2284c82a5a23caadb9d authorAdam Tauber <asciimoo@gmail.com> dateSun 29 Mar 2015, 21:05 (12 years ago) parentb8e9f51
2 files changed+37−4
searx/engines/piratebay.py+7−3 searx/tests/engines/test_piratebay.py+30−1
searx/engines/piratebay.py+7−3
@@ -1,4 +1,4 @@
1−## Piratebay (Videos, Music, Files)
1+# Piratebay (Videos, Music, Files)
22#
33# @website https://thepiratebay.se
44# @provide-api no (nothing found)
@@ -78,7 +78,11 @@ def response(resp):
7878 leech = 0
7979
8080 magnetlink = result.xpath(magnet_xpath)[0]
81− torrentfile = result.xpath(torrent_xpath)[0]
81+ torrentfile_links = result.xpath(torrent_xpath)
82+ if torrentfile_links:
83+ torrentfile_link = torrentfile_links[0].attrib.get('href')
84+ else:
85+ torrentfile_link = None
8286
8387 # append result
8488 results.append({'url': href,
@@ -87,7 +91,7 @@ def response(resp):
8791 'seed': seed,
8892 'leech': leech,
8993 'magnetlink': magnetlink.attrib.get('href'),
90− 'torrentfile': torrentfile.attrib.get('href'),
94+ 'torrentfile': torrentfile_link,
9195 'template': 'torrent.html'})
9296
9397 # return results sorted by seeder
searx/tests/engines/test_piratebay.py+30−1
@@ -65,12 +65,39 @@ class TestPiratebayEngine(SearxTestCase):
6565 <td align="right">13</td>
6666 <td align="right">334</td>
6767 </tr>
68+ <tr>
69+ <td class="vertTh">
70+ <center>
71+ <a href="#" title="More from this category">Anime</a><br/>
72+ (<a href="#" title="More from this category">Anime</a>)
73+ </center>
74+ </td>
75+ <td>
76+ <div class="detName">
77+ <a href="/this.is.the.link" class="detLink" title="Title">
78+ This is the title
79+ </a>
80+ </div>
81+ <a href="magnet:?xt=urn:btih:MAGNETLINK" title="Download this torrent using magnet">
82+ <img src="/static/img/icon-magnet.gif" alt="Magnet link"/>
83+ </a>
84+ <a href="/user/HorribleSubs">
85+ <img src="/static/img/vip.gif" alt="VIP" title="VIP" style="width:11px;" border='0'/>
86+ </a>
87+ <img src="/static/img/11x11p.png"/>
88+ <font class="detDesc">
89+ This is the content <span>and should be</span> OK
90+ </font>
91+ </td>
92+ <td align="right">13</td>
93+ <td align="right">334</td>
94+ </tr>
6895 </table>
6996 """
7097 response = mock.Mock(text=html)
7198 results = piratebay.response(response)
7299 self.assertEqual(type(results), list)
73− self.assertEqual(len(results), 1)
100+ self.assertEqual(len(results), 2)
74101 self.assertEqual(results[0]['title'], 'This is the title')
75102 self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link')
76103 self.assertEqual(results[0]['content'], 'This is the content and should be OK')
@@ -79,6 +106,8 @@ class TestPiratebayEngine(SearxTestCase):
79106 self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK')
80107 self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent')
81108
109+ self.assertEqual(results[1]['torrentfile'], None)
110+
82111 html = """
83112 <table id="searchResult">
84113 <tr>