bitchute.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """bitchute (Videos)"""
  3. from json import dumps
  4. from datetime import datetime
  5. from searx.utils import html_to_text
  6. about = {
  7. "website": 'https://bitchute.com',
  8. "wikidata_id": "Q45287179",
  9. "official_api_documentation": None,
  10. "use_official_api": False,
  11. "require_api_key": False,
  12. "results": "JSON",
  13. }
  14. base_url = "https://api.bitchute.com/api/beta/search/videos"
  15. categories = ['videos']
  16. paging = True
  17. results_per_page = 20
  18. def request(query, params):
  19. start_index = (params["pageno"] - 1) * results_per_page
  20. data = {"offset": start_index, "limit": results_per_page, "query": query, "sensitivity_id": "normal", "sort": "new"}
  21. params["url"] = base_url
  22. params["method"] = 'POST'
  23. params['headers']['content-type'] = "application/json"
  24. params['data'] = dumps(data)
  25. return params
  26. def response(resp):
  27. search_res = resp.json()
  28. results = []
  29. for item in search_res.get('videos', []):
  30. results.append(
  31. {
  32. "title": item['video_name'],
  33. "url": 'https://www.bitchute.com/video/' + item['video_id'],
  34. "content": html_to_text(item['description']),
  35. "author": item['channel']['channel_name'],
  36. "publishedDate": datetime.strptime(item["date_published"], "%Y-%m-%dT%H:%M:%S.%fZ"),
  37. "length": item['duration'],
  38. "views": item['view_count'],
  39. "thumbnail": item['thumbnail_url'],
  40. "iframe_src": 'https://www.bitchute.com/embed/' + item['video_id'],
  41. "template": "videos.html",
  42. }
  43. )
  44. return results