Selaa lähdekoodia

[enh] piratebay engine added

asciimoo 11 vuotta sitten
vanhempi
commit
9ad8013a45
1 muutettua tiedostoa jossa 34 lisäystä ja 0 poistoa
  1. 34
    0
      searx/engines/piratebay.py

+ 34
- 0
searx/engines/piratebay.py Näytä tiedosto

@@ -0,0 +1,34 @@
1
+from lxml import html
2
+from urlparse import urljoin
3
+from cgi import escape
4
+from urllib import quote
5
+
6
+categories = ['videos', 'music']
7
+
8
+base_url = 'https://thepiratebay.sx/'
9
+search_url = base_url + 'search/{search_term}/0/99/{search_type}'
10
+search_types = {'videos': '200'
11
+               ,'music' : '100'
12
+               }
13
+
14
+def request(query, params):
15
+    global search_url, search_types
16
+    # 200 is the video category
17
+    params['url'] = search_url.format(search_term=quote(query), search_type=search_types.get(params['category']))
18
+    return params
19
+
20
+
21
+def response(resp):
22
+    global base_url
23
+    results = []
24
+    dom = html.fromstring(resp.text)
25
+    search_res = dom.xpath('//table[@id="searchResult"]//tr')
26
+    if not search_res:
27
+        return results
28
+    for result in search_res[1:]:
29
+        link = result.xpath('.//div[@class="detName"]//a')[0]
30
+        url = urljoin(base_url, link.attrib.get('href'))
31
+        title = ' '.join(link.xpath('.//text()'))
32
+        content = escape(' '.join(result.xpath('.//font[@class="detDesc"]//text()')))
33
+        results.append({'url': url, 'title': title, 'content': content})
34
+    return results