digbt.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. DigBT (Videos, Music, Files)
  4. """
  5. from urllib.parse import urljoin
  6. from lxml import html
  7. from searx.utils import extract_text, get_torrent_size
  8. # about
  9. about = {
  10. "website": 'https://digbt.org',
  11. "wikidata_id": None,
  12. "official_api_documentation": None,
  13. "use_official_api": False,
  14. "require_api_key": False,
  15. "results": 'HTML',
  16. }
  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