seedpeer.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Seedpeer (Videos, Music, Files)
  2. #
  3. # @website https://seedpeer.me
  4. # @provide-api no (nothing found)
  5. #
  6. # @using-api no
  7. # @results HTML (using search portal)
  8. # @stable yes (HTML can change)
  9. # @parse url, title, content, seed, leech, magnetlink
  10. from lxml import html
  11. from json import loads
  12. from operator import itemgetter
  13. from urllib.parse import quote, urljoin
  14. from searx.utils import extract_text
  15. url = 'https://seedpeer.me/'
  16. search_url = url + 'search/{search_term}?page={page_no}'
  17. torrent_file_url = url + 'torrent/{torrent_hash}'
  18. # specific xpath variables
  19. script_xpath = '//script[@type="text/javascript"][not(@src)]'
  20. torrent_xpath = '(//table)[2]/tbody/tr'
  21. link_xpath = '(./td)[1]/a/@href'
  22. age_xpath = '(./td)[2]'
  23. size_xpath = '(./td)[3]'
  24. # do search-request
  25. def request(query, params):
  26. params['url'] = search_url.format(search_term=quote(query),
  27. page_no=params['pageno'])
  28. return params
  29. # get response from search-request
  30. def response(resp):
  31. results = []
  32. dom = html.fromstring(resp.text)
  33. result_rows = dom.xpath(torrent_xpath)
  34. try:
  35. script_element = dom.xpath(script_xpath)[0]
  36. json_string = script_element.text[script_element.text.find('{'):]
  37. torrents_json = loads(json_string)
  38. except:
  39. return []
  40. # parse results
  41. for torrent_row, torrent_json in zip(result_rows, torrents_json['data']['list']):
  42. title = torrent_json['name']
  43. seed = int(torrent_json['seeds'])
  44. leech = int(torrent_json['peers'])
  45. size = int(torrent_json['size'])
  46. torrent_hash = torrent_json['hash']
  47. torrentfile = torrent_file_url.format(torrent_hash=torrent_hash)
  48. magnetlink = 'magnet:?xt=urn:btih:{}'.format(torrent_hash)
  49. age = extract_text(torrent_row.xpath(age_xpath))
  50. link = torrent_row.xpath(link_xpath)[0]
  51. href = urljoin(url, link)
  52. # append result
  53. results.append({'url': href,
  54. 'title': title,
  55. 'content': age,
  56. 'seed': seed,
  57. 'leech': leech,
  58. 'filesize': size,
  59. 'torrentfile': torrentfile,
  60. 'magnetlink': magnetlink,
  61. 'template': 'torrent.html'})
  62. # return results sorted by seeder
  63. return sorted(results, key=itemgetter('seed'), reverse=True)