acgsou.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. try:
  37. category = extract_text(result.xpath(xpath_category)[0])
  38. except:
  39. pass
  40. page_a = result.xpath(xpath_title)[0]
  41. title = extract_text(page_a)
  42. href = base_url + page_a.attrib.get('href')
  43. magnet_link = magnet_link.format(page_a.attrib.get('href')[5:-5])
  44. try:
  45. filesize_info = result.xpath(xpath_filesize)[0]
  46. filesize = filesize_info[:-2]
  47. filesize_multiplier = filesize_info[-2:]
  48. filesize = get_torrent_size(filesize, filesize_multiplier)
  49. except:
  50. pass
  51. # I didn't add download/seed/leech count since as I figured out they are generated randomly everytime
  52. content = 'Category: "{category}".'
  53. content = content.format(category=category)
  54. results.append({'url': href,
  55. 'title': title,
  56. 'content': content,
  57. 'filesize': filesize,
  58. 'magnetlink': magnet_link,
  59. 'template': 'torrent.html'})
  60. return results