]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/go.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class GoIE(InfoExtractor
):
20 'watchdisneychannel': '004',
21 'watchdisneyjunior': '008',
22 'watchdisneyxd': '009',
24 _VALID_URL
= r
'https?://(?:(?P<sub_domain>%s)\.)?go\.com/(?:[^/]+/)*(?:vdka(?P<id>\w+)|season-\d+/\d+-(?P<display_id>[^/?#]+))' % '|'.join(_BRANDS
.keys())
26 'url': 'http://abc.go.com/shows/castle/video/most-recent/vdka0_g86w5onx',
30 'title': 'Sneak Peek: Language Arts',
31 'description': 'md5:7dcdab3b2d17e5217c953256af964e9c',
35 'skip_download': True,
38 'url': 'http://abc.go.com/shows/after-paradise/video/most-recent/vdka3335601',
39 'only_matching': True,
42 def _real_extract(self
, url
):
43 sub_domain
, video_id
, display_id
= re
.match(self
._VALID
_URL
, url
).groups()
45 webpage
= self
._download
_webpage
(url
, display_id
)
46 video_id
= self
._search
_regex
(
47 # There may be inner quotes, e.g. data-video-id="'VDKA3609139'"
48 # from http://freeform.go.com/shows/shadowhunters/episodes/season-2/1-this-guilty-blood
49 r
'data-video-id=["\']*VDKA(\w
+)', webpage, 'video
id')
50 brand = self._BRANDS[sub_domain]
51 video_data = self._download_json(
52 'http
://api
.contents
.watchabc
.go
.com
/vp2
/ws
/contents
/3000/videos
/%s/001/-1/-1/-1/%s/-1/-1.json
' % (brand, video_id),
54 title = video_data['title
']
57 for asset in video_data.get('assets
', {}).get('asset
', []):
58 asset_url = asset.get('value
')
61 format_id = asset.get('format
')
62 ext = determine_ext(asset_url)
64 video_type = video_data.get('type')
65 if video_type == 'lf
':
66 entitlement = self._download_json(
67 'https
://api
.entitlement
.watchabc
.go
.com
/vp2
/ws
-secure
/entitlement
/2020/authorize
.json
',
68 video_id, data=urlencode_postdata({
69 'video_id
': video_data['id'],
70 'video_type
': video_type,
74 errors = entitlement.get('errors
', {}).get('errors
', [])
76 error_message = ', '.join([error['message
'] for error in errors])
77 raise ExtractorError('%s said
: %s' % (self.IE_NAME, error_message), expected=True)
78 asset_url += '?
' + entitlement['uplynkData
']['sessionKey
']
79 formats.extend(self._extract_m3u8_formats(
80 asset_url, video_id, 'mp4
', m3u8_id=format_id or 'hls
', fatal=False))
83 'format_id
': format_id,
87 self._sort_formats(formats)
90 for cc in video_data.get('closedcaption
', {}).get('src
', []):
91 cc_url = cc.get('value
')
94 ext = determine_ext(cc_url)
97 subtitles.setdefault(cc.get('lang
'), []).append({
103 for thumbnail in video_data.get('thumbnails
', {}).get('thumbnail
', []):
104 thumbnail_url = thumbnail.get('value
')
105 if not thumbnail_url:
108 'url
': thumbnail_url,
109 'width
': int_or_none(thumbnail.get('width
')),
110 'height
': int_or_none(thumbnail.get('height
')),
116 'description
': video_data.get('longdescription
') or video_data.get('description
'),
117 'duration
': int_or_none(video_data.get('duration
', {}).get('value
'), 1000),
118 'age_limit
': parse_age_limit(video_data.get('tvrating
', {}).get('rating
')),
119 'episode_number
': int_or_none(video_data.get('episodenumber
')),
120 'series
': video_data.get('show
', {}).get('title
'),
121 'season_number
': int_or_none(video_data.get('season
', {}).get('num
')),
122 'thumbnails
': thumbnails,
124 'subtitles
': subtitles,