digbt.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. DigBT (Videos, Music, Files)
  3. @website https://digbt.org
  4. @provide-api no
  5. @using-api no
  6. @results HTML (using search portal)
  7. @stable no (HTML can change)
  8. @parse url, title, content, magnetlink
  9. """
  10. from urlparse import urljoin
  11. from lxml import html
  12. from searx.engines.xpath import extract_text
  13. from searx.utils import get_torrent_size
  14. categories = ['videos', 'music', 'files']
  15. paging = True
  16. URL = 'https://digbt.org'
  17. SEARCH_URL = URL + '/search/{query}-time-{pageno}'
  18. FILESIZE = 3
  19. FILESIZE_MULTIPLIER = 4
  20. def request(query, params):
  21. params['url'] = SEARCH_URL.format(query=query, pageno=params['pageno'])
  22. return params
  23. def response(resp):
  24. dom = html.fromstring(resp.content)
  25. search_res = dom.xpath('.//td[@class="x-item"]')
  26. if not search_res:
  27. return list()
  28. results = list()
  29. for result in search_res:
  30. url = urljoin(URL, result.xpath('.//a[@title]/@href')[0])
  31. title = extract_text(result.xpath('.//a[@title]'))
  32. content = extract_text(result.xpath('.//div[@class="files"]'))
  33. files_data = extract_text(result.xpath('.//div[@class="tail"]')).split()
  34. filesize = get_torrent_size(files_data[FILESIZE], files_data[FILESIZE_MULTIPLIER])
  35. magnetlink = result.xpath('.//div[@class="tail"]//a[@class="title"]/@href')[0]
  36. results.append({'url': url,
  37. 'title': title,
  38. 'content': content,
  39. 'filesize': filesize,
  40. 'magnetlink': magnetlink,
  41. 'seed': 'N/A',
  42. 'leech': 'N/A',
  43. 'template': 'torrent.html'})
  44. return results