kickass.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. from urlparse import urljoin
  11. from cgi import escape
  12. from urllib import quote
  13. from lxml import html
  14. from operator import itemgetter
  15. # engine dependent config
  16. categories = ['videos', 'music', 'files']
  17. paging = True
  18. # search-url
  19. url = 'https://kickass.so/'
  20. search_url = url + 'search/{search_term}/{pageno}/'
  21. # specific xpath variables
  22. magnet_xpath = './/a[@title="Torrent magnet link"]'
  23. content_xpath = './/span[@class="font11px lightgrey block"]'
  24. # do search-request
  25. def request(query, params):
  26. params['url'] = search_url.format(search_term=quote(query),
  27. pageno=params['pageno'])
  28. # FIX: SSLError: hostname 'kickass.so'
  29. # doesn't match either of '*.kickass.to', 'kickass.to'
  30. params['verify'] = False
  31. return params
  32. # get response from search-request
  33. def response(resp):
  34. results = []
  35. dom = html.fromstring(resp.text)
  36. search_res = dom.xpath('//table[@class="data"]//tr')
  37. # return empty array if nothing is found
  38. if not search_res:
  39. return []
  40. # parse results
  41. for result in search_res[1:]:
  42. link = result.xpath('.//a[@class="cellMainLink"]')[0]
  43. href = urljoin(url, link.attrib['href'])
  44. title = ' '.join(link.xpath('.//text()'))
  45. content = escape(html.tostring(result.xpath(content_xpath)[0],
  46. method="text"))
  47. seed = result.xpath('.//td[contains(@class, "green")]/text()')[0]
  48. leech = result.xpath('.//td[contains(@class, "red")]/text()')[0]
  49. # convert seed to int if possible
  50. if seed.isdigit():
  51. seed = int(seed)
  52. else:
  53. seed = 0
  54. # convert leech to int if possible
  55. if leech.isdigit():
  56. leech = int(leech)
  57. else:
  58. leech = 0
  59. magnetlink = result.xpath(magnet_xpath)[0].attrib['href']
  60. # append result
  61. results.append({'url': href,
  62. 'title': title,
  63. 'content': content,
  64. 'seed': seed,
  65. 'leech': leech,
  66. 'magnetlink': magnetlink,
  67. 'template': 'torrent.html'})
  68. # return results sorted by seeder
  69. return sorted(results, key=itemgetter('seed'), reverse=True)