| 
									
										
										
										
											2016-10-02 13:39:18 +02:00
										 |  |  | # coding: utf-8 | 
					
						
							| 
									
										
										
										
											2014-01-23 00:12:47 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-18 22:05:56 +06:00
										 |  |  | from .brightcove import ( | 
					
						
							|  |  |  |     BrightcoveLegacyIE, | 
					
						
							|  |  |  |     BrightcoveNewIE, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2014-01-23 00:12:47 +01:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  | from ..compat import compat_str | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							|  |  |  |     ExtractorError, | 
					
						
							|  |  |  |     sanitized_Request, | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 00:12:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  | class NownessBaseIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |     def _extract_url_result(self, post): | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |         if post['type'] == 'video': | 
					
						
							|  |  |  |             for media in post['media']: | 
					
						
							|  |  |  |                 if media['type'] == 'video': | 
					
						
							|  |  |  |                     video_id = media['content'] | 
					
						
							|  |  |  |                     source = media['source'] | 
					
						
							|  |  |  |                     if source == 'brightcove': | 
					
						
							|  |  |  |                         player_code = self._download_webpage( | 
					
						
							|  |  |  |                             'http://www.nowness.com/iframe?id=%s' % video_id, video_id, | 
					
						
							|  |  |  |                             note='Downloading player JavaScript', | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |                             errnote='Unable to download player JavaScript') | 
					
						
							| 
									
										
										
										
											2015-11-14 05:54:16 +06:00
										 |  |  |                         bc_url = BrightcoveLegacyIE._extract_brightcove_url(player_code) | 
					
						
							| 
									
										
										
										
											2015-12-18 22:05:56 +06:00
										 |  |  |                         if bc_url: | 
					
						
							|  |  |  |                             return self.url_result(bc_url, BrightcoveLegacyIE.ie_key()) | 
					
						
							| 
									
										
										
										
											2017-04-18 21:46:25 +07:00
										 |  |  |                         bc_url = BrightcoveNewIE._extract_url(self, player_code) | 
					
						
							| 
									
										
										
										
											2015-12-18 22:05:56 +06:00
										 |  |  |                         if bc_url: | 
					
						
							|  |  |  |                             return self.url_result(bc_url, BrightcoveNewIE.ie_key()) | 
					
						
							|  |  |  |                         raise ExtractorError('Could not find player definition') | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |                     elif source == 'vimeo': | 
					
						
							|  |  |  |                         return self.url_result('http://vimeo.com/%s' % video_id, 'Vimeo') | 
					
						
							|  |  |  |                     elif source == 'youtube': | 
					
						
							|  |  |  |                         return self.url_result(video_id, 'Youtube') | 
					
						
							|  |  |  |                     elif source == 'cinematique': | 
					
						
							| 
									
										
										
										
											2015-09-05 21:18:21 +01:00
										 |  |  |                         # youtube-dl currently doesn't support cinematique | 
					
						
							|  |  |  |                         # return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique') | 
					
						
							|  |  |  |                         pass | 
					
						
							| 
									
										
										
										
											2014-01-23 00:12:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |     def _api_request(self, url, request_path): | 
					
						
							| 
									
										
										
										
											2015-09-05 20:51:27 +01:00
										 |  |  |         display_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |         request = sanitized_Request( | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |             'http://api.nowness.com/api/' + request_path % display_id, | 
					
						
							|  |  |  |             headers={ | 
					
						
							|  |  |  |                 'X-Nowness-Language': 'zh-cn' if 'cn.nowness.com' in url else 'en-us', | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         return display_id, self._download_json(request, display_id) | 
					
						
							| 
									
										
										
										
											2015-09-05 20:32:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-08 18:43:28 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  | class NownessIE(NownessBaseIE): | 
					
						
							|  |  |  |     IE_NAME = 'nowness' | 
					
						
							| 
									
										
										
										
											2015-09-05 20:32:31 +01:00
										 |  |  |     _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])' | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation', | 
					
						
							|  |  |  |         'md5': '068bc0202558c2e391924cb8cc470676', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '2520295746001', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Candor: The Art of Gesticulation', | 
					
						
							|  |  |  |             'description': 'Candor: The Art of Gesticulation', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2016-04-02 18:56:31 +01:00
										 |  |  |             'timestamp': 1446745676, | 
					
						
							|  |  |  |             'upload_date': '20151105', | 
					
						
							|  |  |  |             'uploader_id': '2385340575001', | 
					
						
							| 
									
										
										
										
											2015-09-13 19:27:22 +06:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-04-02 18:56:31 +01:00
										 |  |  |         'add_ie': ['BrightcoveNew'], | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr', | 
					
						
							|  |  |  |         'md5': 'e79cf125e387216f86b2e0a5b5c63aa3', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '3716354522001', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR', | 
					
						
							|  |  |  |             'description': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2016-04-02 18:56:31 +01:00
										 |  |  |             'timestamp': 1407315371, | 
					
						
							|  |  |  |             'upload_date': '20140806', | 
					
						
							|  |  |  |             'uploader_id': '2385340575001', | 
					
						
							| 
									
										
										
										
											2015-09-13 19:27:22 +06:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-04-02 18:56:31 +01:00
										 |  |  |         'add_ie': ['BrightcoveNew'], | 
					
						
							| 
									
										
										
										
											2015-09-13 19:27:22 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         # vimeo | 
					
						
							|  |  |  |         'url': 'https://www.nowness.com/series/nowness-picks/jean-luc-godard-supercut', | 
					
						
							|  |  |  |         'md5': '9a5a6a8edf806407e411296ab6bc2a49', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '130020913', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Bleu, Blanc, Rouge - A Godard Supercut', | 
					
						
							|  |  |  |             'description': 'md5:f0ea5f1857dffca02dbd37875d742cec', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2015-09-13 19:27:22 +06:00
										 |  |  |             'upload_date': '20150607', | 
					
						
							|  |  |  |             'uploader': 'Cinema Sem Lei', | 
					
						
							|  |  |  |             'uploader_id': 'cinemasemlei', | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-04-02 18:56:31 +01:00
										 |  |  |         'add_ie': ['Vimeo'], | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |     }] | 
					
						
							| 
									
										
										
										
											2014-01-23 00:12:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |         _, post = self._api_request(url, 'post/getBySlug/%s') | 
					
						
							|  |  |  |         return self._extract_url_result(post) | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NownessPlaylistIE(NownessBaseIE): | 
					
						
							|  |  |  |     IE_NAME = 'nowness:playlist' | 
					
						
							| 
									
										
										
										
											2015-09-05 20:32:31 +01:00
										 |  |  |     _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)' | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |     _TEST = { | 
					
						
							|  |  |  |         'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues', | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |             'id': '3286', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         'playlist_mincount': 8, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |         playlist_id, playlist = self._api_request(url, 'post?PlaylistId=%s') | 
					
						
							|  |  |  |         entries = [self._extract_url_result(item) for item in playlist['items']] | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |         return self.playlist_result(entries, playlist_id) | 
					
						
							| 
									
										
										
										
											2014-01-23 00:12:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  | class NownessSeriesIE(NownessBaseIE): | 
					
						
							|  |  |  |     IE_NAME = 'nowness:series' | 
					
						
							| 
									
										
										
										
											2015-09-05 20:32:31 +01:00
										 |  |  |     _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])' | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |     _TEST = { | 
					
						
							|  |  |  |         'url': 'https://www.nowness.com/series/60-seconds', | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |             'id': '60', | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |             'title': '60 Seconds', | 
					
						
							|  |  |  |             'description': 'One-minute wisdom in a new NOWNESS series', | 
					
						
							| 
									
										
										
										
											2015-09-05 16:38:05 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |         'playlist_mincount': 4, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-09-13 19:18:57 +06:00
										 |  |  |         display_id, series = self._api_request(url, 'series/getBySlug/%s') | 
					
						
							|  |  |  |         entries = [self._extract_url_result(post) for post in series['posts']] | 
					
						
							|  |  |  |         series_title = None | 
					
						
							|  |  |  |         series_description = None | 
					
						
							|  |  |  |         translations = series.get('translations', []) | 
					
						
							|  |  |  |         if translations: | 
					
						
							|  |  |  |             series_title = translations[0].get('title') or translations[0]['seoTitle'] | 
					
						
							|  |  |  |             series_description = translations[0].get('seoDescription') | 
					
						
							|  |  |  |         return self.playlist_result( | 
					
						
							|  |  |  |             entries, compat_str(series['id']), series_title, series_description) |