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