pokergo.py 4.2 KB

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