]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/mitele.py
release 2017.10.01
[yt-dlp.git] / youtube_dl / extractor / mitele.py
CommitLineData
69295694 1# coding: utf-8
938dd254
JMF
2from __future__ import unicode_literals
3
cb882540 4import uuid
69295694 5
938dd254 6from .common import InfoExtractor
e313d209 7from .ooyala import OoyalaIE
eb97f46e 8from ..compat import (
cb882540 9 compat_str,
15707c7e 10 compat_urllib_parse_urlencode,
eb97f46e
JMF
11 compat_urlparse,
12)
1cc79574 13from ..utils import (
f84ce1eb 14 int_or_none,
47335a0e
RA
15 extract_attributes,
16 determine_ext,
cb882540
D
17 smuggle_url,
18 parse_duration,
938dd254
JMF
19)
20
21
47335a0e
RA
22class MiTeleBaseIE(InfoExtractor):
23 def _get_player_info(self, url, webpage):
24 player_data = extract_attributes(self._search_regex(
25 r'(?s)(<ms-video-player.+?</ms-video-player>)',
26 webpage, 'ms video player'))
27 video_id = player_data['data-media-id']
e313d209
S
28 if player_data.get('data-cms-id') == 'ooyala':
29 return self.url_result(
30 'ooyala:%s' % video_id, ie=OoyalaIE.ie_key(), video_id=video_id)
47335a0e
RA
31 config_url = compat_urlparse.urljoin(url, player_data['data-config'])
32 config = self._download_json(
33 config_url, video_id, 'Downloading config JSON')
34 mmc_url = config['services']['mmc']
35
36 duration = None
37 formats = []
38 for m_url in (mmc_url, mmc_url.replace('/flash.json', '/html5.json')):
39 mmc = self._download_json(
40 m_url, video_id, 'Downloading mmc JSON')
41 if not duration:
42 duration = int_or_none(mmc.get('duration'))
43 for location in mmc['locations']:
44 gat = self._proto_relative_url(location.get('gat'), 'http:')
45 bas = location.get('bas')
46 loc = location.get('loc')
47 ogn = location.get('ogn')
48 if None in (gat, bas, loc, ogn):
49 continue
50 token_data = {
51 'bas': bas,
52 'icd': loc,
53 'ogn': ogn,
54 'sta': '0',
55 }
56 media = self._download_json(
57 '%s/?%s' % (gat, compat_urllib_parse_urlencode(token_data)),
58 video_id, 'Downloading %s JSON' % location['loc'])
59 file_ = media.get('file')
60 if not file_:
61 continue
62 ext = determine_ext(file_)
63 if ext == 'f4m':
64 formats.extend(self._extract_f4m_formats(
65 file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
66 video_id, f4m_id='hds', fatal=False))
67 elif ext == 'm3u8':
68 formats.extend(self._extract_m3u8_formats(
69 file_, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
70 self._sort_formats(formats)
71
72 return {
73 'id': video_id,
74 'formats': formats,
75 'thumbnail': player_data.get('data-poster') or config.get('poster', {}).get('imageUrl'),
76 'duration': duration,
77 }
78
79
cb882540 80class MiTeleIE(InfoExtractor):
3368d70d 81 IE_DESC = 'mitele.es'
b68599ed 82 _VALID_URL = r'https?://(?:www\.)?mitele\.es/(?:[^/]+/)+(?P<id>[^/]+)/player'
938dd254 83
69295694 84 _TESTS = [{
cb882540 85 'url': 'http://www.mitele.es/programas-tv/diario-de/57b0dfb9c715da65618b4afa/player',
938dd254 86 'info_dict': {
cb882540 87 'id': '57b0dfb9c715da65618b4afa',
47335a0e 88 'ext': 'mp4',
f84ce1eb
S
89 'title': 'Tor, la web invisible',
90 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
69295694
S
91 'series': 'Diario de',
92 'season': 'La redacción',
8eb7b5c3
S
93 'season_number': 14,
94 'season_id': 'diario_de_t14_11981',
69295694 95 'episode': 'Programa 144',
8eb7b5c3 96 'episode_number': 3,
ec85ded8 97 'thumbnail': r're:(?i)^https?://.*\.jpg$',
938dd254
JMF
98 'duration': 2913,
99 },
cb882540 100 'add_ie': ['Ooyala'],
69295694
S
101 }, {
102 # no explicit title
cb882540 103 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/57b0de3dc915da14058b4876/player',
69295694 104 'info_dict': {
cb882540 105 'id': '57b0de3dc915da14058b4876',
47335a0e 106 'ext': 'mp4',
cb882540
D
107 'title': 'Cuarto Milenio Temporada 6 Programa 226',
108 'description': 'md5:5ff132013f0cd968ffbf1f5f3538a65f',
69295694
S
109 'series': 'Cuarto Milenio',
110 'season': 'Temporada 6',
8eb7b5c3
S
111 'season_number': 6,
112 'season_id': 'cuarto_milenio_t06_12715',
69295694 113 'episode': 'Programa 226',
8eb7b5c3 114 'episode_number': 24,
ec85ded8 115 'thumbnail': r're:(?i)^https?://.*\.jpg$',
cb882540 116 'duration': 7313,
69295694
S
117 },
118 'params': {
119 'skip_download': True,
120 },
cb882540 121 'add_ie': ['Ooyala'],
b68599ed 122 }, {
123 'url': 'http://www.mitele.es/series-online/la-que-se-avecina/57aac5c1c915da951a8b45ed/player',
124 'only_matching': True,
69295694 125 }]
938dd254
JMF
126
127 def _real_extract(self, url):
cb882540
D
128 video_id = self._match_id(url)
129 webpage = self._download_webpage(url, video_id)
130
8eb7b5c3
S
131 gigya_url = self._search_regex(
132 r'<gigya-api>[^>]*</gigya-api>[^>]*<script\s+src="([^"]*)">[^>]*</script>',
133 webpage, 'gigya', default=None)
134 gigya_sc = self._download_webpage(
135 compat_urlparse.urljoin('http://www.mitele.es/', gigya_url),
136 video_id, 'Downloading gigya script')
137
cb882540 138 # Get a appKey/uuid for getting the session key
8eb7b5c3 139 appKey = self._search_regex(
00cb0fac
L
140 r'constant\s*\(\s*["\']_appGridApplicationKey["\']\s*,\s*["\']([0-9a-f]+)',
141 gigya_sc, 'appKey')
8eb7b5c3
S
142
143 session_json = self._download_json(
144 'https://appgrid-api.cloud.accedo.tv/session',
145 video_id, 'Downloading session keys', query={
146 'appKey': appKey,
147 'uuid': compat_str(uuid.uuid4()),
148 })
149
150 paths = self._download_json(
151 'https://appgrid-api.cloud.accedo.tv/metadata/general_configuration,%20web_configuration',
152 video_id, 'Downloading paths JSON',
153 query={'sessionKey': compat_str(session_json['sessionKey'])})
154
cb882540 155 ooyala_s = paths['general_configuration']['api_configuration']['ooyala_search']
8eb7b5c3
S
156 source = self._download_json(
157 'http://%s%s%s/docs/%s' % (
158 ooyala_s['base_url'], ooyala_s['full_path'],
159 ooyala_s['provider_id'], video_id),
160 video_id, 'Downloading data JSON', query={
161 'include_titles': 'Series,Season',
162 'product_name': 'test',
163 'format': 'full',
164 })['hits']['hits'][0]['_source']
cb882540 165
8eb7b5c3 166 embedCode = source['offers'][0]['embed_codes'][0]
cb882540 167 titles = source['localizable_titles'][0]
8eb7b5c3 168
cb882540 169 title = titles.get('title_medium') or titles['title_long']
8eb7b5c3
S
170
171 description = titles.get('summary_long') or titles.get('summary_medium')
172
173 def get(key1, key2):
174 value1 = source.get(key1)
175 if not value1 or not isinstance(value1, list):
176 return
177 if not isinstance(value1[0], dict):
178 return
179 return value1[0].get(key2)
180
181 series = get('localizable_titles_series', 'title_medium')
182
183 season = get('localizable_titles_season', 'title_medium')
184 season_number = int_or_none(source.get('season_number'))
185 season_id = source.get('season_id')
186
187 episode = titles.get('title_sort_name')
188 episode_number = int_or_none(source.get('episode_number'))
189
190 duration = parse_duration(get('videos', 'duration'))
f84ce1eb 191
cb882540
D
192 return {
193 '_type': 'url_transparent',
194 # for some reason only HLS is supported
5e8eebb6 195 'url': smuggle_url('ooyala:' + embedCode, {'supportedformats': 'm3u8,dash'}),
cb882540 196 'id': video_id,
f84ce1eb 197 'title': title,
cb882540 198 'description': description,
69295694
S
199 'series': series,
200 'season': season,
8eb7b5c3
S
201 'season_number': season_number,
202 'season_id': season_id,
69295694 203 'episode': episode,
8eb7b5c3 204 'episode_number': episode_number,
cb882540 205 'duration': duration,
8eb7b5c3 206 'thumbnail': get('images', 'url'),
cb882540 207 }