]>
Commit | Line | Data |
---|---|---|
608b8a43 | 1 | import hashlib |
934858ad | 2 | import itertools |
d6039175 | 3 | import re |
ac668111 | 4 | import urllib.parse |
d6039175 | 5 | |
ac668111 | 6 | from .brightcove import BrightcoveNewIE |
934858ad | 7 | from .common import InfoExtractor, SearchInfoExtractor |
ac668111 | 8 | from .youtube import YoutubeIE |
9 | from ..compat import compat_str | |
1cc79574 | 10 | from ..utils import ( |
2468a6fa | 11 | ExtractorError, |
ac668111 | 12 | clean_html, |
7217e148 | 13 | int_or_none, |
ecee5724 | 14 | mimetype2ext, |
45f4a433 | 15 | parse_iso8601, |
c8da40d8 | 16 | smuggle_url, |
608b8a43 | 17 | try_get, |
608b8a43 | 18 | url_or_none, |
d6039175 PH |
19 | ) |
20 | ||
9c15e9de | 21 | |
d6039175 | 22 | class YahooIE(InfoExtractor): |
a4eb9578 | 23 | IE_DESC = 'Yahoo screen and movies' |
3cf70bf1 | 24 | _VALID_URL = r'(?P<url>https?://(?:(?P<country>[a-zA-Z]{2}(?:-[a-zA-Z]{2})?|malaysia)\.)?(?:[\da-zA-Z_-]+\.)?yahoo\.com/(?:[^/]+/)*(?P<id>[^?&#]*-[0-9]+(?:-[a-z]+)?)\.html)' |
45f4a433 RA |
25 | _TESTS = [{ |
26 | 'url': 'http://screen.yahoo.com/julian-smith-travis-legg-watch-214727115.html', | |
27 | 'info_dict': { | |
28 | 'id': '2d25e626-2378-391f-ada0-ddaf1417e588', | |
29 | 'ext': 'mp4', | |
30 | 'title': 'Julian Smith & Travis Legg Watch Julian Smith', | |
31 | 'description': 'Julian and Travis watch Julian Smith', | |
32 | 'duration': 6863, | |
33 | 'timestamp': 1369812016, | |
34 | 'upload_date': '20130529', | |
9c15e9de | 35 | }, |
412cce82 | 36 | 'skip': 'No longer exists', |
45f4a433 RA |
37 | }, { |
38 | 'url': 'https://screen.yahoo.com/community/community-sizzle-reel-203225340.html?format=embed', | |
39 | 'md5': '7993e572fac98e044588d0b5260f4352', | |
40 | 'info_dict': { | |
41 | 'id': '4fe78544-8d48-39d8-97cd-13f205d9fcdb', | |
42 | 'ext': 'mp4', | |
43 | 'title': "Yahoo Saves 'Community'", | |
44 | 'description': 'md5:4d4145af2fd3de00cbb6c1d664105053', | |
45 | 'duration': 170, | |
46 | 'timestamp': 1406838636, | |
47 | 'upload_date': '20140731', | |
6f5ac90c | 48 | }, |
412cce82 | 49 | 'skip': 'Unfortunately, this video is not available in your region', |
45f4a433 RA |
50 | }, { |
51 | 'url': 'https://uk.screen.yahoo.com/editor-picks/cute-raccoon-freed-drain-using-091756545.html', | |
8040a0d3 | 52 | 'md5': '71298482f7c64cbb7fa064e4553ff1c1', |
45f4a433 RA |
53 | 'info_dict': { |
54 | 'id': 'b3affa53-2e14-3590-852b-0e0db6cd1a58', | |
8040a0d3 | 55 | 'ext': 'webm', |
45f4a433 RA |
56 | 'title': 'Cute Raccoon Freed From Drain\u00a0Using Angle Grinder', |
57 | 'description': 'md5:f66c890e1490f4910a9953c941dee944', | |
58 | 'duration': 97, | |
59 | 'timestamp': 1414489862, | |
60 | 'upload_date': '20141028', | |
412cce82 L |
61 | }, |
62 | 'skip': 'No longer exists', | |
45f4a433 RA |
63 | }, { |
64 | 'url': 'http://news.yahoo.com/video/china-moses-crazy-blues-104538833.html', | |
65 | 'md5': '88e209b417f173d86186bef6e4d1f160', | |
66 | 'info_dict': { | |
67 | 'id': 'f885cf7f-43d4-3450-9fac-46ac30ece521', | |
68 | 'ext': 'mp4', | |
69 | 'title': 'China Moses Is Crazy About the Blues', | |
70 | 'description': 'md5:9900ab8cd5808175c7b3fe55b979bed0', | |
71 | 'duration': 128, | |
72 | 'timestamp': 1385722202, | |
73 | 'upload_date': '20131129', | |
74 | } | |
75 | }, { | |
76 | 'url': 'https://www.yahoo.com/movies/v/true-story-trailer-173000497.html', | |
77 | 'md5': '2a9752f74cb898af5d1083ea9f661b58', | |
78 | 'info_dict': { | |
79 | 'id': '071c4013-ce30-3a93-a5b2-e0413cd4a9d1', | |
80 | 'ext': 'mp4', | |
81 | 'title': '\'True Story\' Trailer', | |
82 | 'description': 'True Story', | |
83 | 'duration': 150, | |
84 | 'timestamp': 1418919206, | |
85 | 'upload_date': '20141218', | |
762958d5 | 86 | }, |
45f4a433 RA |
87 | }, { |
88 | 'url': 'https://gma.yahoo.com/pizza-delivery-man-surprised-huge-tip-college-kids-195200785.html', | |
89 | 'only_matching': True, | |
90 | }, { | |
91 | 'note': 'NBC Sports embeds', | |
92 | 'url': 'http://sports.yahoo.com/blogs/ncaab-the-dagger/tyler-kalinoski-s-buzzer-beater-caps-davidson-s-comeback-win-185609842.html?guid=nbc_cbk_davidsonbuzzerbeater_150313', | |
93 | 'info_dict': { | |
94 | 'id': '9CsDKds0kvHI', | |
95 | 'ext': 'flv', | |
96 | 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d', | |
97 | 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson', | |
98 | 'upload_date': '20150313', | |
99 | 'uploader': 'NBCU-SPORTS', | |
100 | 'timestamp': 1426270238, | |
762958d5 | 101 | }, |
45f4a433 RA |
102 | }, { |
103 | 'url': 'https://tw.news.yahoo.com/-100120367.html', | |
104 | 'only_matching': True, | |
105 | }, { | |
106 | # Query result is embedded in webpage, but explicit request to video API fails with geo restriction | |
107 | 'url': 'https://screen.yahoo.com/community/communitary-community-episode-1-ladders-154501237.html', | |
108 | 'md5': '4fbafb9c9b6f07aa8f870629f6671b35', | |
109 | 'info_dict': { | |
110 | 'id': '1f32853c-a271-3eef-8cb6-f6d6872cb504', | |
111 | 'ext': 'mp4', | |
112 | 'title': 'Communitary - Community Episode 1: Ladders', | |
113 | 'description': 'md5:8fc39608213295748e1e289807838c97', | |
114 | 'duration': 1646, | |
115 | 'timestamp': 1440436550, | |
116 | 'upload_date': '20150824', | |
117 | 'series': 'Communitary', | |
118 | 'season_number': 6, | |
119 | 'episode_number': 1, | |
49807b4a | 120 | }, |
412cce82 | 121 | 'skip': 'No longer exists', |
45f4a433 RA |
122 | }, { |
123 | # ytwnews://cavideo/ | |
124 | 'url': 'https://tw.video.yahoo.com/movie-tw/單車天使-中文版預-092316541.html', | |
125 | 'info_dict': { | |
126 | 'id': 'ba133ff2-0793-3510-b636-59dfe9ff6cff', | |
127 | 'ext': 'mp4', | |
128 | 'title': '單車天使 - 中文版預', | |
129 | 'description': '中文版預', | |
130 | 'timestamp': 1476696196, | |
131 | 'upload_date': '20161017', | |
ca227c86 | 132 | }, |
45f4a433 RA |
133 | 'params': { |
134 | 'skip_download': True, | |
2a7c3883 | 135 | }, |
45f4a433 RA |
136 | }, { |
137 | # Contains both a Yahoo hosted video and multiple Youtube embeds | |
138 | 'url': 'https://www.yahoo.com/entertainment/gwen-stefani-reveals-the-pop-hit-she-passed-on-assigns-it-to-her-voice-contestant-instead-033045672.html', | |
139 | 'info_dict': { | |
140 | 'id': '46c5d95a-528f-3d03-b732-732fcadd51de', | |
141 | 'title': 'Gwen Stefani reveals the pop hit she passed on, assigns it to her \'Voice\' contestant instead', | |
142 | 'description': 'Gwen decided not to record this hit herself, but she decided it was the perfect fit for Kyndall Inskeep.', | |
b61cd518 | 143 | }, |
45f4a433 | 144 | 'playlist': [{ |
f420902a | 145 | 'info_dict': { |
45f4a433 | 146 | 'id': '966d4262-4fd1-3aaa-b45b-049ca6e38ba6', |
f420902a | 147 | 'ext': 'mp4', |
45f4a433 RA |
148 | 'title': 'Gwen Stefani reveals she turned down one of Sia\'s best songs', |
149 | 'description': 'On "The Voice" Tuesday, Gwen Stefani told Taylor Swift which Sia hit was almost hers.', | |
150 | 'timestamp': 1572406500, | |
151 | 'upload_date': '20191030', | |
f420902a | 152 | }, |
45f4a433 | 153 | }, { |
eb9a15be | 154 | 'info_dict': { |
45f4a433 | 155 | 'id': '352CFDOQrKg', |
eb9a15be | 156 | 'ext': 'mp4', |
45f4a433 | 157 | 'title': 'Kyndal Inskeep "Performs the Hell Out of" Sia\'s "Elastic Heart" - The Voice Knockouts 2019', |
412cce82 | 158 | 'description': 'md5:7fe8e3d5806f96002e55f190d1d94479', |
45f4a433 RA |
159 | 'uploader': 'The Voice', |
160 | 'uploader_id': 'NBCTheVoice', | |
161 | 'upload_date': '20191029', | |
eb9a15be | 162 | }, |
45f4a433 RA |
163 | }], |
164 | 'params': { | |
165 | 'playlistend': 2, | |
c8da40d8 | 166 | }, |
412cce82 | 167 | 'expected_warnings': ['HTTP Error 404', 'Ignoring subtitle tracks'], |
45f4a433 RA |
168 | }, { |
169 | 'url': 'https://malaysia.news.yahoo.com/video/bystanders-help-ontario-policeman-bust-190932818.html', | |
170 | 'only_matching': True, | |
171 | }, { | |
172 | 'url': 'https://es-us.noticias.yahoo.com/es-la-puerta-irrompible-que-110539379.html', | |
173 | 'only_matching': True, | |
237513e8 RA |
174 | }, { |
175 | 'url': 'https://www.yahoo.com/entertainment/v/longtime-cbs-news-60-minutes-032036500-cbs.html', | |
176 | 'only_matching': True, | |
45f4a433 | 177 | }] |
d6039175 | 178 | |
a820dc72 | 179 | def _extract_yahoo_video(self, video_id, country): |
45f4a433 | 180 | video = self._download_json( |
a820dc72 | 181 | 'https://%s.yahoo.com/_td/api/resource/VideoService.videos;view=full;video_ids=["%s"]' % (country, video_id), |
45f4a433 RA |
182 | video_id, 'Downloading video JSON metadata')[0] |
183 | title = video['title'] | |
befd88b7 | 184 | |
45f4a433 RA |
185 | if country == 'malaysia': |
186 | country = 'my' | |
3c06d371 | 187 | |
45f4a433 | 188 | is_live = video.get('live_state') == 'live' |
8040a0d3 | 189 | fmts = ('m3u8',) if is_live else ('webm', 'mp4') |
9c15e9de | 190 | |
45f4a433 | 191 | urls = [] |
9c15e9de | 192 | formats = [] |
45f4a433 RA |
193 | subtitles = {} |
194 | for fmt in fmts: | |
195 | media_obj = self._download_json( | |
196 | 'https://video-api.yql.yahoo.com/v1/video/sapi/streams/' + video_id, | |
197 | video_id, 'Downloading %s JSON metadata' % fmt, | |
198 | headers=self.geo_verification_headers(), query={ | |
199 | 'format': fmt, | |
200 | 'region': country.upper(), | |
201 | })['query']['results']['mediaObj'][0] | |
202 | msg = media_obj.get('status', {}).get('msg') | |
9c15e9de | 203 | |
45f4a433 RA |
204 | for s in media_obj.get('streams', []): |
205 | host = s.get('host') | |
206 | path = s.get('path') | |
207 | if not host or not path: | |
208 | continue | |
209 | s_url = host + path | |
210 | if s.get('format') == 'm3u8': | |
211 | formats.extend(self._extract_m3u8_formats( | |
212 | s_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) | |
213 | continue | |
214 | tbr = int_or_none(s.get('bitrate')) | |
215 | formats.append({ | |
216 | 'url': s_url, | |
217 | 'format_id': fmt + ('-%d' % tbr if tbr else ''), | |
218 | 'width': int_or_none(s.get('width')), | |
219 | 'height': int_or_none(s.get('height')), | |
220 | 'tbr': tbr, | |
221 | 'fps': int_or_none(s.get('framerate')), | |
9c15e9de | 222 | }) |
ecee5724 | 223 | |
45f4a433 RA |
224 | for cc in media_obj.get('closedcaptions', []): |
225 | cc_url = cc.get('url') | |
226 | if not cc_url or cc_url in urls: | |
227 | continue | |
228 | urls.append(cc_url) | |
229 | subtitles.setdefault(cc.get('lang') or 'en-US', []).append({ | |
230 | 'url': cc_url, | |
231 | 'ext': mimetype2ext(cc.get('content_type')), | |
ecee5724 YCH |
232 | }) |
233 | ||
45f4a433 RA |
234 | streaming_url = video.get('streaming_url') |
235 | if streaming_url and not is_live: | |
236 | formats.extend(self._extract_m3u8_formats( | |
237 | streaming_url, video_id, 'mp4', | |
238 | 'm3u8_native', m3u8_id='hls', fatal=False)) | |
239 | ||
240 | if not formats and msg == 'geo restricted': | |
b7da73eb | 241 | self.raise_geo_restricted(metadata_available=True) |
45f4a433 RA |
242 | |
243 | self._sort_formats(formats) | |
244 | ||
245 | thumbnails = [] | |
246 | for thumb in video.get('thumbnails', []): | |
247 | thumb_url = thumb.get('url') | |
248 | if not thumb_url: | |
249 | continue | |
250 | thumbnails.append({ | |
251 | 'id': thumb.get('tag'), | |
252 | 'url': thumb.get('url'), | |
253 | 'width': int_or_none(thumb.get('width')), | |
254 | 'height': int_or_none(thumb.get('height')), | |
255 | }) | |
256 | ||
257 | series_info = video.get('series_info') or {} | |
258 | ||
35907e23 | 259 | return { |
9c15e9de | 260 | 'id': video_id, |
39ca3b5c | 261 | 'title': title, |
9c15e9de | 262 | 'formats': formats, |
45f4a433 RA |
263 | 'thumbnails': thumbnails, |
264 | 'description': clean_html(video.get('description')), | |
265 | 'timestamp': parse_iso8601(video.get('publish_time')), | |
ecee5724 | 266 | 'subtitles': subtitles, |
45f4a433 RA |
267 | 'duration': int_or_none(video.get('duration')), |
268 | 'view_count': int_or_none(video.get('view_count')), | |
269 | 'is_live': is_live, | |
270 | 'series': video.get('show_name'), | |
271 | 'season_number': int_or_none(series_info.get('season_number')), | |
272 | 'episode_number': int_or_none(series_info.get('episode_number')), | |
9c15e9de | 273 | } |
d6039175 | 274 | |
a820dc72 | 275 | def _real_extract(self, url): |
5ad28e7f | 276 | url, country, display_id = self._match_valid_url(url).groups() |
a820dc72 RA |
277 | if not country: |
278 | country = 'us' | |
279 | else: | |
280 | country = country.split('-')[0] | |
281 | ||
412cce82 | 282 | items = self._download_json( |
a820dc72 RA |
283 | 'https://%s.yahoo.com/caas/content/article' % country, display_id, |
284 | 'Downloading content JSON metadata', query={ | |
285 | 'url': url | |
412cce82 | 286 | })['items'][0] |
a820dc72 | 287 | |
412cce82 | 288 | item = items['data']['partnerData'] |
a820dc72 RA |
289 | if item.get('type') != 'video': |
290 | entries = [] | |
291 | ||
292 | cover = item.get('cover') or {} | |
293 | if cover.get('type') == 'yvideo': | |
294 | cover_url = cover.get('url') | |
295 | if cover_url: | |
296 | entries.append(self.url_result( | |
297 | cover_url, 'Yahoo', cover.get('uuid'))) | |
298 | ||
299 | for e in (item.get('body') or []): | |
300 | if e.get('type') == 'videoIframe': | |
301 | iframe_url = e.get('url') | |
412cce82 L |
302 | if iframe_url: |
303 | entries.append(self.url_result(iframe_url)) | |
304 | ||
305 | if item.get('type') == 'storywithleadvideo': | |
306 | iframe_url = try_get(item, lambda x: x['meta']['player']['url']) | |
307 | if iframe_url: | |
a820dc72 | 308 | entries.append(self.url_result(iframe_url)) |
412cce82 L |
309 | else: |
310 | self.report_warning("Yahoo didn't provide an iframe url for this storywithleadvideo") | |
311 | ||
312 | if items.get('markup'): | |
313 | entries.extend( | |
314 | self.url_result(yt_url) for yt_url in YoutubeIE._extract_urls(items['markup'])) | |
a820dc72 RA |
315 | |
316 | return self.playlist_result( | |
317 | entries, item.get('uuid'), | |
318 | item.get('title'), item.get('summary')) | |
319 | ||
320 | info = self._extract_yahoo_video(item['uuid'], country) | |
321 | info['display_id'] = display_id | |
322 | return info | |
323 | ||
934858ad PH |
324 | |
325 | class YahooSearchIE(SearchInfoExtractor): | |
2317e6b2 | 326 | IE_DESC = 'Yahoo screen search' |
934858ad | 327 | _MAX_RESULTS = 1000 |
2317e6b2 | 328 | IE_NAME = 'screen.yahoo:search' |
934858ad PH |
329 | _SEARCH_KEY = 'yvsearch' |
330 | ||
cc16383f | 331 | def _search_results(self, query): |
88f1c6de | 332 | for pagenum in itertools.count(0): |
ac668111 | 333 | result_url = 'http://video.search.yahoo.com/search/?p=%s&fr=screen&o=js&gs=0&b=%d' % (urllib.parse.quote_plus(query), pagenum * 30) |
88f1c6de | 334 | info = self._download_json(result_url, query, |
9e1a5b84 | 335 | note='Downloading results page ' + str(pagenum + 1)) |
cc16383f | 336 | yield from (self.url_result(result['rurl']) for result in info['results']) |
337 | if info['m']['last'] >= info['m']['total'] - 1: | |
934858ad PH |
338 | break |
339 | ||
174f6299 RA |
340 | |
341 | class YahooGyaOPlayerIE(InfoExtractor): | |
342 | IE_NAME = 'yahoo:gyao:player' | |
ccc7795c | 343 | _VALID_URL = r'https?://(?:gyao\.yahoo\.co\.jp/(?:player|episode(?:/[^/]+)?)|streaming\.yahoo\.co\.jp/c/y)/(?P<id>\d+/v\d+/v\d+|[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})' |
3534b632 | 344 | _TESTS = [{ |
174f6299 RA |
345 | 'url': 'https://gyao.yahoo.co.jp/player/00998/v00818/v0000000000000008564/', |
346 | 'info_dict': { | |
347 | 'id': '5993125228001', | |
348 | 'ext': 'mp4', | |
349 | 'title': 'フューリー 【字幕版】', | |
350 | 'description': 'md5:21e691c798a15330eda4db17a8fe45a5', | |
351 | 'uploader_id': '4235717419001', | |
352 | 'upload_date': '20190124', | |
353 | 'timestamp': 1548294365, | |
354 | }, | |
355 | 'params': { | |
356 | # m3u8 download | |
357 | 'skip_download': True, | |
358 | }, | |
3534b632 RA |
359 | }, { |
360 | 'url': 'https://streaming.yahoo.co.jp/c/y/01034/v00133/v0000000000000000706/', | |
361 | 'only_matching': True, | |
0b758fea RA |
362 | }, { |
363 | 'url': 'https://gyao.yahoo.co.jp/episode/%E3%81%8D%E3%81%AE%E3%81%86%E4%BD%95%E9%A3%9F%E3%81%B9%E3%81%9F%EF%BC%9F%20%E7%AC%AC2%E8%A9%B1%202019%2F4%2F12%E6%94%BE%E9%80%81%E5%88%86/5cb02352-b725-409e-9f8d-88f947a9f682', | |
364 | 'only_matching': True, | |
ccc7795c THD |
365 | }, { |
366 | 'url': 'https://gyao.yahoo.co.jp/episode/5fa1226c-ef8d-4e93-af7a-fd92f4e30597', | |
367 | 'only_matching': True, | |
3534b632 | 368 | }] |
2468a6fa | 369 | _GEO_BYPASS = False |
174f6299 RA |
370 | |
371 | def _real_extract(self, url): | |
372 | video_id = self._match_id(url).replace('/', ':') | |
2468a6fa RA |
373 | headers = self.geo_verification_headers() |
374 | headers['Accept'] = 'application/json' | |
375 | resp = self._download_json( | |
376 | 'https://gyao.yahoo.co.jp/apis/playback/graphql', video_id, query={ | |
377 | 'appId': 'dj00aiZpPUNJeDh2cU1RazU3UCZzPWNvbnN1bWVyc2VjcmV0Jng9NTk-', | |
378 | 'query': '''{ | |
379 | content(parameter: {contentId: "%s", logicaAgent: PC_WEB}) { | |
380 | video { | |
381 | delivery { | |
382 | id | |
383 | } | |
384 | title | |
385 | } | |
386 | } | |
387 | }''' % video_id, | |
388 | }, headers=headers) | |
389 | content = resp['data']['content'] | |
390 | if not content: | |
391 | msg = resp['errors'][0]['message'] | |
392 | if msg == 'not in japan': | |
393 | self.raise_geo_restricted(countries=['JP']) | |
394 | raise ExtractorError(msg) | |
395 | video = content['video'] | |
174f6299 RA |
396 | return { |
397 | '_type': 'url_transparent', | |
398 | 'id': video_id, | |
399 | 'title': video['title'], | |
0b758fea | 400 | 'url': smuggle_url( |
2468a6fa | 401 | 'http://players.brightcove.net/4235717419001/SyG5P0gjb_default/index.html?videoId=' + video['delivery']['id'], |
0b758fea | 402 | {'geo_countries': ['JP']}), |
174f6299 RA |
403 | 'ie_key': BrightcoveNewIE.ie_key(), |
404 | } | |
405 | ||
406 | ||
407 | class YahooGyaOIE(InfoExtractor): | |
408 | IE_NAME = 'yahoo:gyao' | |
2468a6fa | 409 | _VALID_URL = r'https?://(?:gyao\.yahoo\.co\.jp/(?:p|title(?:/[^/]+)?)|streaming\.yahoo\.co\.jp/p/y)/(?P<id>\d+/v\d+|[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})' |
3534b632 | 410 | _TESTS = [{ |
e9a6a65a | 411 | 'url': 'https://gyao.yahoo.co.jp/title/%E3%82%BF%E3%82%A4%E3%83%A0%E3%83%9C%E3%82%AB%E3%83%B3%E3%82%B7%E3%83%AA%E3%83%BC%E3%82%BA%20%E3%83%A4%E3%83%83%E3%82%BF%E3%83%BC%E3%83%9E%E3%83%B3/5f60ceb3-6e5e-40ef-ba40-d68b598d067f', |
174f6299 | 412 | 'info_dict': { |
e9a6a65a | 413 | 'id': '5f60ceb3-6e5e-40ef-ba40-d68b598d067f', |
174f6299 | 414 | }, |
e9a6a65a HY |
415 | 'playlist_mincount': 80, |
416 | }, { | |
417 | 'url': 'https://gyao.yahoo.co.jp/p/00449/v03102/', | |
418 | 'only_matching': True, | |
3534b632 RA |
419 | }, { |
420 | 'url': 'https://streaming.yahoo.co.jp/p/y/01034/v00133/', | |
421 | 'only_matching': True, | |
a5b92d35 RA |
422 | }, { |
423 | 'url': 'https://gyao.yahoo.co.jp/title/%E3%81%97%E3%82%83%E3%81%B9%E3%81%8F%E3%82%8A007/5b025a49-b2e5-4dc7-945c-09c6634afacf', | |
424 | 'only_matching': True, | |
2468a6fa RA |
425 | }, { |
426 | 'url': 'https://gyao.yahoo.co.jp/title/5b025a49-b2e5-4dc7-945c-09c6634afacf', | |
427 | 'only_matching': True, | |
3534b632 | 428 | }] |
174f6299 | 429 | |
e9a6a65a HY |
430 | def _entries(self, program_id): |
431 | page = 1 | |
432 | while True: | |
433 | playlist = self._download_json( | |
8a3e7b1c | 434 | f'https://gyao.yahoo.co.jp/api/programs/{program_id}/videos?page={page}&serviceId=gy', program_id, |
e9a6a65a HY |
435 | note=f'Downloading JSON metadata page {page}') |
436 | if not playlist: | |
437 | break | |
438 | for video in playlist['videos']: | |
439 | video_id = video.get('id') | |
440 | if not video_id: | |
441 | continue | |
442 | if video.get('streamingAvailability') == 'notYet': | |
443 | continue | |
444 | yield self.url_result( | |
445 | 'https://gyao.yahoo.co.jp/player/%s/' % video_id.replace(':', '/'), | |
446 | YahooGyaOPlayerIE.ie_key(), video_id) | |
447 | if playlist.get('ended'): | |
448 | break | |
449 | page += 1 | |
450 | ||
174f6299 RA |
451 | def _real_extract(self, url): |
452 | program_id = self._match_id(url).replace('/', ':') | |
e9a6a65a | 453 | return self.playlist_result(self._entries(program_id), program_id) |
608b8a43 K |
454 | |
455 | ||
456 | class YahooJapanNewsIE(InfoExtractor): | |
457 | IE_NAME = 'yahoo:japannews' | |
458 | IE_DESC = 'Yahoo! Japan News' | |
459 | _VALID_URL = r'https?://(?P<host>(?:news|headlines)\.yahoo\.co\.jp)[^\d]*(?P<id>\d[\d-]*\d)?' | |
460 | _GEO_COUNTRIES = ['JP'] | |
461 | _TESTS = [{ | |
462 | 'url': 'https://headlines.yahoo.co.jp/videonews/ann?a=20190716-00000071-ann-int', | |
463 | 'info_dict': { | |
464 | 'id': '1736242', | |
465 | 'ext': 'mp4', | |
466 | 'title': 'ムン大統領が対日批判を強化“現金化”効果は?(テレビ朝日系(ANN)) - Yahoo!ニュース', | |
467 | 'description': '韓国の元徴用工らを巡る裁判の原告が弁護士が差し押さえた三菱重工業の資産を売却して - Yahoo!ニュース(テレビ朝日系(ANN))', | |
468 | 'thumbnail': r're:^https?://.*\.[a-zA-Z\d]{3,4}$', | |
469 | }, | |
470 | 'params': { | |
471 | 'skip_download': True, | |
472 | }, | |
473 | }, { | |
474 | # geo restricted | |
475 | 'url': 'https://headlines.yahoo.co.jp/hl?a=20190721-00000001-oxv-l04', | |
476 | 'only_matching': True, | |
477 | }, { | |
478 | 'url': 'https://headlines.yahoo.co.jp/videonews/', | |
479 | 'only_matching': True, | |
480 | }, { | |
481 | 'url': 'https://news.yahoo.co.jp', | |
482 | 'only_matching': True, | |
483 | }, { | |
484 | 'url': 'https://news.yahoo.co.jp/byline/hashimotojunji/20190628-00131977/', | |
485 | 'only_matching': True, | |
486 | }, { | |
487 | 'url': 'https://news.yahoo.co.jp/feature/1356', | |
488 | 'only_matching': True | |
489 | }] | |
490 | ||
491 | def _extract_formats(self, json_data, content_id): | |
492 | formats = [] | |
493 | ||
494 | video_data = try_get( | |
495 | json_data, | |
496 | lambda x: x['ResultSet']['Result'][0]['VideoUrlSet']['VideoUrl'], | |
497 | list) | |
498 | for vid in video_data or []: | |
499 | delivery = vid.get('delivery') | |
500 | url = url_or_none(vid.get('Url')) | |
501 | if not delivery or not url: | |
502 | continue | |
503 | elif delivery == 'hls': | |
504 | formats.extend( | |
505 | self._extract_m3u8_formats( | |
506 | url, content_id, 'mp4', 'm3u8_native', | |
507 | m3u8_id='hls', fatal=False)) | |
508 | else: | |
509 | formats.append({ | |
510 | 'url': url, | |
511 | 'format_id': 'http-%s' % compat_str(vid.get('bitrate', '')), | |
512 | 'height': int_or_none(vid.get('height')), | |
513 | 'width': int_or_none(vid.get('width')), | |
514 | 'tbr': int_or_none(vid.get('bitrate')), | |
515 | }) | |
516 | self._remove_duplicate_formats(formats) | |
517 | self._sort_formats(formats) | |
518 | ||
519 | return formats | |
520 | ||
521 | def _real_extract(self, url): | |
5ad28e7f | 522 | mobj = self._match_valid_url(url) |
608b8a43 K |
523 | host = mobj.group('host') |
524 | display_id = mobj.group('id') or host | |
525 | ||
526 | webpage = self._download_webpage(url, display_id) | |
527 | ||
528 | title = self._html_search_meta( | |
529 | ['og:title', 'twitter:title'], webpage, 'title', default=None | |
04f3fd2c | 530 | ) or self._html_extract_title(webpage) |
608b8a43 K |
531 | |
532 | if display_id == host: | |
533 | # Headline page (w/ multiple BC playlists) ('news.yahoo.co.jp', 'headlines.yahoo.co.jp/videonews/', ...) | |
534 | stream_plists = re.findall(r'plist=(\d+)', webpage) or re.findall(r'plist["\']:\s*["\']([^"\']+)', webpage) | |
535 | entries = [ | |
536 | self.url_result( | |
537 | smuggle_url( | |
538 | 'http://players.brightcove.net/5690807595001/HyZNerRl7_default/index.html?playlistId=%s' % plist_id, | |
539 | {'geo_countries': ['JP']}), | |
540 | ie='BrightcoveNew', video_id=plist_id) | |
541 | for plist_id in stream_plists] | |
542 | return self.playlist_result(entries, playlist_title=title) | |
543 | ||
544 | # Article page | |
545 | description = self._html_search_meta( | |
546 | ['og:description', 'description', 'twitter:description'], | |
547 | webpage, 'description', default=None) | |
548 | thumbnail = self._og_search_thumbnail( | |
549 | webpage, default=None) or self._html_search_meta( | |
550 | 'twitter:image', webpage, 'thumbnail', default=None) | |
551 | space_id = self._search_regex([ | |
552 | r'<script[^>]+class=["\']yvpub-player["\'][^>]+spaceid=([^&"\']+)', | |
553 | r'YAHOO\.JP\.srch\.\w+link\.onLoad[^;]+spaceID["\' ]*:["\' ]+([^"\']+)', | |
554 | r'<!--\s+SpaceID=(\d+)' | |
555 | ], webpage, 'spaceid') | |
556 | ||
557 | content_id = self._search_regex( | |
558 | r'<script[^>]+class=["\']yvpub-player["\'][^>]+contentid=(?P<contentid>[^&"\']+)', | |
559 | webpage, 'contentid', group='contentid') | |
560 | ||
561 | json_data = self._download_json( | |
562 | 'https://feapi-yvpub.yahooapis.jp/v1/content/%s' % content_id, | |
563 | content_id, | |
564 | query={ | |
565 | 'appid': 'dj0zaiZpPVZMTVFJR0FwZWpiMyZzPWNvbnN1bWVyc2VjcmV0Jng9YjU-', | |
566 | 'output': 'json', | |
567 | 'space_id': space_id, | |
568 | 'domain': host, | |
569 | 'ak': hashlib.md5('_'.join((space_id, host)).encode()).hexdigest(), | |
570 | 'device_type': '1100', | |
571 | }) | |
572 | formats = self._extract_formats(json_data, content_id) | |
573 | ||
574 | return { | |
575 | 'id': content_id, | |
576 | 'title': title, | |
577 | 'description': description, | |
578 | 'thumbnail': thumbnail, | |
579 | 'formats': formats, | |
580 | } |