2014-08-08 13:43:28 +02:00
|
|
|
# encoding: utf-8
|
2014-01-23 00:12:47 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from .brightcove import BrightcoveIE
|
|
|
|
from .common import InfoExtractor
|
2014-05-19 14:05:18 +02:00
|
|
|
from ..utils import ExtractorError
|
2015-09-05 17:38:05 +02:00
|
|
|
from ..compat import compat_urllib_request
|
|
|
|
|
2014-01-23 00:12:47 +01:00
|
|
|
|
2015-09-05 17:38:05 +02:00
|
|
|
class NownessBaseIE(InfoExtractor):
|
|
|
|
def extract_url_result(self, post):
|
|
|
|
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',
|
|
|
|
errnote='Player download failed')
|
|
|
|
bc_url = BrightcoveIE._extract_brightcove_url(player_code)
|
|
|
|
if bc_url is None:
|
|
|
|
raise ExtractorError('Could not find player definition')
|
|
|
|
return self.url_result(bc_url, 'Brightcove')
|
|
|
|
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':
|
|
|
|
return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
|
2014-01-23 00:12:47 +01:00
|
|
|
|
2015-09-05 21:32:31 +02:00
|
|
|
def api_request(self, url, request_url):
|
|
|
|
id = self._match_id(url)
|
|
|
|
|
|
|
|
lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us'
|
|
|
|
request = compat_urllib_request.Request(request_url % id, headers={
|
|
|
|
'X-Nowness-Language': lang,
|
|
|
|
})
|
|
|
|
json_data = self._download_json(request, id)
|
|
|
|
return id, json_data
|
|
|
|
|
2014-08-08 13:43:28 +02:00
|
|
|
|
2015-09-05 17:38:05 +02:00
|
|
|
class NownessIE(NownessBaseIE):
|
|
|
|
IE_NAME = 'nowness'
|
2015-09-05 21:32:31 +02:00
|
|
|
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
|
2014-08-08 13:43:28 +02:00
|
|
|
_TESTS = [
|
|
|
|
{
|
2015-09-05 17:38:05 +02:00
|
|
|
'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation',
|
2014-08-08 13:43:28 +02:00
|
|
|
'md5': '068bc0202558c2e391924cb8cc470676',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '2520295746001',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Candor: The Art of Gesticulation',
|
|
|
|
'description': 'Candor: The Art of Gesticulation',
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
|
|
|
'uploader': 'Nowness',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2015-09-05 17:38:05 +02:00
|
|
|
'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr',
|
2014-08-08 13:43:28 +02:00
|
|
|
'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',
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
|
|
|
'uploader': 'Nowness',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
2014-01-23 00:12:47 +01:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2015-09-05 21:32:31 +02:00
|
|
|
display_id, post = self.api_request(url, 'http://api.nowness.com/api/post/getBySlug/%s')
|
2015-09-05 17:38:05 +02:00
|
|
|
return self.extract_url_result(post)
|
|
|
|
|
|
|
|
|
|
|
|
class NownessPlaylistIE(NownessBaseIE):
|
|
|
|
IE_NAME = 'nowness:playlist'
|
2015-09-05 21:32:31 +02:00
|
|
|
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)'
|
2015-09-05 17:38:05 +02:00
|
|
|
_TEST = {
|
|
|
|
'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues',
|
|
|
|
'info_dict':
|
|
|
|
{
|
|
|
|
'id': '3286',
|
|
|
|
},
|
|
|
|
'playlist_mincount': 8,
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2015-09-05 21:32:31 +02:00
|
|
|
playlist_id, playlist = self.api_request(url, 'http://api.nowness.com/api/post?PlaylistId=%s')
|
2015-09-05 17:38:05 +02:00
|
|
|
entries = [self.extract_url_result(item) for item in playlist['items']]
|
|
|
|
return self.playlist_result(entries, playlist_id)
|
2014-01-23 00:12:47 +01:00
|
|
|
|
|
|
|
|
2015-09-05 17:38:05 +02:00
|
|
|
class NownessSerieIE(NownessBaseIE):
|
|
|
|
IE_NAME = 'nowness:serie'
|
2015-09-05 21:32:31 +02:00
|
|
|
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
|
2015-09-05 17:38:05 +02:00
|
|
|
_TEST = {
|
|
|
|
'url': 'https://www.nowness.com/series/60-seconds',
|
|
|
|
'info_dict':
|
|
|
|
{
|
|
|
|
'id': '60',
|
|
|
|
},
|
|
|
|
'playlist_mincount': 4,
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2015-09-05 21:32:31 +02:00
|
|
|
display_id, serie = self.api_request(url, 'http://api.nowness.com/api/series/getBySlug/%s')
|
2015-09-05 17:38:05 +02:00
|
|
|
serie_id = str(serie['id'])
|
|
|
|
entries = [self.extract_url_result(post) for post in serie['posts']]
|
|
|
|
return self.playlist_result(entries, serie_id)
|