]>
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
19 class TurnerBaseIE(AdobePassIE
):
20 def _extract_timestamp(self
, video_data
):
21 return int_or_none(xpath_attr(video_data
, 'dateCreated', 'uts'))
23 def _extract_cvp_info(self
, data_src
, video_id
, path_data
={}, ap_data
={}):
24 video_data
= self
._download
_xml
(data_src
, video_id
)
25 video_id
= video_data
.attrib
['id']
26 title
= xpath_text(video_data
, 'headline', fatal
=True)
27 content_id
= xpath_text(video_data
, 'contentId') or video_id
28 # rtmp_src = xpath_text(video_data, 'akamai/src')
30 # splited_rtmp_src = rtmp_src.split(',')
31 # if len(splited_rtmp_src) == 2:
32 # rtmp_src = splited_rtmp_src[1]
33 # aifp = xpath_text(video_data, 'akamai/aifp', default='')
39 r
'(?P<width>[0-9]+)x(?P<height>[0-9]+)(?:_(?P<bitrate>[0-9]+))?')
40 # Possible formats locations: files/file, files/groupFiles/files
42 for video_file
in video_data
.findall('.//file'):
43 video_url
= video_file
.text
.strip()
46 ext
= determine_ext(video_url
)
47 if video_url
.startswith('/mp4:protected/'):
49 # TODO Correct extraction for these files
50 # protected_path_data = path_data.get('protected')
51 # if not protected_path_data or not rtmp_src:
53 # protected_path = self._search_regex(
54 # r'/mp4:(.+)\.[a-z0-9]', video_url, 'secure path')
55 # auth = self._download_webpage(
56 # protected_path_data['tokenizer_src'], query={
57 # 'path': protected_path,
58 # 'videoId': content_id,
61 # token = xpath_text(auth, 'token')
64 # video_url = rtmp_src + video_url + '?' + token
65 elif video_url
.startswith('/secure/'):
66 secure_path_data
= path_data
.get('secure')
67 if not secure_path_data
:
69 video_url
= secure_path_data
['media_src'] + video_url
70 secure_path
= self
._search
_regex
(r
'https?://[^/]+(.+/)', video_url
, 'secure path') + '*'
71 token
= tokens
.get(secure_path
)
75 'videoId': content_id
,
77 if ap_data
.get('auth_required'):
78 query
['accessToken'] = self
._extract
_mvpd
_auth
(ap_data
['url'], video_id
, ap_data
['site_name'], ap_data
['site_name'])
79 auth
= self
._download
_xml
(
80 secure_path_data
['tokenizer_src'], video_id
, query
=query
)
81 error_msg
= xpath_text(auth
, 'error/msg')
83 raise ExtractorError(error_msg
, expected
=True)
84 token
= xpath_text(auth
, 'token')
87 tokens
[secure_path
] = token
88 video_url
= video_url
+ '?hdnea=' + token
89 elif not re
.match('https?://', video_url
):
90 base_path_data
= path_data
.get(ext
, path_data
.get('default', {}))
91 media_src
= base_path_data
.get('media_src')
94 video_url
= media_src
+ video_url
97 urls
.append(video_url
)
98 format_id
= video_file
.get('bitrate')
100 formats
.extend(self
._extract
_smil
_formats
(
101 video_url
, video_id
, fatal
=False))
103 m3u8_formats
= self
._extract
_m
3u8_formats
(
104 video_url
, video_id
, 'mp4',
105 m3u8_id
=format_id
or 'hls', fatal
=False)
106 if '/secure/' in video_url
and '?hdnea=' in video_url
:
107 for f
in m3u8_formats
:
108 f
['_seekable'] = False
109 formats
.extend(m3u8_formats
)
111 formats
.extend(self
._extract
_f
4m
_formats
(
112 update_url_query(video_url
, {'hdcore': '3.7.0'}),
113 video_id
, f4m_id
=format_id
or 'hds', fatal
=False))
116 'format_id': format_id
,
120 mobj
= rex
.search(format_id
+ video_url
)
123 'width': int(mobj
.group('width')),
124 'height': int(mobj
.group('height')),
125 'tbr': int_or_none(mobj
.group('bitrate')),
127 elif isinstance(format_id
, compat_str
):
128 if format_id
.isdigit():
129 f
['tbr'] = int(format_id
)
131 mobj
= re
.match(r
'ios_(audio|[0-9]+)$', format_id
)
133 if mobj
.group(1) == 'audio':
139 f
['tbr'] = int(mobj
.group(1))
141 self
._sort
_formats
(formats
)
144 for source
in video_data
.findall('closedCaptions/source'):
145 for track
in source
.findall('track'):
146 track_url
= track
.get('url')
147 if not isinstance(track_url
, compat_str
) or track_url
.endswith('/big'):
149 lang
= track
.get('lang') or track
.get('label') or 'en'
150 subtitles
.setdefault(lang
, []).append({
156 }.get(source
.get('format'))
160 'id': image
.get('cut'),
162 'width': int_or_none(image
.get('width')),
163 'height': int_or_none(image
.get('height')),
164 } for image
in video_data
.findall('images/image')]
170 'subtitles': subtitles
,
171 'thumbnails': thumbnails
,
172 'description': xpath_text(video_data
, 'description'),
173 'duration': parse_duration(xpath_text(video_data
, 'length') or xpath_text(video_data
, 'trt')),
174 'timestamp': self
._extract
_timestamp
(video_data
),
175 'upload_date': xpath_attr(video_data
, 'metas', 'version'),
176 'series': xpath_text(video_data
, 'showTitle'),
177 'season_number': int_or_none(xpath_text(video_data
, 'seasonNumber')),
178 'episode_number': int_or_none(xpath_text(video_data
, 'episodeNumber')),