logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

kickass.py (2974B)


  1. """
  2. Kickass Torrent (Videos, Music, Files)
  3. @website https://kickass.so
  4. @provide-api no (nothing found)
  5. @using-api no
  6. @results HTML (using search portal)
  7. @stable yes (HTML can change)
  8. @parse url, title, content, seed, leech, magnetlink
  9. """
  10. from lxml import html
  11. from operator import itemgetter
  12. from searx.engines.xpath import extract_text
  13. from searx.utils import get_torrent_size, convert_str_to_int
  14. from searx.url_utils import quote, urljoin
  15. # engine dependent config
  16. categories = ['videos', 'music', 'files']
  17. paging = True
  18. # search-url
  19. url = 'https://kickass.cd/'
  20. search_url = url + 'search/{search_term}/{pageno}/'
  21. # specific xpath variables
  22. magnet_xpath = './/a[@title="Torrent magnet link"]'
  23. torrent_xpath = './/a[@title="Download torrent file"]'
  24. content_xpath = './/span[@class="font11px lightgrey block"]'
  25. # do search-request
  26. def request(query, params):
  27. params['url'] = search_url.format(search_term=quote(query),
  28. pageno=params['pageno'])
  29. return params
  30. # get response from search-request
  31. def response(resp):
  32. results = []
  33. dom = html.fromstring(resp.text)
  34. search_res = dom.xpath('//table[@class="data"]//tr')
  35. # return empty array if nothing is found
  36. if not search_res:
  37. return []
  38. # parse results
  39. for result in search_res[1:]:
  40. link = result.xpath('.//a[@class="cellMainLink"]')[0]
  41. href = urljoin(url, link.attrib['href'])
  42. title = extract_text(link)
  43. content = extract_text(result.xpath(content_xpath))
  44. seed = extract_text(result.xpath('.//td[contains(@class, "green")]'))
  45. leech = extract_text(result.xpath('.//td[contains(@class, "red")]'))
  46. filesize_info = extract_text(result.xpath('.//td[contains(@class, "nobr")]'))
  47. files = extract_text(result.xpath('.//td[contains(@class, "center")][2]'))
  48. seed = convert_str_to_int(seed)
  49. leech = convert_str_to_int(leech)
  50. filesize, filesize_multiplier = filesize_info.split()
  51. filesize = get_torrent_size(filesize, filesize_multiplier)
  52. if files.isdigit():
  53. files = int(files)
  54. else:
  55. files = None
  56. magnetlink = result.xpath(magnet_xpath)[0].attrib['href']
  57. torrentfile = result.xpath(torrent_xpath)[0].attrib['href']
  58. torrentfileurl = quote(torrentfile, safe="%/:=&?~#+!$,;'@()*")
  59. # append result
  60. results.append({'url': href,
  61. 'title': title,
  62. 'content': content,
  63. 'seed': seed,
  64. 'leech': leech,
  65. 'filesize': filesize,
  66. 'files': files,
  67. 'magnetlink': magnetlink,
  68. 'torrentfile': torrentfileurl,
  69. 'template': 'torrent.html'})
  70. # return results sorted by seeder
  71. return sorted(results, key=itemgetter('seed'), reverse=True)