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