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