]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/pokergo.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / pokergo.py
1 import base64
2
3 from .common import InfoExtractor
4 from ..utils import (
5 ExtractorError,
6 try_get,
7 )
8
9
10 class PokerGoBaseIE(InfoExtractor):
11 _NETRC_MACHINE = 'pokergo'
12 _AUTH_TOKEN = None
13 _PROPERTY_ID = '1dfb3940-7d53-4980-b0b0-f28b369a000d'
14
15 def _perform_login(self, username, password):
16 if self._AUTH_TOKEN:
17 return
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:
28 self.raise_login_required(method='password')
29
30
31 class 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 video_id = self._match_id(url)
57 data_json = self._download_json(
58 f'https://api.pokergo.com/v2/properties/{self._PROPERTY_ID}/videos/{video_id}', video_id,
59 headers={'authorization': f'Bearer {self._AUTH_TOKEN}'})['data']
60 v_id = data_json['source']
61
62 thumbnails = [{
63 'url': image['url'],
64 'id': image.get('label'),
65 'width': image.get('width'),
66 'height': image.get('height'),
67 } for image in data_json.get('images') or [] if image.get('url')]
68 series_json = next(dct for dct in data_json.get('show_tags') or [] if dct.get('video_id') == video_id) or {}
69
70 return {
71 '_type': 'url_transparent',
72 'display_id': video_id,
73 'title': data_json.get('title'),
74 'description': data_json.get('description'),
75 'duration': data_json.get('duration'),
76 'thumbnails': thumbnails,
77 'season_number': series_json.get('season'),
78 'episode_number': series_json.get('episode_number'),
79 'series': try_get(series_json, lambda x: x['tag']['name']),
80 'url': f'https://cdn.jwplayer.com/v2/media/{v_id}',
81 }
82
83
84 class PokerGoCollectionIE(PokerGoBaseIE):
85 _VALID_URL = r'https?://(?:www\.)?pokergo\.com/collections/(?P<id>[^&$#/?]+)'
86
87 _TESTS = [{
88 'url': 'https://www.pokergo.com/collections/19ffe481-5dae-481a-8869-75cc0e3c4700',
89 'playlist_mincount': 13,
90 'info_dict': {
91 'id': '19ffe481-5dae-481a-8869-75cc0e3c4700',
92 },
93 }]
94
95 def _entries(self, playlist_id):
96 data_json = self._download_json(
97 f'https://api.pokergo.com/v2/properties/{self._PROPERTY_ID}/collections/{playlist_id}?include=entities',
98 playlist_id, headers={'authorization': f'Bearer {self._AUTH_TOKEN}'})['data']
99 for video in data_json.get('collection_video') or []:
100 video_id = video.get('id')
101 if video_id:
102 yield self.url_result(
103 f'https://www.pokergo.com/videos/{video_id}',
104 ie=PokerGoIE.ie_key(), video_id=video_id)
105
106 def _real_extract(self, url):
107 playlist_id = self._match_id(url)
108 return self.playlist_result(self._entries(playlist_id), playlist_id=playlist_id)