]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nowness.py
   2 from __future__ 
import unicode_literals
 
   4 from .brightcove 
import BrightcoveIE
 
   5 from .common 
import InfoExtractor
 
   6 from ..utils 
import ExtractorError
 
  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 
= BrightcoveIE
._extract
_brightcove
_url
(player_code
) 
  27                             raise ExtractorError('Could not find player definition') 
  28                         return self
.url_result(bc_url
, 'Brightcove') 
  29                     elif source 
== 'vimeo': 
  30                         return self
.url_result('http://vimeo.com/%s' % video_id
, 'Vimeo') 
  31                     elif source 
== 'youtube': 
  32                         return self
.url_result(video_id
, 'Youtube') 
  33                     elif source 
== 'cinematique': 
  34                         # youtube-dl currently doesn't support cinematique 
  35                         # return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique') 
  38     def _api_request(self
, url
, request_path
): 
  39         display_id 
= self
._match
_id
(url
) 
  40         request 
= compat_urllib_request
.Request( 
  41             'http://api.nowness.com/api/' + request_path 
% display_id
, 
  43                 'X-Nowness-Language': 'zh-cn' if 'cn.nowness.com' in url 
else 'en-us', 
  45         return display_id
, self
._download
_json
(request
, display_id
) 
  48 class NownessIE(NownessBaseIE
): 
  50     _VALID_URL 
= r
'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])' 
  52         'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation', 
  53         'md5': '068bc0202558c2e391924cb8cc470676', 
  55             'id': '2520295746001', 
  57             'title': 'Candor: The Art of Gesticulation', 
  58             'description': 'Candor: The Art of Gesticulation', 
  59             'thumbnail': 're:^https?://.*\.jpg', 
  60             'uploader': 'Nowness', 
  63         'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr', 
  64         'md5': 'e79cf125e387216f86b2e0a5b5c63aa3', 
  66             'id': '3716354522001', 
  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', 
  75         'url': 'https://www.nowness.com/series/nowness-picks/jean-luc-godard-supercut', 
  76         'md5': '9a5a6a8edf806407e411296ab6bc2a49', 
  80             'title': 'Bleu, Blanc, Rouge - A Godard Supercut', 
  81             'description': 'md5:f0ea5f1857dffca02dbd37875d742cec', 
  82             'thumbnail': 're:^https?://.*\.jpg', 
  83             'upload_date': '20150607', 
  84             'uploader': 'Cinema Sem Lei', 
  85             'uploader_id': 'cinemasemlei', 
  89     def _real_extract(self
, url
): 
  90         _
, post 
= self
._api
_request
(url
, 'post/getBySlug/%s') 
  91         return self
._extract
_url
_result
(post
) 
  94 class NownessPlaylistIE(NownessBaseIE
): 
  95     IE_NAME 
= 'nowness:playlist' 
  96     _VALID_URL 
= r
'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)' 
  98         'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues', 
 102         'playlist_mincount': 8, 
 105     def _real_extract(self
, url
): 
 106         playlist_id
, playlist 
= self
._api
_request
(url
, 'post?PlaylistId=%s') 
 107         entries 
= [self
._extract
_url
_result
(item
) for item 
in playlist
['items']] 
 108         return self
.playlist_result(entries
, playlist_id
) 
 111 class NownessSeriesIE(NownessBaseIE
): 
 112     IE_NAME 
= 'nowness:series' 
 113     _VALID_URL 
= r
'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])' 
 115         'url': 'https://www.nowness.com/series/60-seconds', 
 118             'title': '60 Seconds', 
 119             'description': 'One-minute wisdom in a new NOWNESS series', 
 121         'playlist_mincount': 4, 
 124     def _real_extract(self
, url
): 
 125         display_id
, series 
= self
._api
_request
(url
, 'series/getBySlug/%s') 
 126         entries 
= [self
._extract
_url
_result
(post
) for post 
in series
['posts']] 
 128         series_description 
= None 
 129         translations 
= series
.get('translations', []) 
 131             series_title 
= translations
[0].get('title') or translations
[0]['seoTitle'] 
 132             series_description 
= translations
[0].get('seoDescription') 
 133         return self
.playlist_result( 
 134             entries
, compat_str(series
['id']), series_title
, series_description
)