digbt.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 sys import version_info
  11. from lxml import html
  12. from searx.engines.xpath import extract_text
  13. from searx.utils import get_torrent_size
  14. from searx.url_utils import urljoin
  15. if version_info[0] == 3:
  16. unicode = str
  17. categories = ['videos', 'music', 'files']
  18. paging = True
  19. URL = 'https://digbt.org'
  20. SEARCH_URL = URL + '/search/{query}-time-{pageno}'
  21. FILESIZE = 3
  22. FILESIZE_MULTIPLIER = 4
  23. def request(query, params):
  24. params['url'] = SEARCH_URL.format(query=query, pageno=params['pageno'])
  25. return params
  26. def response(resp):
  27. dom = html.fromstring(resp.text)
  28. search_res = dom.xpath('.//td[@class="x-item"]')
  29. if not search_res:
  30. return list()
  31. results = list()
  32. for result in search_res:
  33. url = urljoin(URL, result.xpath('.//a[@title]/@href')[0])
  34. title = extract_text(result.xpath('.//a[@title]'))
  35. content = extract_text(result.xpath('.//div[@class="files"]'))
  36. files_data = extract_text(result.xpath('.//div[@class="tail"]')).split()
  37. filesize = get_torrent_size(files_data[FILESIZE], files_data[FILESIZE_MULTIPLIER])
  38. magnetlink = result.xpath('.//div[@class="tail"]//a[@class="title"]/@href')[0]
  39. results.append({'url': url,
  40. 'title': title,
  41. 'content': content,
  42. 'filesize': filesize,
  43. 'magnetlink': magnetlink,
  44. 'seed': 'N/A',
  45. 'leech': 'N/A',
  46. 'template': 'torrent.html'})
  47. return results