ソースを参照

[fix] piratebay: missing torrent link

Adam Tauber 10 年 前
コミット
52d243f7af
共有2 個のファイルを変更した37 個の追加4 個の削除を含む
  1. 7
    3
      searx/engines/piratebay.py
  2. 30
    1
      searx/tests/engines/test_piratebay.py

+ 7
- 3
searx/engines/piratebay.py ファイルの表示

1
-## Piratebay (Videos, Music, Files)
1
+#  Piratebay (Videos, Music, Files)
2
 #
2
 #
3
 # @website     https://thepiratebay.se
3
 # @website     https://thepiratebay.se
4
 # @provide-api no (nothing found)
4
 # @provide-api no (nothing found)
78
             leech = 0
78
             leech = 0
79
 
79
 
80
         magnetlink = result.xpath(magnet_xpath)[0]
80
         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
82
 
86
 
83
         # append result
87
         # append result
84
         results.append({'url': href,
88
         results.append({'url': href,
87
                         'seed': seed,
91
                         'seed': seed,
88
                         'leech': leech,
92
                         'leech': leech,
89
                         'magnetlink': magnetlink.attrib.get('href'),
93
                         'magnetlink': magnetlink.attrib.get('href'),
90
-                        'torrentfile': torrentfile.attrib.get('href'),
94
+                        'torrentfile': torrentfile_link,
91
                         'template': 'torrent.html'})
95
                         'template': 'torrent.html'})
92
 
96
 
93
     # return results sorted by seeder
97
     # return results sorted by seeder

+ 30
- 1
searx/tests/engines/test_piratebay.py ファイルの表示

65
                 <td align="right">13</td>
65
                 <td align="right">13</td>
66
                 <td align="right">334</td>
66
                 <td align="right">334</td>
67
             </tr>
67
             </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>
68
         </table>
95
         </table>
69
         """
96
         """
70
         response = mock.Mock(text=html)
97
         response = mock.Mock(text=html)
71
         results = piratebay.response(response)
98
         results = piratebay.response(response)
72
         self.assertEqual(type(results), list)
99
         self.assertEqual(type(results), list)
73
-        self.assertEqual(len(results), 1)
100
+        self.assertEqual(len(results), 2)
74
         self.assertEqual(results[0]['title'], 'This is the title')
101
         self.assertEqual(results[0]['title'], 'This is the title')
75
         self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link')
102
         self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link')
76
         self.assertEqual(results[0]['content'], 'This is the content and should be OK')
103
         self.assertEqual(results[0]['content'], 'This is the content and should be OK')
79
         self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK')
106
         self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK')
80
         self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent')
107
         self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent')
81
 
108
 
109
+        self.assertEqual(results[1]['torrentfile'], None)
110
+
82
         html = """
111
         html = """
83
         <table id="searchResult">
112
         <table id="searchResult">
84
             <tr>
113
             <tr>