acgsou.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """
  2. Acgsou (Japanese Animation/Music/Comics Bittorrent tracker)
  3. @website https://www.acgsou.com/
  4. @provide-api no
  5. @using-api no
  6. @results HTML
  7. @stable no (HTML can change)
  8. @parse url, title, content, seed, leech, torrentfile
  9. """
  10. from lxml import html
  11. from searx.engines.xpath import extract_text
  12. from searx.url_utils import urlencode
  13. from searx.utils import get_torrent_size, int_or_zero
  14. # engine dependent config
  15. categories = ['files', 'images', 'videos', 'music']
  16. paging = True
  17. # search-url
  18. base_url = 'https://www.acgsou.com/'
  19. search_url = base_url + 'search.php?{query}&page={offset}'
  20. # xpath queries
  21. xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
  22. xpath_category = './/td[2]/a[1]'
  23. xpath_title = './/td[3]/a[last()]'
  24. xpath_torrent_links = './/td[3]/a'
  25. xpath_filesize = './/td[4]/text()'
  26. # do search-request
  27. def request(query, params):
  28. query = urlencode({'keyword': query})
  29. params['url'] = search_url.format(query=query, offset=params['pageno'])
  30. return params
  31. # get response from search-request
  32. def response(resp):
  33. results = []
  34. dom = html.fromstring(resp.text)
  35. print(resp.text)
  36. for result in dom.xpath(xpath_results):
  37. # defaults
  38. filesize = 0
  39. magnet_link = "magnet:?xt=urn:btih:{}&tr=http://tracker.acgsou.com:2710/announce"
  40. torrent_link = ""
  41. # category in which our torrent belongs
  42. try:
  43. category = extract_text(result.xpath(xpath_category)[0])
  44. except:
  45. pass
  46. # torrent title
  47. page_a = result.xpath(xpath_title)[0]
  48. title = extract_text(page_a)
  49. # link to the page
  50. href = base_url + page_a.attrib.get('href')
  51. #magnet link
  52. magnet_link = magnet_link.format(page_a.attrib.get('href')[5:-5])
  53. # let's try to calculate the torrent size
  54. try:
  55. filesize_info = result.xpath(xpath_filesize)[0]
  56. filesize = filesize_info[:-2]
  57. filesize_multiplier = filesize_info[-2:]
  58. filesize = get_torrent_size(filesize, filesize_multiplier)
  59. except :
  60. pass
  61. # content string contains all information not included into template
  62. content = 'Category: "{category}".'
  63. content = content.format(category=category)
  64. results.append({'url': href,
  65. 'title': title,
  66. 'content': content,
  67. 'filesize': filesize,
  68. 'magnetlink': magnet_link,
  69. 'template': 'torrent.html'})
  70. return results