]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/go90.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_HTTPError
 
  17 class Go90IE(InfoExtractor
): 
  18     _VALID_URL 
= r
'https?://(?:www\.)?go90\.com/(?:videos|embed)/(?P<id>[0-9a-zA-Z]+)' 
  20         'url': 'https://www.go90.com/videos/84BUqjLpf9D', 
  21         'md5': 'efa7670dbbbf21a7b07b360652b24a32', 
  25             'title': 'Daily VICE - Inside The Utah Coalition Against Pornography Convention', 
  26             'description': 'VICE\'s Karley Sciortino meets with activists who discuss the state\'s strong anti-porn stance. Then, VICE Sports explains NFL contracts.', 
  27             'timestamp': 1491868800, 
  28             'upload_date': '20170411', 
  32         'url': 'https://www.go90.com/embed/261MflWkD3N', 
  33         'only_matching': True, 
  37     def _real_extract(self
, url
): 
  38         video_id 
= self
._match
_id
(url
) 
  41             headers 
= self
.geo_verification_headers() 
  43                 'Content-Type': 'application/json; charset=utf-8', 
  45             video_data 
= self
._download
_json
( 
  46                 'https://www.go90.com/api/view/items/' + video_id
, video_id
, 
  47                 headers
=headers
, data
=b
'{"client":"web","device_type":"pc"}') 
  48         except ExtractorError 
as e
: 
  49             if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code 
== 400: 
  50                 message 
= self
._parse
_json
(e
.cause
.read().decode(), None)['error']['message'] 
  51                 if 'region unavailable' in message
: 
  52                     self
.raise_geo_restricted(countries
=['US']) 
  53                 raise ExtractorError(message
, expected
=True) 
  56         if video_data
.get('requires_drm'): 
  57             raise ExtractorError('This video is DRM protected.', expected
=True) 
  58         main_video_asset 
= video_data
['main_video_asset'] 
  60         episode_number 
= int_or_none(video_data
.get('episode_number')) 
  65         for metadata 
in video_data
.get('__children', {}).get('Item', {}).values(): 
  66             if metadata
.get('type') == 'show': 
  67                 series 
= metadata
.get('title') 
  68             elif metadata
.get('type') == 'season': 
  69                 season 
= metadata
.get('title') 
  70                 season_id 
= metadata
.get('id') 
  71                 season_number 
= int_or_none(metadata
.get('season_number')) 
  73         title 
= episode 
= video_data
.get('title') or series
 
  74         if series 
and series 
!= title
: 
  75             title 
= '%s - %s' % (series
, title
) 
  80         for asset 
in video_data
.get('assets'): 
  81             if asset
.get('id') == main_video_asset
: 
  82                 for source 
in asset
.get('sources', []): 
  83                     source_location 
= source
.get('location') 
  84                     if not source_location
: 
  86                     source_type 
= source
.get('type') 
  87                     if source_type 
== 'hls': 
  88                         m3u8_formats 
= self
._extract
_m
3u8_formats
( 
  89                             source_location
, video_id
, 'mp4', 
  90                             'm3u8_native', m3u8_id
='hls', fatal
=False) 
  91                         for f 
in m3u8_formats
: 
  92                             mobj 
= re
.search(r
'/hls-(\d+)-(\d+)K', f
['url']) 
  94                                 height
, tbr 
= mobj
.groups() 
  95                                 height 
= int_or_none(height
) 
  97                                     'height': f
.get('height') or height
, 
  98                                     'width': f
.get('width') or int_or_none(height 
/ 9.0 * 16.0 if height 
else None), 
  99                                     'tbr': f
.get('tbr') or int_or_none(tbr
), 
 101                         formats
.extend(m3u8_formats
) 
 102                     elif source_type 
== 'dash': 
 103                         formats
.extend(self
._extract
_mpd
_formats
( 
 104                             source_location
, video_id
, mpd_id
='dash', fatal
=False)) 
 107                             'format_id': source
.get('name'), 
 108                             'url': source_location
, 
 109                             'width': int_or_none(source
.get('width')), 
 110                             'height': int_or_none(source
.get('height')), 
 111                             'tbr': int_or_none(source
.get('bitrate')), 
 114                 for caption 
in asset
.get('caption_metadata', []): 
 115                     caption_url 
= caption
.get('source_url') 
 118                     subtitles
.setdefault(caption
.get('language', 'en'), []).append({ 
 120                         'ext': determine_ext(caption_url
, 'vtt'), 
 122             elif asset
.get('type') == 'image': 
 123                 asset_location 
= asset
.get('location') 
 124                 if not asset_location
: 
 127                     'url': asset_location
, 
 128                     'width': int_or_none(asset
.get('width')), 
 129                     'height': int_or_none(asset
.get('height')), 
 131         self
._sort
_formats
(formats
) 
 137             'thumbnails': thumbnails
, 
 138             'description': video_data
.get('short_description'), 
 139             'like_count': int_or_none(video_data
.get('like_count')), 
 140             'timestamp': parse_iso8601(video_data
.get('released_at')), 
 144             'season_id': season_id
, 
 145             'season_number': season_number
, 
 146             'episode_number': episode_number
, 
 147             'subtitles': subtitles
, 
 148             'age_limit': parse_age_limit(video_data
.get('rating')),