]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/go90.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  14 class Go90IE(InfoExtractor
): 
  15     _VALID_URL 
= r
'https?://(?:www\.)?go90\.com/videos/(?P<id>[0-9a-zA-Z]+)' 
  17         'url': 'https://www.go90.com/videos/84BUqjLpf9D', 
  18         'md5': 'efa7670dbbbf21a7b07b360652b24a32', 
  22             'title': 'Daily VICE - Inside The Utah Coalition Against Pornography Convention', 
  23             'description': 'VICE\'s Karley Sciortino meets with activists who discuss the state\'s strong anti-porn stance. Then, VICE Sports explains NFL contracts.', 
  24             'timestamp': 1491868800, 
  25             'upload_date': '20170411', 
  29     def _real_extract(self
, url
): 
  30         video_id 
= self
._match
_id
(url
) 
  31         video_data 
= self
._download
_json
( 
  32             'https://www.go90.com/api/view/items/' + video_id
, 
  34                 'Content-Type': 'application/json; charset=utf-8', 
  35             }, data
=b
'{"client":"web","device_type":"pc"}') 
  36         main_video_asset 
= video_data
['main_video_asset'] 
  38         episode_number 
= int_or_none(video_data
.get('episode_number')) 
  43         for metadata 
in video_data
.get('__children', {}).get('Item', {}).values(): 
  44             if metadata
.get('type') == 'show': 
  45                 series 
= metadata
.get('title') 
  46             elif metadata
.get('type') == 'season': 
  47                 season 
= metadata
.get('title') 
  48                 season_id 
= metadata
.get('id') 
  49                 season_number 
= int_or_none(metadata
.get('season_number')) 
  51         title 
= episode 
= video_data
.get('title') or series
 
  52         if series 
and series 
!= title
: 
  53             title 
= '%s - %s' % (series
, title
) 
  58         for asset 
in video_data
.get('assets'): 
  59             if asset
.get('id') == main_video_asset
: 
  60                 for source 
in asset
.get('sources', []): 
  61                     source_location 
= source
.get('location') 
  62                     if not source_location
: 
  64                     source_type 
= source
.get('type') 
  65                     if source_type 
== 'hls': 
  66                         m3u8_formats 
= self
._extract
_m
3u8_formats
( 
  67                             source_location
, video_id
, 'mp4', 
  68                             'm3u8_native', m3u8_id
='hls', fatal
=False) 
  69                         for f 
in m3u8_formats
: 
  70                             mobj 
= re
.search(r
'/hls-(\d+)-(\d+)K', f
['url']) 
  72                                 height
, tbr 
= mobj
.groups() 
  73                                 height 
= int_or_none(height
) 
  75                                     'height': f
.get('height') or height
, 
  76                                     'width': f
.get('width') or int_or_none(height 
/ 9.0 * 16.0 if height 
else None), 
  77                                     'tbr': f
.get('tbr') or int_or_none(tbr
), 
  79                         formats
.extend(m3u8_formats
) 
  80                     elif source_type 
== 'dash': 
  81                         formats
.extend(self
._extract
_mpd
_formats
( 
  82                             source_location
, video_id
, mpd_id
='dash', fatal
=False)) 
  85                             'format_id': source
.get('name'), 
  86                             'url': source_location
, 
  87                             'width': int_or_none(source
.get('width')), 
  88                             'height': int_or_none(source
.get('height')), 
  89                             'tbr': int_or_none(source
.get('bitrate')), 
  92                 for caption 
in asset
.get('caption_metadata', []): 
  93                     caption_url 
= caption
.get('source_url') 
  96                     subtitles
.setdefault(caption
.get('language', 'en'), []).append({ 
  98                         'ext': determine_ext(caption_url
, 'vtt'), 
 100             elif asset
.get('type') == 'image': 
 101                 asset_location 
= asset
.get('location') 
 102                 if not asset_location
: 
 105                     'url': asset_location
, 
 106                     'width': int_or_none(asset
.get('width')), 
 107                     'height': int_or_none(asset
.get('height')), 
 109         self
._sort
_formats
(formats
) 
 115             'thumbnails': thumbnails
, 
 116             'description': video_data
.get('short_description'), 
 117             'like_count': int_or_none(video_data
.get('like_count')), 
 118             'timestamp': parse_iso8601(video_data
.get('released_at')), 
 122             'season_id': season_id
, 
 123             'season_number': season_number
, 
 124             'episode_number': episode_number
, 
 125             'subtitles': subtitles
,