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