]>
Commit | Line | Data |
---|---|---|
a91cf277 | 1 | # encoding: utf-8 |
066f6a06 PH |
2 | from __future__ import unicode_literals |
3 | ||
066f6a06 PH |
4 | from .brightcove import BrightcoveIE |
5 | from .common import InfoExtractor | |
e3a6576f | 6 | from ..utils import ExtractorError |
c23c3d7d | 7 | from ..compat import compat_urllib_request |
8 | ||
066f6a06 | 9 | |
c23c3d7d | 10 | class NownessBaseIE(InfoExtractor): |
11 | def extract_url_result(self, post): | |
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( | |
19 | 'http://www.nowness.com/iframe?id=%s' % video_id, video_id, | |
20 | note='Downloading player JavaScript', | |
21 | errnote='Player download failed') | |
22 | bc_url = BrightcoveIE._extract_brightcove_url(player_code) | |
23 | if bc_url is None: | |
24 | raise ExtractorError('Could not find player definition') | |
25 | return self.url_result(bc_url, 'Brightcove') | |
26 | elif source == 'vimeo': | |
27 | return self.url_result('http://vimeo.com/%s' % video_id, 'Vimeo') | |
28 | elif source == 'youtube': | |
29 | return self.url_result(video_id, 'Youtube') | |
30 | elif source == 'cinematique': | |
31 | return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique') | |
066f6a06 | 32 | |
a91cf277 | 33 | |
c23c3d7d | 34 | class NownessIE(NownessBaseIE): |
35 | IE_NAME = 'nowness' | |
75b399f4 | 36 | _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(story|series/[^/]+)/(?P<id>[0-9a-z-]+)' |
a91cf277 S |
37 | _TESTS = [ |
38 | { | |
c23c3d7d | 39 | 'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation', |
a91cf277 S |
40 | 'md5': '068bc0202558c2e391924cb8cc470676', |
41 | 'info_dict': { | |
42 | 'id': '2520295746001', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'Candor: The Art of Gesticulation', | |
45 | 'description': 'Candor: The Art of Gesticulation', | |
46 | 'thumbnail': 're:^https?://.*\.jpg', | |
47 | 'uploader': 'Nowness', | |
48 | } | |
49 | }, | |
50 | { | |
c23c3d7d | 51 | 'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr', |
a91cf277 S |
52 | 'md5': 'e79cf125e387216f86b2e0a5b5c63aa3', |
53 | 'info_dict': { | |
54 | 'id': '3716354522001', | |
55 | 'ext': 'mp4', | |
56 | 'title': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR', | |
57 | 'description': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR', | |
58 | 'thumbnail': 're:^https?://.*\.jpg', | |
59 | 'uploader': 'Nowness', | |
60 | } | |
61 | }, | |
62 | ] | |
066f6a06 PH |
63 | |
64 | def _real_extract(self, url): | |
c23c3d7d | 65 | display_id = self._match_id(url) |
66 | ||
67 | lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us' | |
68 | request = compat_urllib_request.Request('http://api.nowness.com/api/post/getBySlug/%s' % display_id, headers={ | |
69 | 'X-Nowness-Language': lang, | |
70 | }) | |
71 | post = self._download_json(request, display_id) | |
72 | return self.extract_url_result(post) | |
73 | ||
74 | ||
75 | class NownessPlaylistIE(NownessBaseIE): | |
76 | IE_NAME = 'nowness:playlist' | |
77 | _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)/[0-9a-z-]+' | |
78 | _TEST = { | |
79 | 'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues', | |
80 | 'info_dict': | |
81 | { | |
82 | 'id': '3286', | |
83 | }, | |
84 | 'playlist_mincount': 8, | |
85 | } | |
86 | ||
87 | def _real_extract(self, url): | |
88 | playlist_id = self._match_id(url) | |
066f6a06 | 89 | |
c23c3d7d | 90 | lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us' |
91 | request = compat_urllib_request.Request('http://api.nowness.com/api/post?PlaylistId=%s' % playlist_id, headers={ | |
92 | 'X-Nowness-Language': lang, | |
93 | }) | |
94 | playlist = self._download_json(request, playlist_id) | |
95 | entries = [self.extract_url_result(item) for item in playlist['items']] | |
96 | return self.playlist_result(entries, playlist_id) | |
066f6a06 | 97 | |
066f6a06 | 98 | |
c23c3d7d | 99 | class NownessSerieIE(NownessBaseIE): |
100 | IE_NAME = 'nowness:serie' | |
101 | _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[0-9a-z-]+)' | |
102 | _TEST = { | |
103 | 'url': 'https://www.nowness.com/series/60-seconds', | |
104 | 'info_dict': | |
105 | { | |
106 | 'id': '60', | |
107 | }, | |
108 | 'playlist_mincount': 4, | |
109 | } | |
110 | ||
111 | def _real_extract(self, url): | |
112 | display_id = self._match_id(url) | |
113 | ||
114 | lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us' | |
75b399f4 | 115 | request = compat_urllib_request.Request('http://api.nowness.com/api/series/getBySlug/%s' % display_id, headers={ |
c23c3d7d | 116 | 'X-Nowness-Language': lang, |
117 | }) | |
118 | serie = self._download_json(request, display_id) | |
119 | serie_id = str(serie['id']) | |
120 | entries = [self.extract_url_result(post) for post in serie['posts']] | |
121 | return self.playlist_result(entries, serie_id) |