Selaa lähdekoodia

Merge pull request #144 from Cqoicebordel/KickassTorrent-Search-Engine

Kickass torrent search engine
Adam Tauber 10 vuotta sitten
vanhempi
commit
e047d22046

+ 84
- 0
searx/engines/kickass.py Näytä tiedosto

@@ -0,0 +1,84 @@
1
+## Kickass Torrent (Videos, Music, Files)
2
+# 
3
+# @website     https://kickass.so
4
+# @provide-api no (nothing found)
5
+# 
6
+# @using-api   no
7
+# @results     HTML (using search portal)
8
+# @stable      yes (HTML can change)
9
+# @parse       url, title, content, seed, leech, magnetlink
10
+
11
+from urlparse import urljoin
12
+from cgi import escape
13
+from urllib import quote
14
+from lxml import html
15
+from operator import itemgetter
16
+from dateutil import parser
17
+
18
+# engine dependent config
19
+categories = ['videos', 'music', 'files']
20
+paging = True
21
+
22
+# search-url
23
+url = 'https://kickass.so/'
24
+search_url = url + 'search/{search_term}/{pageno}/'
25
+
26
+# specific xpath variables
27
+magnet_xpath = './/a[@title="Torrent magnet link"]'
28
+#content_xpath = './/font[@class="detDesc"]//text()'
29
+
30
+
31
+# do search-request
32
+def request(query, params):
33
+    params['url'] = search_url.format(search_term=quote(query),
34
+                                      pageno=params['pageno'])
35
+
36
+    return params
37
+
38
+
39
+# get response from search-request
40
+def response(resp):
41
+    results = []
42
+
43
+    dom = html.fromstring(resp.text)
44
+
45
+    search_res = dom.xpath('//table[@class="data"]//tr')
46
+
47
+    # return empty array if nothing is found
48
+    if not search_res:
49
+        return []
50
+
51
+    # parse results
52
+    for result in search_res[1:]:
53
+        link = result.xpath('.//a[@class="cellMainLink"]')[0]
54
+        href = urljoin(url, link.attrib['href'])
55
+        title = ' '.join(link.xpath('.//text()'))
56
+        content = escape(html.tostring(result.xpath('.//span[@class="font11px lightgrey block"]')[0], method="text"))
57
+        seed = result.xpath('.//td[contains(@class, "green")]/text()')[0]
58
+        leech = result.xpath('.//td[contains(@class, "red")]/text()')[0]
59
+
60
+        # convert seed to int if possible
61
+        if seed.isdigit():
62
+            seed = int(seed)
63
+        else:
64
+            seed = 0
65
+
66
+        # convert leech to int if possible
67
+        if leech.isdigit():
68
+            leech = int(leech)
69
+        else:
70
+            leech = 0
71
+
72
+        magnetlink = result.xpath(magnet_xpath)[0].attrib['href']
73
+
74
+        # append result
75
+        results.append({'url': href,
76
+                        'title': title,
77
+                        'content': content,
78
+                        'seed': seed,
79
+                        'leech': leech,
80
+                        'magnetlink': magnetlink,
81
+                        'template': 'torrent.html'})
82
+
83
+    # return results sorted by seeder
84
+    return sorted(results, key=itemgetter('seed'), reverse=True)

+ 4
- 0
searx/settings.yml Näytä tiedosto

@@ -99,6 +99,10 @@ engines:
99 99
 #    engine : piratebay
100 100
 #    shortcut : tpb
101 101
 
102
+  - name : kickass
103
+    engine : kickass
104
+    shortcut : ka
105
+
102 106
   - name : soundcloud
103 107
     engine : soundcloud
104 108
     shortcut : sc

BIN
searx/static/courgette/img/icon_kickass.ico Näytä tiedosto


BIN
searx/static/default/img/icon_kickass.ico Näytä tiedosto


BIN
searx/static/oscar/img/icons/kickass.png Näytä tiedosto


+ 1
- 1
searx/webapp.py Näytä tiedosto

@@ -70,7 +70,7 @@ babel = Babel(app)
70 70
 
71 71
 #TODO configurable via settings.yml
72 72
 favicons = ['wikipedia', 'youtube', 'vimeo', 'dailymotion', 'soundcloud',
73
-            'twitter', 'stackoverflow', 'github', 'deviantart']
73
+            'twitter', 'stackoverflow', 'github', 'deviantart', 'kickass']
74 74
 
75 75
 cookie_max_age = 60 * 60 * 24 * 365 * 23  # 23 years
76 76