pokergo.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import base64
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. try_get,
  6. )
  7. class PokerGoBaseIE(InfoExtractor):
  8. _NETRC_MACHINE = 'pokergo'
  9. _AUTH_TOKEN = None
  10. _PROPERTY_ID = '1dfb3940-7d53-4980-b0b0-f28b369a000d'
  11. def _perform_login(self, username, password):
  12. if self._AUTH_TOKEN:
  13. return
  14. self.report_login()
  15. PokerGoBaseIE._AUTH_TOKEN = self._download_json(
  16. f'https://subscription.pokergo.com/properties/{self._PROPERTY_ID}/sign-in', None,
  17. headers={'authorization': f'Basic {base64.b64encode(f"{username}:{password}".encode()).decode()}'},
  18. data=b'')['meta']['token']
  19. if not self._AUTH_TOKEN:
  20. raise ExtractorError('Unable to get Auth Token.', expected=True)
  21. def _real_initialize(self):
  22. if not self._AUTH_TOKEN:
  23. self.raise_login_required(method='password')
  24. class PokerGoIE(PokerGoBaseIE):
  25. _VALID_URL = r'https?://(?:www\.)?pokergo\.com/videos/(?P<id>[^&$#/?]+)'
  26. _TESTS = [{
  27. 'url': 'https://www.pokergo.com/videos/2a70ec4e-4a80-414b-97ec-725d9b72a7dc',
  28. 'info_dict': {
  29. 'id': 'aVLOxDzY',
  30. 'ext': 'mp4',
  31. 'title': 'Poker After Dark | Season 12 (2020) | Cry Me a River | Episode 2',
  32. 'description': 'md5:c7a8c29556cbfb6eb3c0d5d622251b71',
  33. 'thumbnail': 'https://cdn.jwplayer.com/v2/media/aVLOxDzY/poster.jpg?width=720',
  34. 'timestamp': 1608085715,
  35. 'duration': 2700.12,
  36. 'season_number': 12,
  37. 'episode_number': 2,
  38. 'series': 'poker after dark',
  39. 'upload_date': '20201216',
  40. 'season': 'Season 12',
  41. 'episode': 'Episode 2',
  42. 'display_id': '2a70ec4e-4a80-414b-97ec-725d9b72a7dc',
  43. },
  44. 'params': {'skip_download': True}
  45. }]
  46. def _real_extract(self, url):
  47. id = self._match_id(url)
  48. data_json = self._download_json(f'https://api.pokergo.com/v2/properties/{self._PROPERTY_ID}/videos/{id}', id,
  49. headers={'authorization': f'Bearer {self._AUTH_TOKEN}'})['data']
  50. v_id = data_json['source']
  51. thumbnails = [{
  52. 'url': image['url'],
  53. 'id': image.get('label'),
  54. 'width': image.get('width'),
  55. 'height': image.get('height')
  56. } for image in data_json.get('images') or [] if image.get('url')]
  57. series_json = next(dct for dct in data_json.get('show_tags') or [] if dct.get('video_id') == id) or {}
  58. return {
  59. '_type': 'url_transparent',
  60. 'display_id': id,
  61. 'title': data_json.get('title'),
  62. 'description': data_json.get('description'),
  63. 'duration': data_json.get('duration'),
  64. 'thumbnails': thumbnails,
  65. 'season_number': series_json.get('season'),
  66. 'episode_number': series_json.get('episode_number'),
  67. 'series': try_get(series_json, lambda x: x['tag']['name']),
  68. 'url': f'https://cdn.jwplayer.com/v2/media/{v_id}'
  69. }
  70. class PokerGoCollectionIE(PokerGoBaseIE):
  71. _VALID_URL = r'https?://(?:www\.)?pokergo\.com/collections/(?P<id>[^&$#/?]+)'
  72. _TESTS = [{
  73. 'url': 'https://www.pokergo.com/collections/19ffe481-5dae-481a-8869-75cc0e3c4700',
  74. 'playlist_mincount': 13,
  75. 'info_dict': {
  76. 'id': '19ffe481-5dae-481a-8869-75cc0e3c4700',
  77. },
  78. }]
  79. def _entries(self, id):
  80. data_json = self._download_json(f'https://api.pokergo.com/v2/properties/{self._PROPERTY_ID}/collections/{id}?include=entities',
  81. id, headers={'authorization': f'Bearer {self._AUTH_TOKEN}'})['data']
  82. for video in data_json.get('collection_video') or []:
  83. video_id = video.get('id')
  84. if video_id:
  85. yield self.url_result(
  86. f'https://www.pokergo.com/videos/{video_id}',
  87. ie=PokerGoIE.ie_key(), video_id=video_id)
  88. def _real_extract(self, url):
  89. id = self._match_id(url)
  90. return self.playlist_result(self._entries(id), playlist_id=id)