0
0
Fork 0

[nowness] add api abstration function adn extend _VALID_URL regex

main
remitamine 2015-09-05 20:32:31 +01:00
parent 75b399f455
commit f33f32f159
1 changed files with 16 additions and 24 deletions

View File

@ -30,10 +30,20 @@ class NownessBaseIE(InfoExtractor):
elif source == 'cinematique':
return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
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
class NownessIE(NownessBaseIE):
IE_NAME = 'nowness'
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(story|series/[^/]+)/(?P<id>[0-9a-z-]+)'
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
_TESTS = [
{
'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation',
@ -62,19 +72,13 @@ class NownessIE(NownessBaseIE):
]
def _real_extract(self, url):
display_id = self._match_id(url)
lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us'
request = compat_urllib_request.Request('http://api.nowness.com/api/post/getBySlug/%s' % display_id, headers={
'X-Nowness-Language': lang,
})
post = self._download_json(request, display_id)
display_id, post = self.api_request(url, 'http://api.nowness.com/api/post/getBySlug/%s')
return self.extract_url_result(post)
class NownessPlaylistIE(NownessBaseIE):
IE_NAME = 'nowness:playlist'
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)/[0-9a-z-]+'
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)'
_TEST = {
'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues',
'info_dict':
@ -85,20 +89,14 @@ class NownessPlaylistIE(NownessBaseIE):
}
def _real_extract(self, url):
playlist_id = self._match_id(url)
lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us'
request = compat_urllib_request.Request('http://api.nowness.com/api/post?PlaylistId=%s' % playlist_id, headers={
'X-Nowness-Language': lang,
})
playlist = self._download_json(request, playlist_id)
playlist_id, playlist = self.api_request(url, 'http://api.nowness.com/api/post?PlaylistId=%s')
entries = [self.extract_url_result(item) for item in playlist['items']]
return self.playlist_result(entries, playlist_id)
class NownessSerieIE(NownessBaseIE):
IE_NAME = 'nowness:serie'
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[0-9a-z-]+)'
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
_TEST = {
'url': 'https://www.nowness.com/series/60-seconds',
'info_dict':
@ -109,13 +107,7 @@ class NownessSerieIE(NownessBaseIE):
}
def _real_extract(self, url):
display_id = self._match_id(url)
lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us'
request = compat_urllib_request.Request('http://api.nowness.com/api/series/getBySlug/%s' % display_id, headers={
'X-Nowness-Language': lang,
})
serie = self._download_json(request, display_id)
display_id, serie = self.api_request(url, 'http://api.nowness.com/api/series/getBySlug/%s')
serie_id = str(serie['id'])
entries = [self.extract_url_result(post) for post in serie['posts']]
return self.playlist_result(entries, serie_id)