acgsou.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. Acgsou (Japanese Animation/Music/Comics Bittorrent tracker)
  4. """
  5. from urllib.parse import urlencode
  6. from lxml import html
  7. from searx.utils import extract_text, get_torrent_size, eval_xpath_list, eval_xpath_getindex
  8. # about
  9. about = {
  10. "website": 'https://www.acgsou.com/',
  11. "wikidata_id": None,
  12. "official_api_documentation": None,
  13. "use_official_api": False,
  14. "require_api_key": False,
  15. "results": 'HTML',
  16. }
  17. # engine dependent config
  18. categories = ['files', 'images', 'videos', 'music']
  19. paging = True
  20. # search-url
  21. base_url = 'https://www.acgsou.com/'
  22. search_url = base_url + 'search.php?{query}&page={offset}'
  23. # xpath queries
  24. xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
  25. xpath_category = './/td[2]/a[1]'
  26. xpath_title = './/td[3]/a[last()]'
  27. xpath_torrent_links = './/td[3]/a'
  28. xpath_filesize = './/td[4]/text()'
  29. def request(query, params):
  30. query = urlencode({'keyword': query})
  31. params['url'] = search_url.format(query=query, offset=params['pageno'])
  32. return params
  33. def response(resp):
  34. results = []
  35. dom = html.fromstring(resp.text)
  36. for result in eval_xpath_list(dom, xpath_results):
  37. # defaults
  38. filesize = 0
  39. magnet_link = "magnet:?xt=urn:btih:{}&tr=https://tracker.acgsou.com:2710/announce"
  40. category = extract_text(eval_xpath_getindex(result, xpath_category, 0, default=[]))
  41. page_a = eval_xpath_getindex(result, xpath_title, 0)
  42. title = extract_text(page_a)
  43. href = base_url + page_a.attrib.get('href')
  44. magnet_link = magnet_link.format(page_a.attrib.get('href')[5:-5])
  45. filesize_info = eval_xpath_getindex(result, xpath_filesize, 0, default=None)
  46. if filesize_info:
  47. try:
  48. filesize = filesize_info[:-2]
  49. filesize_multiplier = filesize_info[-2:]
  50. filesize = get_torrent_size(filesize, filesize_multiplier)
  51. except:
  52. pass
  53. # I didn't add download/seed/leech count since as I figured out they are generated randomly everytime
  54. content = 'Category: "{category}".'
  55. content = content.format(category=category)
  56. results.append({'url': href,
  57. 'title': title,
  58. 'content': content,
  59. 'filesize': filesize,
  60. 'magnetlink': magnet_link,
  61. 'template': 'torrent.html'})
  62. return results