|
@@ -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)
|