acgsou.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 urllib.parse import urlencode
  11. from lxml import html
  12. from searx.utils import extract_text, get_torrent_size
  13. # engine dependent config
  14. categories = ['files', 'images', 'videos', 'music']
  15. paging = True
  16. # search-url
  17. base_url = 'http://www.acgsou.com/'
  18. search_url = base_url + 'search.php?{query}&page={offset}'
  19. # xpath queries
  20. xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
  21. xpath_category = './/td[2]/a[1]'
  22. xpath_title = './/td[3]/a[last()]'
  23. xpath_torrent_links = './/td[3]/a'
  24. xpath_filesize = './/td[4]/text()'
  25. def request(query, params):
  26. query = urlencode({'keyword': query})
  27. params['url'] = search_url.format(query=query, offset=params['pageno'])
  28. return params
  29. def response(resp):
  30. results = []
  31. dom = html.fromstring(resp.text)
  32. for result in dom.xpath(xpath_results):
  33. # defaults
  34. filesize = 0
  35. magnet_link = "magnet:?xt=urn:btih:{}&tr=http://tracker.acgsou.com:2710/announce"
  36. torrent_link = ""
  37. try:
  38. category = extract_text(result.xpath(xpath_category)[0])
  39. except:
  40. pass
  41. page_a = result.xpath(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. try:
  46. filesize_info = result.xpath(xpath_filesize)[0]
  47. filesize = filesize_info[:-2]
  48. filesize_multiplier = filesize_info[-2:]
  49. filesize = get_torrent_size(filesize, filesize_multiplier)
  50. except:
  51. pass
  52. # I didn't add download/seed/leech count since as I figured out they are generated randomly everytime
  53. content = 'Category: "{category}".'
  54. content = content.format(category=category)
  55. results.append({'url': href,
  56. 'title': title,
  57. 'content': content,
  58. 'filesize': filesize,
  59. 'magnetlink': magnet_link,
  60. 'template': 'torrent.html'})
  61. return results