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