laxarxames.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import json
  2. from .brightcove import BrightcoveNewIE
  3. from .common import InfoExtractor
  4. from ..utils import ExtractorError
  5. from ..utils.traversal import traverse_obj
  6. class LaXarxaMesIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/?#]+/)*?(player|movie-details)/(?P<id>\d+)'
  8. _NETRC_MACHINE = 'laxarxames'
  9. _TOKEN = None
  10. _TESTS = [{
  11. 'url': 'https://www.laxarxames.cat/player/3459421',
  12. 'md5': '0966f46c34275934c19af78f3df6e2bc',
  13. 'info_dict': {
  14. 'id': '6339612436112',
  15. 'ext': 'mp4',
  16. 'title': 'Resum | UA Horta — UD Viladecans',
  17. 'timestamp': 1697905186,
  18. 'thumbnail': r're:https?://.*\.jpg',
  19. 'description': '',
  20. 'upload_date': '20231021',
  21. 'duration': 129.44,
  22. 'tags': ['ott', 'esports', '23-24', ' futbol', ' futbol-partits', 'elit', 'resum'],
  23. 'uploader_id': '5779379807001',
  24. },
  25. 'skip': 'Requires login',
  26. }]
  27. def _perform_login(self, username, password):
  28. if self._TOKEN:
  29. return
  30. login = self._download_json(
  31. 'https://api.laxarxames.cat/Authorization/SignIn', None, note='Logging in', headers={
  32. 'X-Tenantorigin': 'https://laxarxames.cat',
  33. 'Content-Type': 'application/json',
  34. }, data=json.dumps({
  35. 'Username': username,
  36. 'Password': password,
  37. 'Device': {
  38. 'PlatformCode': 'WEB',
  39. 'Name': 'Mac OS ()',
  40. },
  41. }).encode(), expected_status=401)
  42. self._TOKEN = traverse_obj(login, ('AuthorizationToken', 'Token', {str}))
  43. if not self._TOKEN:
  44. raise ExtractorError('Login failed', expected=True)
  45. def _real_extract(self, url):
  46. video_id = self._match_id(url)
  47. if not self._TOKEN:
  48. self.raise_login_required()
  49. media_play_info = self._download_json(
  50. 'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
  51. data=json.dumps({
  52. 'MediaId': int(video_id),
  53. 'StreamType': 'MAIN',
  54. }).encode(), headers={
  55. 'Authorization': f'Bearer {self._TOKEN}',
  56. 'X-Tenantorigin': 'https://laxarxames.cat',
  57. 'Content-Type': 'application/json',
  58. })
  59. if not traverse_obj(media_play_info, ('ContentUrl', {str})):
  60. self.raise_no_formats('No video found', expected=True)
  61. return self.url_result(
  62. f'https://players.brightcove.net/5779379807001/default_default/index.html?videoId={media_play_info["ContentUrl"]}',
  63. BrightcoveNewIE, video_id, media_play_info.get('Title'))