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