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