seedpeer.py 3.0KB

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