]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/nowness.py
Merge branch 'nowness' of https://github.com/remitamine/youtube-dl into remitamine...
[yt-dlp.git] / youtube_dl / extractor / nowness.py
CommitLineData
a91cf277 1# encoding: utf-8
066f6a06
PH
2from __future__ import unicode_literals
3
066f6a06
PH
4from .brightcove import BrightcoveIE
5from .common import InfoExtractor
e3a6576f 6from ..utils import ExtractorError
c23c3d7d 7from ..compat import compat_urllib_request
8
066f6a06 9
c23c3d7d 10class 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':
f43c1631 31 # youtube-dl currently doesn't support cinematique
32 # return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
33 pass
066f6a06 34
673bf566 35 def api_request(self, url, request_path):
f95c5e12 36 display_id = self._match_id(url)
f33f32f1 37
38 lang = 'zh-cn' if 'cn.nowness.com' in url else 'en-us'
673bf566 39 request = compat_urllib_request.Request('http://api.nowness.com/api/' + request_path % display_id, headers={
f33f32f1 40 'X-Nowness-Language': lang,
41 })
f95c5e12 42 json_data = self._download_json(request, display_id)
43 return display_id, json_data
f33f32f1 44
a91cf277 45
c23c3d7d 46class NownessIE(NownessBaseIE):
47 IE_NAME = 'nowness'
f33f32f1 48 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
a91cf277
S
49 _TESTS = [
50 {
c23c3d7d 51 'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation',
a91cf277
S
52 'md5': '068bc0202558c2e391924cb8cc470676',
53 'info_dict': {
54 'id': '2520295746001',
55 'ext': 'mp4',
56 'title': 'Candor: The Art of Gesticulation',
57 'description': 'Candor: The Art of Gesticulation',
58 'thumbnail': 're:^https?://.*\.jpg',
59 'uploader': 'Nowness',
60 }
61 },
62 {
c23c3d7d 63 'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr',
a91cf277
S
64 'md5': 'e79cf125e387216f86b2e0a5b5c63aa3',
65 'info_dict': {
66 'id': '3716354522001',
67 'ext': 'mp4',
68 'title': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
69 'description': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
70 'thumbnail': 're:^https?://.*\.jpg',
71 'uploader': 'Nowness',
72 }
73 },
74 ]
066f6a06
PH
75
76 def _real_extract(self, url):
673bf566 77 display_id, post = self.api_request(url, 'post/getBySlug/%s')
c23c3d7d 78 return self.extract_url_result(post)
79
80
81class NownessPlaylistIE(NownessBaseIE):
82 IE_NAME = 'nowness:playlist'
f33f32f1 83 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)'
c23c3d7d 84 _TEST = {
85 'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues',
86 'info_dict':
87 {
88 'id': '3286',
89 },
90 'playlist_mincount': 8,
91 }
92
93 def _real_extract(self, url):
673bf566 94 playlist_id, playlist = self.api_request(url, 'post?PlaylistId=%s')
c23c3d7d 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 99class NownessSerieIE(NownessBaseIE):
100 IE_NAME = 'nowness:serie'
f33f32f1 101 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
c23c3d7d 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):
673bf566 112 display_id, serie = self.api_request(url, 'series/getBySlug/%s')
c23c3d7d 113 serie_id = str(serie['id'])
114 entries = [self.extract_url_result(post) for post in serie['posts']]
115 return self.playlist_result(entries, serie_id)