kickass.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 = './/font[@class="detDesc"]//text()'
  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('.//span[@class="font11px lightgrey block"]')[0], method="text"))
  46. seed = result.xpath('.//td[contains(@class, "green")]/text()')[0]
  47. leech = result.xpath('.//td[contains(@class, "red")]/text()')[0]
  48. # convert seed to int if possible
  49. if seed.isdigit():
  50. seed = int(seed)
  51. else:
  52. seed = 0
  53. # convert leech to int if possible
  54. if leech.isdigit():
  55. leech = int(leech)
  56. else:
  57. leech = 0
  58. magnetlink = result.xpath(magnet_xpath)[0].attrib['href']
  59. # append result
  60. results.append({'url': href,
  61. 'title': title,
  62. 'content': content,
  63. 'seed': seed,
  64. 'leech': leech,
  65. 'magnetlink': magnetlink,
  66. 'template': 'torrent.html'})
  67. # return results sorted by seeder
  68. return sorted(results, key=itemgetter('seed'), reverse=True)