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