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