|
@@ -2,6 +2,7 @@ from urlparse import urljoin
|
2
|
2
|
from cgi import escape
|
3
|
3
|
from urllib import quote
|
4
|
4
|
from lxml import html
|
|
5
|
+from operator import itemgetter
|
5
|
6
|
|
6
|
7
|
categories = ['videos', 'music']
|
7
|
8
|
|
|
@@ -24,18 +25,32 @@ def request(query, params):
|
24
|
25
|
pageno=params['pageno'] - 1)
|
25
|
26
|
return params
|
26
|
27
|
|
|
28
|
+
|
27
|
29
|
def response(resp):
|
28
|
30
|
results = []
|
29
|
31
|
dom = html.fromstring(resp.text)
|
30
|
32
|
search_res = dom.xpath('//table[@id="searchResult"]//tr')
|
|
33
|
+
|
31
|
34
|
if not search_res:
|
32
|
35
|
return results
|
|
36
|
+
|
33
|
37
|
for result in search_res[1:]:
|
34
|
38
|
link = result.xpath('.//div[@class="detName"]//a')[0]
|
35
|
39
|
href = urljoin(url, link.attrib.get('href'))
|
36
|
40
|
title = ' '.join(link.xpath('.//text()'))
|
37
|
41
|
content = escape(' '.join(result.xpath(content_xpath)))
|
38
|
42
|
seed, leech = result.xpath('.//td[@align="right"]/text()')[:2]
|
|
43
|
+
|
|
44
|
+ if seed.isdigit():
|
|
45
|
+ seed = int(seed)
|
|
46
|
+ else:
|
|
47
|
+ seed = 0
|
|
48
|
+
|
|
49
|
+ if leech.isdigit():
|
|
50
|
+ leech = int(leech)
|
|
51
|
+ else:
|
|
52
|
+ leech = 0
|
|
53
|
+
|
39
|
54
|
magnetlink = result.xpath(magnet_xpath)[0]
|
40
|
55
|
results.append({'url': href,
|
41
|
56
|
'title': title,
|
|
@@ -44,10 +59,5 @@ def response(resp):
|
44
|
59
|
'leech': leech,
|
45
|
60
|
'magnetlink': magnetlink.attrib['href'],
|
46
|
61
|
'template': 'torrent.html'})
|
47
|
|
- return sorted(results, key=lambda x: get_int('seed'), reversed=True)
|
48
|
62
|
|
49
|
|
-def get_int(field):
|
50
|
|
- try:
|
51
|
|
- return int(field)
|
52
|
|
- except TypeError:
|
53
|
|
- return 0
|
|
63
|
+ return sorted(results, key=itemgetter('seed'), reverse=True)
|