]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/turner.py
2 from __future__
import unicode_literals
6 from .adobepass
import AdobePassIE
7 from ..compat
import compat_str
20 class TurnerBaseIE(AdobePassIE
):
21 def _extract_timestamp(self
, video_data
):
22 return int_or_none(xpath_attr(video_data
, 'dateCreated', 'uts'))
24 def _extract_cvp_info(self
, data_src
, video_id
, path_data
={}, ap_data
={}):
25 video_data
= self
._download
_xml
(data_src
, video_id
)
26 video_id
= video_data
.attrib
['id']
27 title
= xpath_text(video_data
, 'headline', fatal
=True)
28 content_id
= xpath_text(video_data
, 'contentId') or video_id
29 # rtmp_src = xpath_text(video_data, 'akamai/src')
31 # splited_rtmp_src = rtmp_src.split(',')
32 # if len(splited_rtmp_src) == 2:
33 # rtmp_src = splited_rtmp_src[1]
34 # aifp = xpath_text(video_data, 'akamai/aifp', default='')
40 r
'(?P<width>[0-9]+)x(?P<height>[0-9]+)(?:_(?P<bitrate>[0-9]+))?')
41 # Possible formats locations: files/file, files/groupFiles/files
43 for video_file
in video_data
.findall('.//file'):
44 video_url
= video_file
.text
.strip()
47 ext
= determine_ext(video_url
)
48 if video_url
.startswith('/mp4:protected/'):
50 # TODO Correct extraction for these files
51 # protected_path_data = path_data.get('protected')
52 # if not protected_path_data or not rtmp_src:
54 # protected_path = self._search_regex(
55 # r'/mp4:(.+)\.[a-z0-9]', video_url, 'secure path')
56 # auth = self._download_webpage(
57 # protected_path_data['tokenizer_src'], query={
58 # 'path': protected_path,
59 # 'videoId': content_id,
62 # token = xpath_text(auth, 'token')
65 # video_url = rtmp_src + video_url + '?' + token
66 elif video_url
.startswith('/secure/'):
67 secure_path_data
= path_data
.get('secure')
68 if not secure_path_data
:
70 video_url
= secure_path_data
['media_src'] + video_url
71 secure_path
= self
._search
_regex
(r
'https?://[^/]+(.+/)', video_url
, 'secure path') + '*'
72 token
= tokens
.get(secure_path
)
76 'videoId': content_id
,
78 if ap_data
.get('auth_required'):
79 query
['accessToken'] = self
._extract
_mvpd
_auth
(ap_data
['url'], video_id
, ap_data
['site_name'], ap_data
['site_name'])
80 auth
= self
._download
_xml
(
81 secure_path_data
['tokenizer_src'], video_id
, query
=query
)
82 error_msg
= xpath_text(auth
, 'error/msg')
84 raise ExtractorError(error_msg
, expected
=True)
85 token
= xpath_text(auth
, 'token')
88 tokens
[secure_path
] = token
89 video_url
= video_url
+ '?hdnea=' + token
90 elif not re
.match('https?://', video_url
):
91 base_path_data
= path_data
.get(ext
, path_data
.get('default', {}))
92 media_src
= base_path_data
.get('media_src')
95 video_url
= media_src
+ video_url
98 urls
.append(video_url
)
99 format_id
= video_file
.get('bitrate')
101 formats
.extend(self
._extract
_smil
_formats
(
102 video_url
, video_id
, fatal
=False))
104 m3u8_formats
= self
._extract
_m
3u8_formats
(
105 video_url
, video_id
, 'mp4',
106 m3u8_id
=format_id
or 'hls', fatal
=False)
107 if '/secure/' in video_url
and '?hdnea=' in video_url
:
108 for f
in m3u8_formats
:
109 f
['_seekable'] = False
110 formats
.extend(m3u8_formats
)
112 formats
.extend(self
._extract
_f
4m
_formats
(
113 update_url_query(video_url
, {'hdcore': '3.7.0'}),
114 video_id
, f4m_id
=format_id
or 'hds', fatal
=False))
117 'format_id': format_id
,
121 mobj
= rex
.search(format_id
+ video_url
)
124 'width': int(mobj
.group('width')),
125 'height': int(mobj
.group('height')),
126 'tbr': int_or_none(mobj
.group('bitrate')),
128 elif isinstance(format_id
, compat_str
):
129 if format_id
.isdigit():
130 f
['tbr'] = int(format_id
)
132 mobj
= re
.match(r
'ios_(audio|[0-9]+)$', format_id
)
134 if mobj
.group(1) == 'audio':
140 f
['tbr'] = int(mobj
.group(1))
142 self
._sort
_formats
(formats
)
145 for source
in video_data
.findall('closedCaptions/source'):
146 for track
in source
.findall('track'):
147 track_url
= track
.get('url')
148 if not isinstance(track_url
, compat_str
) or track_url
.endswith('/big'):
150 lang
= track
.get('lang') or track
.get('label') or 'en'
151 subtitles
.setdefault(lang
, []).append({
157 }.get(source
.get('format'))
161 'id': image
.get('cut'),
163 'width': int_or_none(image
.get('width')),
164 'height': int_or_none(image
.get('height')),
165 } for image
in video_data
.findall('images/image')]
167 is_live
= xpath_text(video_data
, 'isLive') == 'true'
171 'title': self
._live
_title
(title
) if is_live
else title
,
173 'subtitles': subtitles
,
174 'thumbnails': thumbnails
,
175 'thumbnail': xpath_text(video_data
, 'poster'),
176 'description': strip_or_none(xpath_text(video_data
, 'description')),
177 'duration': parse_duration(xpath_text(video_data
, 'length') or xpath_text(video_data
, 'trt')),
178 'timestamp': self
._extract
_timestamp
(video_data
),
179 'upload_date': xpath_attr(video_data
, 'metas', 'version'),
180 'series': xpath_text(video_data
, 'showTitle'),
181 'season_number': int_or_none(xpath_text(video_data
, 'seasonNumber')),
182 'episode_number': int_or_none(xpath_text(video_data
, 'episodeNumber')),