logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

acgsou.py (2401B)


  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 = 'http://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. def request(query, params):
  27. query = urlencode({'keyword': query})
  28. params['url'] = search_url.format(query=query, offset=params['pageno'])
  29. return params
  30. def response(resp):
  31. results = []
  32. dom = html.fromstring(resp.text)
  33. for result in dom.xpath(xpath_results):
  34. # defaults
  35. filesize = 0
  36. magnet_link = "magnet:?xt=urn:btih:{}&tr=http://tracker.acgsou.com:2710/announce"
  37. torrent_link = ""
  38. try:
  39. category = extract_text(result.xpath(xpath_category)[0])
  40. except:
  41. pass
  42. page_a = result.xpath(xpath_title)[0]
  43. title = extract_text(page_a)
  44. href = base_url + page_a.attrib.get('href')
  45. magnet_link = magnet_link.format(page_a.attrib.get('href')[5:-5])
  46. try:
  47. filesize_info = result.xpath(xpath_filesize)[0]
  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 = u'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