]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/go.py
   2 from __future__ 
import unicode_literals
 
   6 from .adobepass 
import AdobePassIE
 
  16 class GoIE(AdobePassIE
): 
  20             'requestor_id': 'ABC', 
  24             'requestor_id': 'ABCFamily', 
  26         'watchdisneychannel': { 
  28             'requestor_id': 'Disney', 
  30         'watchdisneyjunior': { 
  32             'requestor_id': 'DisneyJunior', 
  36             'requestor_id': 'DisneyXD', 
  39     _VALID_URL 
= r
'https?://(?:(?P<sub_domain>%s)\.)?go\.com/(?:(?:[^/]+/)*(?P<id>vdka\w+)|(?:[^/]+/)*(?P<display_id>[^/?#]+))' % '|'.join(_SITE_INFO
.keys()) 
  41         'url': 'http://abc.go.com/shows/designated-survivor/video/most-recent/VDKA3807643', 
  45             'title': 'The Traitor in the White House', 
  46             'description': 'md5:05b009d2d145a1e85d25111bd37222e8', 
  50             'skip_download': True, 
  53         'url': 'http://watchdisneyxd.go.com/doraemon', 
  58         'playlist_mincount': 51, 
  60         'url': 'http://abc.go.com/shows/the-catch/episode-guide/season-01/10-the-wedding', 
  61         'only_matching': True, 
  63         'url': 'http://abc.go.com/shows/world-news-tonight/episode-guide/2017-02/17-021717-intense-stand-off-between-man-with-rifle-and-police-in-oakland', 
  64         'only_matching': True, 
  67     def _extract_videos(self
, brand
, video_id
='-1', show_id
='-1'): 
  68         display_id 
= video_id 
if video_id 
!= '-1' else show_id
 
  69         return self
._download
_json
( 
  70             'http://api.contents.watchabc.go.com/vp2/ws/contents/3000/videos/%s/001/-1/%s/-1/%s/-1/-1.json' % (brand
, show_id
, video_id
), 
  73     def _real_extract(self
, url
): 
  74         sub_domain
, video_id
, display_id 
= re
.match(self
._VALID
_URL
, url
).groups() 
  75         site_info 
= self
._SITE
_INFO
[sub_domain
] 
  76         brand 
= site_info
['brand'] 
  78             webpage 
= self
._download
_webpage
(url
, display_id
) 
  79             video_id 
= self
._search
_regex
( 
  80                 # There may be inner quotes, e.g. data-video-id="'VDKA3609139'" 
  81                 # from http://freeform.go.com/shows/shadowhunters/episodes/season-2/1-this-guilty-blood 
  82                 r
'data-video-id=["\']*(VDKA\w
+)', webpage, 'video 
id', default=None) 
  84                 # show extraction works for Disney, DisneyJunior and DisneyXD 
  85                 # ABC and Freeform has different layout 
  86                 show_id = self._search_regex(r'data
-show
-id=["\']*(SH\d+)', webpage, 'show id') 
  87                 videos = self._extract_videos(brand, show_id=show_id) 
  88                 show_title = self._search_regex(r'data-show-title="([^
"]+)"', webpage, 'show title
', fatal=False) 
  91                     entries.append(self.url_result( 
  92                         video['url
'], 'Go
', video.get('id'), video.get('title
'))) 
  94                 return self.playlist_result(entries, show_id, show_title) 
  95         video_data = self._extract_videos(brand, video_id)[0] 
  96         video_id = video_data['id'] 
  97         title = video_data['title
'] 
 100         for asset in video_data.get('assets
', {}).get('asset
', []): 
 101             asset_url = asset.get('value
') 
 104             format_id = asset.get('format
') 
 105             ext = determine_ext(asset_url) 
 107                 video_type = video_data.get('type') 
 109                     'video_id
': video_data['id'], 
 110                     'video_type
': video_type, 
 114                 if video_data.get('accesslevel
') == '1': 
 115                     requestor_id = site_info['requestor_id
'] 
 116                     resource = self._get_mvpd_resource( 
 117                         requestor_id, title, video_id, None) 
 118                     auth = self._extract_mvpd_auth( 
 119                         url, video_id, requestor_id, resource) 
 123                         'adobe_requestor_id
': requestor_id, 
 126                     self._initialize_geo_bypass(['US
']) 
 127                 entitlement = self._download_json( 
 128                     'https
://api
.entitlement
.watchabc
.go
.com
/vp2
/ws
-secure
/entitlement
/2020/authorize
.json
', 
 129                     video_id, data=urlencode_postdata(data)) 
 130                 errors = entitlement.get('errors
', {}).get('errors
', []) 
 133                         if error.get('code
') == 1002: 
 134                             self.raise_geo_restricted( 
 135                                 error['message
'], countries=['US
']) 
 136                     error_message = ', '.join([error['message
'] for error in errors]) 
 137                     raise ExtractorError('%s said
: %s' % (self.IE_NAME, error_message), expected=True) 
 138                 asset_url += '?
' + entitlement['uplynkData
']['sessionKey
'] 
 139                 formats.extend(self._extract_m3u8_formats( 
 140                     asset_url, video_id, 'mp4
', m3u8_id=format_id or 'hls
', fatal=False)) 
 143                     'format_id
': format_id, 
 147                 if re.search(r'(?
:/mp4
/source
/|_source\
.mp4
)', asset_url): 
 149                         'format_id
': ('%s-' % format_id if format_id else '') + 'SOURCE
', 
 153                     mobj = re.search(r'/(\d
+)x(\d
+)/', asset_url) 
 155                         height = int(mobj.group(2)) 
 157                             'format_id
': ('%s-' % format_id if format_id else '') + '%dP
' % height, 
 158                             'width
': int(mobj.group(1)), 
 162         self._sort_formats(formats) 
 165         for cc in video_data.get('closedcaption
', {}).get('src
', []): 
 166             cc_url = cc.get('value
') 
 169             ext = determine_ext(cc_url) 
 172             subtitles.setdefault(cc.get('lang
'), []).append({ 
 178         for thumbnail in video_data.get('thumbnails
', {}).get('thumbnail
', []): 
 179             thumbnail_url = thumbnail.get('value
') 
 180             if not thumbnail_url: 
 183                 'url
': thumbnail_url, 
 184                 'width
': int_or_none(thumbnail.get('width
')), 
 185                 'height
': int_or_none(thumbnail.get('height
')), 
 191             'description
': video_data.get('longdescription
') or video_data.get('description
'), 
 192             'duration
': int_or_none(video_data.get('duration
', {}).get('value
'), 1000), 
 193             'age_limit
': parse_age_limit(video_data.get('tvrating
', {}).get('rating
')), 
 194             'episode_number
': int_or_none(video_data.get('episodenumber
')), 
 195             'series
': video_data.get('show
', {}).get('title
'), 
 196             'season_number
': int_or_none(video_data.get('season
', {}).get('num
')), 
 197             'thumbnails
': thumbnails, 
 199             'subtitles
': subtitles,