]>
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             'resource_id': 'Disney', 
  30         'watchdisneyjunior': { 
  32             'resource_id': 'DisneyJunior', 
  36             'resource_id': 'DisneyXD', 
  40             'resource_id': 'Disney', 
  46                             (?:(?P<sub_domain>%s)\.)?go| 
  47                             (?P<sub_domain_2>abc|freeform|disneynow) 
  50                             (?:[^/]+/)*(?P<id>[Vv][Dd][Kk][Aa]\w+)| 
  51                             (?:[^/]+/)*(?P<display_id>[^/?\#]+) 
  53                     ''' % '|'.join(list(_SITE_INFO
.keys())) 
  55         'url': 'http://abc.go.com/shows/designated-survivor/video/most-recent/VDKA3807643', 
  59             'title': 'The Traitor in the White House', 
  60             'description': 'md5:05b009d2d145a1e85d25111bd37222e8', 
  64             'skip_download': True, 
  66         'skip': 'This content is no longer available.', 
  68         'url': 'http://watchdisneyxd.go.com/doraemon', 
  73         'playlist_mincount': 51, 
  75         'url': 'http://freeform.go.com/shows/shadowhunters/episodes/season-2/1-this-guilty-blood', 
  79             'title': 'This Guilty Blood', 
  80             'description': 'md5:f18e79ad1c613798d95fdabfe96cd292', 
  84             'geo_bypass_ip_block': '3.244.239.0/24', 
  86             'skip_download': True, 
  89         'url': 'https://abc.com/shows/the-rookie/episode-guide/season-02/03-the-bet', 
  94             'description': 'md5:c66de8ba2e92c6c5c113c3ade84ab404', 
  98             'geo_bypass_ip_block': '3.244.239.0/24', 
 100             'skip_download': True, 
 103         'url': 'http://abc.go.com/shows/the-catch/episode-guide/season-01/10-the-wedding', 
 104         'only_matching': True, 
 106         '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', 
 107         'only_matching': True, 
 110         'url': 'http://disneynow.go.com/shows/big-hero-6-the-series/season-01/episode-10-mr-sparkles-loses-his-sparkle/vdka4637915', 
 111         'only_matching': True, 
 114         'url': 'http://disneynow.go.com/shows/minnies-bow-toons/video/happy-campers/vdka4872013', 
 115         'only_matching': True, 
 117         'url': 'https://disneynow.com/shows/minnies-bow-toons/video/happy-campers/vdka4872013', 
 118         'only_matching': True, 
 121     def _extract_videos(self
, brand
, video_id
='-1', show_id
='-1'): 
 122         display_id 
= video_id 
if video_id 
!= '-1' else show_id
 
 123         return self
._download
_json
( 
 124             '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
), 
 127     def _real_extract(self
, url
): 
 128         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 129         sub_domain 
= mobj
.group('sub_domain') or mobj
.group('sub_domain_2') 
 130         video_id
, display_id 
= mobj
.group('id', 'display_id') 
 131         site_info 
= self
._SITE
_INFO
.get(sub_domain
, {}) 
 132         brand 
= site_info
.get('brand') 
 133         if not video_id 
or not site_info
: 
 134             webpage 
= self
._download
_webpage
(url
, display_id 
or video_id
) 
 135             video_id 
= self
._search
_regex
( 
 137                     # There may be inner quotes, e.g. data-video-id="'VDKA3609139'" 
 138                     # from http://freeform.go.com/shows/shadowhunters/episodes/season-2/1-this-guilty-blood 
 139                     r
'data-video-id=["\']*(VDKA\w
+)', 
 140                     # https://abc.com/shows/the-rookie/episode-guide/season-02/03-the-bet 
 141                     r'\b(?
:video
)?
id["\']\s*:\s*["\'](VDKA\w
+)' 
 142                 ), webpage, 'video 
id', default=video_id) 
 144                 brand = self._search_regex( 
 145                     (r'data
-brand
=\s
*["\']\s*(\d+)', 
 146                      r'data-page-brand=\s*["\']\s
*(\d
+)'), webpage, 'brand
', 
 149                     si for _, si in self._SITE_INFO.items() 
 150                     if si.get('brand
') == brand) 
 152                 # show extraction works for Disney, DisneyJunior and DisneyXD 
 153                 # ABC and Freeform has different layout 
 154                 show_id = self._search_regex(r'data
-show
-id=["\']*(SH\d+)', webpage, 'show id') 
 155                 videos = self._extract_videos(brand, show_id=show_id) 
 156                 show_title = self._search_regex(r'data-show-title="([^
"]+)"', webpage, 'show title
', fatal=False) 
 159                     entries.append(self.url_result( 
 160                         video['url
'], 'Go
', video.get('id'), video.get('title
'))) 
 162                 return self.playlist_result(entries, show_id, show_title) 
 163         video_data = self._extract_videos(brand, video_id)[0] 
 164         video_id = video_data['id'] 
 165         title = video_data['title
'] 
 168         for asset in video_data.get('assets
', {}).get('asset
', []): 
 169             asset_url = asset.get('value
') 
 172             format_id = asset.get('format
') 
 173             ext = determine_ext(asset_url) 
 175                 video_type = video_data.get('type') 
 177                     'video_id
': video_data['id'], 
 178                     'video_type
': video_type, 
 182                 if video_data.get('accesslevel
') == '1': 
 183                     requestor_id = site_info.get('requestor_id
', 'DisneyChannels
') 
 184                     resource = site_info.get('resource_id
') or self._get_mvpd_resource( 
 185                         requestor_id, title, video_id, None) 
 186                     auth = self._extract_mvpd_auth( 
 187                         url, video_id, requestor_id, resource) 
 191                         'adobe_requestor_id
': requestor_id, 
 194                     self._initialize_geo_bypass({'countries
': ['US
']}) 
 195                 entitlement = self._download_json( 
 196                     'https
://api
.entitlement
.watchabc
.go
.com
/vp2
/ws
-secure
/entitlement
/2020/authorize
.json
', 
 197                     video_id, data=urlencode_postdata(data)) 
 198                 errors = entitlement.get('errors
', {}).get('errors
', []) 
 201                         if error.get('code
') == 1002: 
 202                             self.raise_geo_restricted( 
 203                                 error['message
'], countries=['US
']) 
 204                     error_message = ', '.join([error['message
'] for error in errors]) 
 205                     raise ExtractorError('%s said
: %s' % (self.IE_NAME, error_message), expected=True) 
 206                 asset_url += '?
' + entitlement['uplynkData
']['sessionKey
'] 
 207                 formats.extend(self._extract_m3u8_formats( 
 208                     asset_url, video_id, 'mp4
', m3u8_id=format_id or 'hls
', fatal=False)) 
 211                     'format_id
': format_id, 
 215                 if re.search(r'(?
:/mp4
/source
/|_source\
.mp4
)', asset_url): 
 217                         'format_id
': ('%s-' % format_id if format_id else '') + 'SOURCE
', 
 221                     mobj = re.search(r'/(\d
+)x(\d
+)/', asset_url) 
 223                         height = int(mobj.group(2)) 
 225                             'format_id
': ('%s-' % format_id if format_id else '') + '%dP
' % height, 
 226                             'width
': int(mobj.group(1)), 
 230         self._sort_formats(formats) 
 233         for cc in video_data.get('closedcaption
', {}).get('src
', []): 
 234             cc_url = cc.get('value
') 
 237             ext = determine_ext(cc_url) 
 240             subtitles.setdefault(cc.get('lang
'), []).append({ 
 246         for thumbnail in video_data.get('thumbnails
', {}).get('thumbnail
', []): 
 247             thumbnail_url = thumbnail.get('value
') 
 248             if not thumbnail_url: 
 251                 'url
': thumbnail_url, 
 252                 'width
': int_or_none(thumbnail.get('width
')), 
 253                 'height
': int_or_none(thumbnail.get('height
')), 
 259             'description
': video_data.get('longdescription
') or video_data.get('description
'), 
 260             'duration
': int_or_none(video_data.get('duration
', {}).get('value
'), 1000), 
 261             'age_limit
': parse_age_limit(video_data.get('tvrating
', {}).get('rating
')), 
 262             'episode_number
': int_or_none(video_data.get('episodenumber
')), 
 263             'series
': video_data.get('show
', {}).get('title
'), 
 264             'season_number
': int_or_none(video_data.get('season
', {}).get('num
')), 
 265             'thumbnails
': thumbnails, 
 267             'subtitles
': subtitles,