seedpeer.py 3.0 KB

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