]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/nowness.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / nowness.py
CommitLineData
15d50aca
S
1from .brightcove import (
2 BrightcoveLegacyIE,
3 BrightcoveNewIE,
4)
066f6a06 5from .common import InfoExtractor
3d2623a8 6from ..networking import Request
7from ..utils import ExtractorError
c23c3d7d 8
066f6a06 9
c23c3d7d 10class NownessBaseIE(InfoExtractor):
82c18e2a 11 def _extract_url_result(self, post):
c23c3d7d 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(
add96eb9 19 f'http://www.nowness.com/iframe?id={video_id}', video_id,
c23c3d7d 20 note='Downloading player JavaScript',
82c18e2a 21 errnote='Unable to download player JavaScript')
4fcaa4f4 22 bc_url = BrightcoveLegacyIE._extract_brightcove_url(player_code)
15d50aca
S
23 if bc_url:
24 return self.url_result(bc_url, BrightcoveLegacyIE.ie_key())
f631b557 25 bc_url = BrightcoveNewIE._extract_url(self, player_code)
15d50aca
S
26 if bc_url:
27 return self.url_result(bc_url, BrightcoveNewIE.ie_key())
28 raise ExtractorError('Could not find player definition')
c23c3d7d 29 elif source == 'vimeo':
add96eb9 30 return self.url_result(f'http://vimeo.com/{video_id}', 'Vimeo')
c23c3d7d 31 elif source == 'youtube':
32 return self.url_result(video_id, 'Youtube')
33 elif source == 'cinematique':
7a5c1cfe 34 # yt-dlp currently doesn't support cinematique
f43c1631 35 # return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
36 pass
066f6a06 37
82c18e2a 38 def _api_request(self, url, request_path):
f95c5e12 39 display_id = self._match_id(url)
3d2623a8 40 request = Request(
82c18e2a
S
41 'http://api.nowness.com/api/' + request_path % display_id,
42 headers={
43 'X-Nowness-Language': 'zh-cn' if 'cn.nowness.com' in url else 'en-us',
44 })
45 return display_id, self._download_json(request, display_id)
f33f32f1 46
a91cf277 47
c23c3d7d 48class NownessIE(NownessBaseIE):
49 IE_NAME = 'nowness'
f33f32f1 50 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
82c18e2a
S
51 _TESTS = [{
52 'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation',
53 'md5': '068bc0202558c2e391924cb8cc470676',
54 'info_dict': {
55 'id': '2520295746001',
56 'ext': 'mp4',
57 'title': 'Candor: The Art of Gesticulation',
58 'description': 'Candor: The Art of Gesticulation',
ec85ded8 59 'thumbnail': r're:^https?://.*\.jpg',
3aac9b2f 60 'timestamp': 1446745676,
61 'upload_date': '20151105',
62 'uploader_id': '2385340575001',
c2467735 63 },
3aac9b2f 64 'add_ie': ['BrightcoveNew'],
82c18e2a
S
65 }, {
66 'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr',
67 'md5': 'e79cf125e387216f86b2e0a5b5c63aa3',
68 'info_dict': {
69 'id': '3716354522001',
70 'ext': 'mp4',
71 'title': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
72 'description': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
ec85ded8 73 'thumbnail': r're:^https?://.*\.jpg',
3aac9b2f 74 'timestamp': 1407315371,
75 'upload_date': '20140806',
76 'uploader_id': '2385340575001',
c2467735 77 },
3aac9b2f 78 'add_ie': ['BrightcoveNew'],
c2467735
S
79 }, {
80 # vimeo
81 'url': 'https://www.nowness.com/series/nowness-picks/jean-luc-godard-supercut',
82 'md5': '9a5a6a8edf806407e411296ab6bc2a49',
83 'info_dict': {
84 'id': '130020913',
85 'ext': 'mp4',
86 'title': 'Bleu, Blanc, Rouge - A Godard Supercut',
87 'description': 'md5:f0ea5f1857dffca02dbd37875d742cec',
ec85ded8 88 'thumbnail': r're:^https?://.*\.jpg',
c2467735
S
89 'upload_date': '20150607',
90 'uploader': 'Cinema Sem Lei',
91 'uploader_id': 'cinemasemlei',
92 },
3aac9b2f 93 'add_ie': ['Vimeo'],
82c18e2a 94 }]
066f6a06
PH
95
96 def _real_extract(self, url):
82c18e2a
S
97 _, post = self._api_request(url, 'post/getBySlug/%s')
98 return self._extract_url_result(post)
c23c3d7d 99
100
101class NownessPlaylistIE(NownessBaseIE):
102 IE_NAME = 'nowness:playlist'
f33f32f1 103 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)'
c23c3d7d 104 _TEST = {
105 'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues',
82c18e2a 106 'info_dict': {
c23c3d7d 107 'id': '3286',
108 },
109 'playlist_mincount': 8,
110 }
111
112 def _real_extract(self, url):
82c18e2a
S
113 playlist_id, playlist = self._api_request(url, 'post?PlaylistId=%s')
114 entries = [self._extract_url_result(item) for item in playlist['items']]
c23c3d7d 115 return self.playlist_result(entries, playlist_id)
066f6a06 116
066f6a06 117
82c18e2a
S
118class NownessSeriesIE(NownessBaseIE):
119 IE_NAME = 'nowness:series'
f33f32f1 120 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
c23c3d7d 121 _TEST = {
122 'url': 'https://www.nowness.com/series/60-seconds',
82c18e2a 123 'info_dict': {
c23c3d7d 124 'id': '60',
82c18e2a
S
125 'title': '60 Seconds',
126 'description': 'One-minute wisdom in a new NOWNESS series',
c23c3d7d 127 },
128 'playlist_mincount': 4,
129 }
130
131 def _real_extract(self, url):
82c18e2a
S
132 display_id, series = self._api_request(url, 'series/getBySlug/%s')
133 entries = [self._extract_url_result(post) for post in series['posts']]
134 series_title = None
135 series_description = None
136 translations = series.get('translations', [])
137 if translations:
138 series_title = translations[0].get('title') or translations[0]['seoTitle']
139 series_description = translations[0].get('seoDescription')
140 return self.playlist_result(
add96eb9 141 entries, str(series['id']), series_title, series_description)