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