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