]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nowness.py
[extractor/adobepass] Handle `Charter_Direct` MSO as `Spectrum` (#6824)
[yt-dlp.git] / yt_dlp / extractor / nowness.py
1 from .brightcove import (
2 BrightcoveLegacyIE,
3 BrightcoveNewIE,
4 )
5 from .common import InfoExtractor
6 from ..compat import compat_str
7 from ..utils import (
8 ExtractorError,
9 sanitized_Request,
10 )
11
12
13 class NownessBaseIE(InfoExtractor):
14 def _extract_url_result(self, post):
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',
24 errnote='Unable to download player JavaScript')
25 bc_url = BrightcoveLegacyIE._extract_brightcove_url(player_code)
26 if bc_url:
27 return self.url_result(bc_url, BrightcoveLegacyIE.ie_key())
28 bc_url = BrightcoveNewIE._extract_url(self, player_code)
29 if bc_url:
30 return self.url_result(bc_url, BrightcoveNewIE.ie_key())
31 raise ExtractorError('Could not find player definition')
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':
37 # yt-dlp currently doesn't support cinematique
38 # return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
39 pass
40
41 def _api_request(self, url, request_path):
42 display_id = self._match_id(url)
43 request = sanitized_Request(
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)
49
50
51 class NownessIE(NownessBaseIE):
52 IE_NAME = 'nowness'
53 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
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',
62 'thumbnail': r're:^https?://.*\.jpg',
63 'timestamp': 1446745676,
64 'upload_date': '20151105',
65 'uploader_id': '2385340575001',
66 },
67 'add_ie': ['BrightcoveNew'],
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',
76 'thumbnail': r're:^https?://.*\.jpg',
77 'timestamp': 1407315371,
78 'upload_date': '20140806',
79 'uploader_id': '2385340575001',
80 },
81 'add_ie': ['BrightcoveNew'],
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',
91 'thumbnail': r're:^https?://.*\.jpg',
92 'upload_date': '20150607',
93 'uploader': 'Cinema Sem Lei',
94 'uploader_id': 'cinemasemlei',
95 },
96 'add_ie': ['Vimeo'],
97 }]
98
99 def _real_extract(self, url):
100 _, post = self._api_request(url, 'post/getBySlug/%s')
101 return self._extract_url_result(post)
102
103
104 class NownessPlaylistIE(NownessBaseIE):
105 IE_NAME = 'nowness:playlist'
106 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)'
107 _TEST = {
108 'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues',
109 'info_dict': {
110 'id': '3286',
111 },
112 'playlist_mincount': 8,
113 }
114
115 def _real_extract(self, url):
116 playlist_id, playlist = self._api_request(url, 'post?PlaylistId=%s')
117 entries = [self._extract_url_result(item) for item in playlist['items']]
118 return self.playlist_result(entries, playlist_id)
119
120
121 class NownessSeriesIE(NownessBaseIE):
122 IE_NAME = 'nowness:series'
123 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
124 _TEST = {
125 'url': 'https://www.nowness.com/series/60-seconds',
126 'info_dict': {
127 'id': '60',
128 'title': '60 Seconds',
129 'description': 'One-minute wisdom in a new NOWNESS series',
130 },
131 'playlist_mincount': 4,
132 }
133
134 def _real_extract(self, url):
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)