]>
Commit | Line | Data |
---|---|---|
b1c35797 RA |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
b1c35797 | 4 | from ..utils import ( |
b1c35797 | 5 | dict_get, |
29f7c58a | 6 | ExtractorError, |
b1c35797 | 7 | int_or_none, |
34921b43 | 8 | join_nonempty, |
b1c35797 | 9 | parse_iso8601, |
f41b949a | 10 | traverse_obj, |
29f7c58a | 11 | try_get, |
12 | unescapeHTML, | |
f41b949a | 13 | urljoin, |
b1c35797 RA |
14 | ) |
15 | ||
16 | ||
17 | class PikselIE(InfoExtractor): | |
29f7c58a | 18 | _VALID_URL = r'''(?x)https?:// |
19 | (?: | |
20 | (?: | |
21 | player\. | |
22 | (?: | |
23 | olympusattelecom| | |
24 | vibebyvista | |
25 | )| | |
26 | (?:api|player)\.multicastmedia| | |
27 | (?:api-ovp|player)\.piksel | |
28 | )\.com| | |
29 | (?: | |
30 | mz-edge\.stream\.co| | |
31 | movie-s\.nhk\.or | |
32 | )\.jp| | |
33 | vidego\.baltimorecity\.gov | |
34 | )/v/(?:refid/(?P<refid>[^/]+)/prefid/)?(?P<id>[\w-]+)''' | |
bfd973ec | 35 | _EMBED_REGEX = [r'<iframe[^>]+src=["\'](?P<url>(?:https?:)?//player\.piksel\.com/v/[a-z0-9]+)'] |
c2521c1a JH |
36 | _TESTS = [ |
37 | { | |
0326bcb6 CC |
38 | 'url': 'http://player.piksel.com/v/ums2867l', |
39 | 'md5': '34e34c8d89dc2559976a6079db531e85', | |
c2521c1a | 40 | 'info_dict': { |
0326bcb6 | 41 | 'id': 'ums2867l', |
c2521c1a | 42 | 'ext': 'mp4', |
0326bcb6 CC |
43 | 'title': 'GX-005 with Caption', |
44 | 'timestamp': 1481335659, | |
45 | 'upload_date': '20161210' | |
c2521c1a JH |
46 | } |
47 | }, | |
48 | { | |
49 | # Original source: http://www.uscourts.gov/cameras-courts/state-washington-vs-donald-j-trump-et-al | |
50 | 'url': 'https://player.piksel.com/v/v80kqp41', | |
51 | 'md5': '753ddcd8cc8e4fa2dda4b7be0e77744d', | |
52 | 'info_dict': { | |
53 | 'id': 'v80kqp41', | |
54 | 'ext': 'mp4', | |
55 | 'title': 'WAW- State of Washington vs. Donald J. Trump, et al', | |
56 | 'description': 'State of Washington vs. Donald J. Trump, et al, Case Number 17-CV-00141-JLR, TRO Hearing, Civil Rights Case, 02/3/2017, 1:00 PM (PST), Seattle Federal Courthouse, Seattle, WA, Judge James L. Robart presiding.', | |
57 | 'timestamp': 1486171129, | |
0326bcb6 | 58 | 'upload_date': '20170204' |
c2521c1a | 59 | } |
a373befa RA |
60 | }, |
61 | { | |
62 | # https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2019240/ | |
63 | 'url': 'http://player.piksel.com/v/refid/nhkworld/prefid/nw_vod_v_en_2019_240_20190823233000_02_1566873477', | |
64 | 'only_matching': True, | |
b1c35797 | 65 | } |
c2521c1a | 66 | ] |
b1c35797 | 67 | |
f41b949a DR |
68 | def _call_api(self, app_token, resource, display_id, query, host='https://player.piksel.com', fatal=True): |
69 | url = urljoin(host, f'/ws/ws_{resource}/api/{app_token}/mode/json/apiv/5') | |
70 | response = traverse_obj( | |
71 | self._download_json(url, display_id, query=query, fatal=fatal), ('response', {dict})) or {} | |
72 | failure = traverse_obj(response, ('failure', 'reason')) if response else 'Empty response from API' | |
29f7c58a | 73 | if failure: |
74 | if fatal: | |
75 | raise ExtractorError(failure, expected=True) | |
76 | self.report_warning(failure) | |
77 | return response | |
78 | ||
b1c35797 | 79 | def _real_extract(self, url): |
5ad28e7f | 80 | ref_id, display_id = self._match_valid_url(url).groups() |
a373befa | 81 | webpage = self._download_webpage(url, display_id) |
c2521c1a JH |
82 | app_token = self._search_regex([ |
83 | r'clientAPI\s*:\s*"([^"]+)"', | |
84 | r'data-de-api-key\s*=\s*"([^"]+)"' | |
85 | ], webpage, 'app token') | |
29f7c58a | 86 | query = {'refid': ref_id, 'prefid': display_id} if ref_id else {'v': display_id} |
87 | program = self._call_api( | |
f41b949a | 88 | app_token, 'program', display_id, query, url)['WsProgramResponse']['program'] |
29f7c58a | 89 | video_id = program['uuid'] |
90 | video_data = program['asset'] | |
b1c35797 | 91 | title = video_data['title'] |
29f7c58a | 92 | asset_type = dict_get(video_data, ['assetType', 'asset_type']) |
b1c35797 RA |
93 | |
94 | formats = [] | |
95 | ||
29f7c58a | 96 | def process_asset_file(asset_file): |
97 | if not asset_file: | |
98 | return | |
b1c35797 RA |
99 | # TODO: extract rtmp formats |
100 | http_url = asset_file.get('http_url') | |
101 | if not http_url: | |
29f7c58a | 102 | return |
b1c35797 RA |
103 | tbr = None |
104 | vbr = int_or_none(asset_file.get('videoBitrate'), 1024) | |
105 | abr = int_or_none(asset_file.get('audioBitrate'), 1024) | |
106 | if asset_type == 'video': | |
107 | tbr = vbr + abr | |
108 | elif asset_type == 'audio': | |
109 | tbr = abr | |
110 | ||
b1c35797 | 111 | formats.append({ |
34921b43 | 112 | 'format_id': join_nonempty('http', tbr), |
b1c35797 RA |
113 | 'url': unescapeHTML(http_url), |
114 | 'vbr': vbr, | |
115 | 'abr': abr, | |
116 | 'width': int_or_none(asset_file.get('videoWidth')), | |
117 | 'height': int_or_none(asset_file.get('videoHeight')), | |
118 | 'filesize': int_or_none(asset_file.get('filesize')), | |
119 | 'tbr': tbr, | |
120 | }) | |
29f7c58a | 121 | |
122 | def process_asset_files(asset_files): | |
123 | for asset_file in (asset_files or []): | |
124 | process_asset_file(asset_file) | |
125 | ||
126 | process_asset_files(video_data.get('assetFiles')) | |
127 | process_asset_file(video_data.get('referenceFile')) | |
128 | if not formats: | |
129 | asset_id = video_data.get('assetid') or program.get('assetid') | |
130 | if asset_id: | |
131 | process_asset_files(try_get(self._call_api( | |
132 | app_token, 'asset_file', display_id, { | |
133 | 'assetid': asset_id, | |
f41b949a | 134 | }, url, False), lambda x: x['WsAssetFileResponse']['AssetFiles'])) |
29f7c58a | 135 | |
136 | m3u8_url = dict_get(video_data, [ | |
137 | 'm3u8iPadURL', | |
138 | 'ipadM3u8Url', | |
139 | 'm3u8AndroidURL', | |
140 | 'm3u8iPhoneURL', | |
141 | 'iphoneM3u8Url']) | |
142 | if m3u8_url: | |
143 | formats.extend(self._extract_m3u8_formats( | |
144 | m3u8_url, video_id, 'mp4', 'm3u8_native', | |
145 | m3u8_id='hls', fatal=False)) | |
146 | ||
147 | smil_url = dict_get(video_data, ['httpSmil', 'hdSmil', 'rtmpSmil']) | |
148 | if smil_url: | |
149 | transform_source = None | |
150 | if ref_id == 'nhkworld': | |
151 | # TODO: figure out if this is something to be fixed in urljoin, | |
152 | # _parse_smil_formats or keep it here | |
153 | transform_source = lambda x: x.replace('src="/', 'src="').replace('/media"', '/media/"') | |
154 | formats.extend(self._extract_smil_formats( | |
155 | re.sub(r'/od/[^/]+/', '/od/http/', smil_url), video_id, | |
156 | transform_source=transform_source, fatal=False)) | |
157 | ||
0326bcb6 CC |
158 | subtitles = {} |
159 | for caption in video_data.get('captions', []): | |
160 | caption_url = caption.get('url') | |
161 | if caption_url: | |
162 | subtitles.setdefault(caption.get('locale', 'en'), []).append({ | |
163 | 'url': caption_url}) | |
164 | ||
b1c35797 RA |
165 | return { |
166 | 'id': video_id, | |
167 | 'title': title, | |
168 | 'description': video_data.get('description'), | |
169 | 'thumbnail': video_data.get('thumbnailUrl'), | |
170 | 'timestamp': parse_iso8601(video_data.get('dateadd')), | |
171 | 'formats': formats, | |
0326bcb6 | 172 | 'subtitles': subtitles, |
9f14daf2 | 173 | '_format_sort_fields': ('tbr', ), # Incomplete resolution information |
b1c35797 | 174 | } |