logo

searx

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

seedpeer.py (2995B)


  1. # Seedpeer (Videos, Music, Files)
  2. #
  3. # @website http://seedpeer.eu
  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 operator import itemgetter
  12. from searx.url_utils import quote, urljoin
  13. url = 'http://www.seedpeer.eu/'
  14. search_url = url + 'search/{search_term}/7/{page_no}.html'
  15. # specific xpath variables
  16. torrent_xpath = '//*[@id="body"]/center/center/table[2]/tr/td/a'
  17. alternative_torrent_xpath = '//*[@id="body"]/center/center/table[1]/tr/td/a'
  18. title_xpath = '//*[@id="body"]/center/center/table[2]/tr/td/a/text()'
  19. alternative_title_xpath = '//*[@id="body"]/center/center/table/tr/td/a'
  20. seeds_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[4]/font/text()'
  21. alternative_seeds_xpath = '//*[@id="body"]/center/center/table/tr/td[4]/font/text()'
  22. peers_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[5]/font/text()'
  23. alternative_peers_xpath = '//*[@id="body"]/center/center/table/tr/td[5]/font/text()'
  24. age_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[2]/text()'
  25. alternative_age_xpath = '//*[@id="body"]/center/center/table/tr/td[2]/text()'
  26. size_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[3]/text()'
  27. alternative_size_xpath = '//*[@id="body"]/center/center/table/tr/td[3]/text()'
  28. # do search-request
  29. def request(query, params):
  30. params['url'] = search_url.format(search_term=quote(query),
  31. page_no=params['pageno'] - 1)
  32. return params
  33. # get response from search-request
  34. def response(resp):
  35. results = []
  36. dom = html.fromstring(resp.text)
  37. torrent_links = dom.xpath(torrent_xpath)
  38. if len(torrent_links) > 0:
  39. seeds = dom.xpath(seeds_xpath)
  40. peers = dom.xpath(peers_xpath)
  41. titles = dom.xpath(title_xpath)
  42. sizes = dom.xpath(size_xpath)
  43. ages = dom.xpath(age_xpath)
  44. else: # under ~5 results uses a different xpath
  45. torrent_links = dom.xpath(alternative_torrent_xpath)
  46. seeds = dom.xpath(alternative_seeds_xpath)
  47. peers = dom.xpath(alternative_peers_xpath)
  48. titles = dom.xpath(alternative_title_xpath)
  49. sizes = dom.xpath(alternative_size_xpath)
  50. ages = dom.xpath(alternative_age_xpath)
  51. # return empty array if nothing is found
  52. if not torrent_links:
  53. return []
  54. # parse results
  55. for index, result in enumerate(torrent_links):
  56. link = result.attrib.get('href')
  57. href = urljoin(url, link)
  58. results.append({'url': href,
  59. 'title': titles[index].text_content(),
  60. 'content': '{}, {}'.format(sizes[index], ages[index]),
  61. 'seed': seeds[index],
  62. 'leech': peers[index],
  63. 'template': 'torrent.html'})
  64. # return results sorted by seeder
  65. return sorted(results, key=itemgetter('seed'), reverse=True)