2 from __future__ import unicode_literals
4 from .brightcove import BrightcoveIE
5 from .common import InfoExtractor
6 from ..utils import ExtractorError
7 from ..compat import compat_urllib_request
10 class NownessBaseIE(InfoExtractor):
11 def extract_url_result(self, post):
12 if post['type'] == 'video':
13 for media in post['media']:
14 if media['type'] == 'video':
15 video_id = media['content']
16 source = media['source']
17 if source == 'brightcove':
18 player_code = self._download_webpage(
19 'http://www.nowness.com/iframe?id=%s' % video_id, video_id,
20 note='Downloading player JavaScript',
21 errnote='Player download failed')
22 bc_url = BrightcoveIE._extract_brightcove_url(player_code)
24 raise ExtractorError('Could not find player definition')
25 return self.url_result(bc_url, 'Brightcove')
26 elif source == 'vimeo':
27 return self.url_result('http://vimeo.com/%s' % video_id, 'Vimeo')
28 elif source == 'youtube':
29 return self.url_result(video_id, 'Youtube')
30 elif source == 'cinematique':
31 # youtube-dl currently doesn't support cinematique
32 # return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
35 def api_request(self, url, request_path):
36 display_id = self._match_id(url)
38 lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us'
39 request = compat_urllib_request.Request('http://api.nowness.com/api/' + request_path % display_id, headers={
40 'X-Nowness-Language': lang,
42 json_data = self._download_json(request, display_id)
43 return display_id, json_data
46 class NownessIE(NownessBaseIE):
48 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
51 'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation',
52 'md5': '068bc0202558c2e391924cb8cc470676',
54 'id': '2520295746001',
56 'title': 'Candor: The Art of Gesticulation',
57 'description': 'Candor: The Art of Gesticulation',
58 'thumbnail': 're:^https?://.*\.jpg',
59 'uploader': 'Nowness',
63 'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr',
64 'md5': 'e79cf125e387216f86b2e0a5b5c63aa3',
66 'id': '3716354522001',
68 'title': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
69 'description': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
70 'thumbnail': 're:^https?://.*\.jpg',
71 'uploader': 'Nowness',
76 def _real_extract(self, url):
77 display_id, post = self.api_request(url, 'post/getBySlug/%s')
78 return self.extract_url_result(post)
81 class NownessPlaylistIE(NownessBaseIE):
82 IE_NAME = 'nowness:playlist'
83 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)'
85 'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues',
90 'playlist_mincount': 8,
93 def _real_extract(self, url):
94 playlist_id, playlist = self.api_request(url, 'post?PlaylistId=%s')
95 entries = [self.extract_url_result(item) for item in playlist['items']]
96 return self.playlist_result(entries, playlist_id)
99 class NownessSerieIE(NownessBaseIE):
100 IE_NAME = 'nowness:serie'
101 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
103 'url': 'https://www.nowness.com/series/60-seconds',
108 'playlist_mincount': 4,
111 def _real_extract(self, url):
112 display_id, serie = self.api_request(url, 'series/getBySlug/%s')
113 serie_id = str(serie['id'])
114 entries = [self.extract_url_result(post) for post in serie['posts']]
115 return self.playlist_result(entries, serie_id)