]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/mitele.py
[mitele] Relax _VALID_URL
[yt-dlp.git] / youtube_dl / extractor / mitele.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import uuid
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_str,
9 compat_urllib_parse_urlencode,
10 compat_urlparse,
11 )
12 from ..utils import (
13 int_or_none,
14 extract_attributes,
15 determine_ext,
16 smuggle_url,
17 parse_duration,
18 )
19
20
21 class MiTeleBaseIE(InfoExtractor):
22 def _get_player_info(self, url, webpage):
23 player_data = extract_attributes(self._search_regex(
24 r'(?s)(<ms-video-player.+?</ms-video-player>)',
25 webpage, 'ms video player'))
26 video_id = player_data['data-media-id']
27 config_url = compat_urlparse.urljoin(url, player_data['data-config'])
28 config = self._download_json(
29 config_url, video_id, 'Downloading config JSON')
30 mmc_url = config['services']['mmc']
31
32 duration = None
33 formats = []
34 for m_url in (mmc_url, mmc_url.replace('/flash.json', '/html5.json')):
35 mmc = self._download_json(
36 m_url, video_id, 'Downloading mmc JSON')
37 if not duration:
38 duration = int_or_none(mmc.get('duration'))
39 for location in mmc['locations']:
40 gat = self._proto_relative_url(location.get('gat'), 'http:')
41 bas = location.get('bas')
42 loc = location.get('loc')
43 ogn = location.get('ogn')
44 if None in (gat, bas, loc, ogn):
45 continue
46 token_data = {
47 'bas': bas,
48 'icd': loc,
49 'ogn': ogn,
50 'sta': '0',
51 }
52 media = self._download_json(
53 '%s/?%s' % (gat, compat_urllib_parse_urlencode(token_data)),
54 video_id, 'Downloading %s JSON' % location['loc'])
55 file_ = media.get('file')
56 if not file_:
57 continue
58 ext = determine_ext(file_)
59 if ext == 'f4m':
60 formats.extend(self._extract_f4m_formats(
61 file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
62 video_id, f4m_id='hds', fatal=False))
63 elif ext == 'm3u8':
64 formats.extend(self._extract_m3u8_formats(
65 file_, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
66 self._sort_formats(formats)
67
68 return {
69 'id': video_id,
70 'formats': formats,
71 'thumbnail': player_data.get('data-poster') or config.get('poster', {}).get('imageUrl'),
72 'duration': duration,
73 }
74
75
76 class MiTeleIE(InfoExtractor):
77 IE_DESC = 'mitele.es'
78 _VALID_URL = r'https?://(?:www\.)?mitele\.es/(?:[^/]+/)+(?P<id>[^/]+)/player'
79
80 _TESTS = [{
81 'url': 'http://www.mitele.es/programas-tv/diario-de/57b0dfb9c715da65618b4afa/player',
82 'info_dict': {
83 'id': '57b0dfb9c715da65618b4afa',
84 'ext': 'mp4',
85 'title': 'Tor, la web invisible',
86 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
87 'series': 'Diario de',
88 'season': 'La redacción',
89 'episode': 'Programa 144',
90 'thumbnail': 're:(?i)^https?://.*\.jpg$',
91 'duration': 2913,
92 },
93 'add_ie': ['Ooyala'],
94 }, {
95 # no explicit title
96 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/57b0de3dc915da14058b4876/player',
97 'info_dict': {
98 'id': '57b0de3dc915da14058b4876',
99 'ext': 'mp4',
100 'title': 'Cuarto Milenio Temporada 6 Programa 226',
101 'description': 'md5:5ff132013f0cd968ffbf1f5f3538a65f',
102 'series': 'Cuarto Milenio',
103 'season': 'Temporada 6',
104 'episode': 'Programa 226',
105 'thumbnail': 're:(?i)^https?://.*\.jpg$',
106 'duration': 7313,
107 },
108 'params': {
109 'skip_download': True,
110 },
111 'add_ie': ['Ooyala'],
112 }, {
113 'url': 'http://www.mitele.es/series-online/la-que-se-avecina/57aac5c1c915da951a8b45ed/player',
114 'only_matching': True,
115 }]
116
117 def _real_extract(self, url):
118 video_id = self._match_id(url)
119 webpage = self._download_webpage(url, video_id)
120
121 gigya_url = self._search_regex(r'<gigya-api>[^>]*</gigya-api>[^>]*<script\s*src="([^"]*)">[^>]*</script>', webpage, 'gigya', default=None)
122 gigya_sc = self._download_webpage(compat_urlparse.urljoin(r'http://www.mitele.es/', gigya_url), video_id, 'Downloading gigya script')
123 # Get a appKey/uuid for getting the session key
124 appKey_var = self._search_regex(r'value\("appGridApplicationKey",([0-9a-f]+)\)', gigya_sc, 'appKey variable')
125 appKey = self._search_regex(r'var %s="([0-9a-f]+)"' % appKey_var, gigya_sc, 'appKey')
126 uid = compat_str(uuid.uuid4())
127 session_url = 'https://appgrid-api.cloud.accedo.tv/session?appKey=%s&uuid=%s' % (appKey, uid)
128 session_json = self._download_json(session_url, video_id, 'Downloading session keys')
129 sessionKey = compat_str(session_json['sessionKey'])
130
131 paths_url = 'https://appgrid-api.cloud.accedo.tv/metadata/general_configuration,%20web_configuration?sessionKey=' + sessionKey
132 paths = self._download_json(paths_url, video_id, 'Downloading paths JSON')
133 ooyala_s = paths['general_configuration']['api_configuration']['ooyala_search']
134 data_p = (
135 'http://' + ooyala_s['base_url'] + ooyala_s['full_path'] + ooyala_s['provider_id'] +
136 '/docs/' + video_id + '?include_titles=Series,Season&product_name=test&format=full')
137 data = self._download_json(data_p, video_id, 'Downloading data JSON')
138 source = data['hits']['hits'][0]['_source']
139 embedCode = source['offers'][0]['embed_codes'][0]
140
141 titles = source['localizable_titles'][0]
142 title = titles.get('title_medium') or titles['title_long']
143 episode = titles['title_sort_name']
144 description = titles['summary_long']
145 titles_series = source['localizable_titles_series'][0]
146 series = titles_series['title_long']
147 titles_season = source['localizable_titles_season'][0]
148 season = titles_season['title_medium']
149 duration = parse_duration(source['videos'][0]['duration'])
150
151 return {
152 '_type': 'url_transparent',
153 # for some reason only HLS is supported
154 'url': smuggle_url('ooyala:' + embedCode, {'supportedformats': 'm3u8'}),
155 'id': video_id,
156 'title': title,
157 'description': description,
158 'series': series,
159 'season': season,
160 'episode': episode,
161 'duration': duration,
162 'thumbnail': source['images'][0]['url'],
163 }