1337x.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. 1337x
  4. """
  5. from urllib.parse import quote, urljoin
  6. from lxml import html
  7. from searx.utils import extract_text, get_torrent_size, eval_xpath, eval_xpath_list, eval_xpath_getindex
  8. # about
  9. about = {
  10. "website": 'https://1337x.to/',
  11. "wikidata_id": 'Q28134166',
  12. "official_api_documentation": None,
  13. "use_official_api": False,
  14. "require_api_key": False,
  15. "results": 'HTML',
  16. }
  17. url = 'https://1337x.to/'
  18. search_url = url + 'search/{search_term}/{pageno}/'
  19. categories = ['videos']
  20. paging = True
  21. def request(query, params):
  22. params['url'] = search_url.format(search_term=quote(query), pageno=params['pageno'])
  23. return params
  24. def response(resp):
  25. results = []
  26. dom = html.fromstring(resp.text)
  27. for result in eval_xpath_list(dom, '//table[contains(@class, "table-list")]/tbody//tr'):
  28. href = urljoin(url, eval_xpath_getindex(result, './td[contains(@class, "name")]/a[2]/@href', 0))
  29. title = extract_text(eval_xpath(result, './td[contains(@class, "name")]/a[2]'))
  30. seed = extract_text(eval_xpath(result, './/td[contains(@class, "seeds")]'))
  31. leech = extract_text(eval_xpath(result, './/td[contains(@class, "leeches")]'))
  32. filesize_info = extract_text(eval_xpath(result, './/td[contains(@class, "size")]/text()'))
  33. filesize, filesize_multiplier = filesize_info.split()
  34. filesize = get_torrent_size(filesize, filesize_multiplier)
  35. results.append({'url': href,
  36. 'title': title,
  37. 'seed': seed,
  38. 'leech': leech,
  39. 'filesize': filesize,
  40. 'template': 'torrent.html'})
  41. return results