digbt.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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
  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 []
  31. results = []
  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 = f"{files_data[FILESIZE]} {files_data[FILESIZE_MULTIPLIER]}"
  38. magnetlink = result.xpath('.//div[@class="tail"]//a[@class="title"]/@href')[0]
  39. results.append(
  40. {
  41. 'url': url,
  42. 'title': title,
  43. 'content': content,
  44. 'filesize': filesize,
  45. 'magnetlink': magnetlink,
  46. 'seed': 'N/A',
  47. 'leech': 'N/A',
  48. 'template': 'torrent.html',
  49. }
  50. )
  51. return results