mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-02 17:22:31 +01:00
[nowness] Simplify
This commit is contained in:
parent
d5d38d16ae
commit
82c18e2a53
@ -408,7 +408,7 @@
|
||||
from .nowness import (
|
||||
NownessIE,
|
||||
NownessPlaylistIE,
|
||||
NownessSerieIE,
|
||||
NownessSeriesIE,
|
||||
)
|
||||
from .nowtv import NowTVIE
|
||||
from .nowvideo import NowVideoIE
|
||||
|
@ -4,11 +4,14 @@
|
||||
from .brightcove import BrightcoveIE
|
||||
from .common import InfoExtractor
|
||||
from ..utils import ExtractorError
|
||||
from ..compat import compat_urllib_request
|
||||
from ..compat import (
|
||||
compat_str,
|
||||
compat_urllib_request,
|
||||
)
|
||||
|
||||
|
||||
class NownessBaseIE(InfoExtractor):
|
||||
def extract_url_result(self, post):
|
||||
def _extract_url_result(self, post):
|
||||
if post['type'] == 'video':
|
||||
for media in post['media']:
|
||||
if media['type'] == 'video':
|
||||
@ -18,7 +21,7 @@ def extract_url_result(self, post):
|
||||
player_code = self._download_webpage(
|
||||
'http://www.nowness.com/iframe?id=%s' % video_id, video_id,
|
||||
note='Downloading player JavaScript',
|
||||
errnote='Player download failed')
|
||||
errnote='Unable to download player JavaScript')
|
||||
bc_url = BrightcoveIE._extract_brightcove_url(player_code)
|
||||
if bc_url is None:
|
||||
raise ExtractorError('Could not find player definition')
|
||||
@ -32,22 +35,20 @@ def extract_url_result(self, post):
|
||||
# return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
|
||||
pass
|
||||
|
||||
def api_request(self, url, request_path):
|
||||
def _api_request(self, url, request_path):
|
||||
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/' + request_path % display_id, headers={
|
||||
'X-Nowness-Language': lang,
|
||||
request = compat_urllib_request.Request(
|
||||
'http://api.nowness.com/api/' + request_path % display_id,
|
||||
headers={
|
||||
'X-Nowness-Language': 'zh-cn' if 'cn.nowness.com' in url else 'en-us',
|
||||
})
|
||||
json_data = self._download_json(request, display_id)
|
||||
return display_id, json_data
|
||||
return display_id, self._download_json(request, display_id)
|
||||
|
||||
|
||||
class NownessIE(NownessBaseIE):
|
||||
IE_NAME = 'nowness'
|
||||
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
|
||||
_TESTS = [
|
||||
{
|
||||
_TESTS = [{
|
||||
'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation',
|
||||
'md5': '068bc0202558c2e391924cb8cc470676',
|
||||
'info_dict': {
|
||||
@ -58,8 +59,7 @@ class NownessIE(NownessBaseIE):
|
||||
'thumbnail': 're:^https?://.*\.jpg',
|
||||
'uploader': 'Nowness',
|
||||
}
|
||||
},
|
||||
{
|
||||
}, {
|
||||
'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr',
|
||||
'md5': 'e79cf125e387216f86b2e0a5b5c63aa3',
|
||||
'info_dict': {
|
||||
@ -70,12 +70,11 @@ class NownessIE(NownessBaseIE):
|
||||
'thumbnail': 're:^https?://.*\.jpg',
|
||||
'uploader': 'Nowness',
|
||||
}
|
||||
},
|
||||
]
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id, post = self.api_request(url, 'post/getBySlug/%s')
|
||||
return self.extract_url_result(post)
|
||||
_, post = self._api_request(url, 'post/getBySlug/%s')
|
||||
return self._extract_url_result(post)
|
||||
|
||||
|
||||
class NownessPlaylistIE(NownessBaseIE):
|
||||
@ -83,33 +82,39 @@ class NownessPlaylistIE(NownessBaseIE):
|
||||
_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':
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '3286',
|
||||
},
|
||||
'playlist_mincount': 8,
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
playlist_id, playlist = self.api_request(url, 'post?PlaylistId=%s')
|
||||
entries = [self.extract_url_result(item) for item in playlist['items']]
|
||||
playlist_id, playlist = self._api_request(url, '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'
|
||||
class NownessSeriesIE(NownessBaseIE):
|
||||
IE_NAME = 'nowness:series'
|
||||
_VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
|
||||
_TEST = {
|
||||
'url': 'https://www.nowness.com/series/60-seconds',
|
||||
'info_dict':
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '60',
|
||||
'title': '60 Seconds',
|
||||
'description': 'One-minute wisdom in a new NOWNESS series',
|
||||
},
|
||||
'playlist_mincount': 4,
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id, serie = self.api_request(url, '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)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user