1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_str
17 class MedialaanIE(InfoExtractor):
22 (?P<site_id>vtm|q2|vtmkzoom)\.be/
24 video(?:/[^/]+/id/|/?\?.*?\baid=)|
30 _NETRC_MACHINE = 'medialaan'
31 _APIKEY = '3_HZ0FtkMW_gOyKlqQzW5_0FHRC7Nd5XpXJZcDdXY4pk5eES2ZWmejRW5egwVm4ug-'
35 'vtmkzoom': 'vtmkzoom',
39 'url': 'http://vtm.be/video/volledige-afleveringen/id/vtm_20170219_VM0678361_vtmwatch',
41 'id': 'vtm_20170219_VM0678361_vtmwatch',
43 'title': 'Allemaal Chris afl. 6',
44 'description': 'md5:4be86427521e7b07e0adb0c9c554ddb2',
45 'timestamp': 1487533280,
46 'upload_date': '20170219',
48 'series': 'Allemaal Chris',
49 'season': 'Allemaal Chris',
51 'season_id': '256936078124527',
52 'episode': 'Allemaal Chris afl. 6',
54 'episode_id': '256936078591527',
57 'skip_download': True,
59 'skip': 'Requires account credentials',
62 'url': 'http://vtm.be/video?aid=168332',
66 'title': '"Veronique liegt!"',
67 'description': 'md5:1385e2b743923afe54ba4adc38476155',
68 'timestamp': 1489002029,
69 'upload_date': '20170308',
74 'url': 'http://vtm.be/video/volledige-afleveringen/id/257107153551000',
75 'only_matching': True,
78 'url': 'http://vtm.be/video?aid=163157',
79 'only_matching': True,
82 'url': 'http://www.q2.be/video/volledige-afleveringen/id/2be_20170301_VM0684442_q2',
83 'only_matching': True,
86 'url': 'http://vtmkzoom.be/k3-dansstudio/een-nieuw-seizoen-van-k3-dansstudio',
87 'only_matching': True,
90 def _real_initialize(self):
91 self._logged_in = False
94 username, password = self._get_login_info()
96 self.raise_login_required()
99 'APIKey': self._APIKEY,
103 'password': password,
106 auth_info = self._download_json(
107 'https://accounts.eu1.gigya.com/accounts.login', None,
108 note='Logging in', errnote='Unable to log in',
109 data=urlencode_postdata(auth_data))
111 error_message = auth_info.get('errorDetails') or auth_info.get('errorMessage')
113 raise ExtractorError(
114 'Unable to login: %s' % error_message, expected=True)
116 self._uid = auth_info['UID']
117 self._uid_signature = auth_info['UIDSignature']
118 self._signature_timestamp = auth_info['signatureTimestamp']
120 self._logged_in = True
122 def _real_extract(self, url):
123 mobj = re.match(self._VALID_URL, url)
124 video_id, site_id = mobj.group('id', 'site_id')
126 webpage = self._download_webpage(url, video_id)
128 config = self._parse_json(
130 r'videoJSConfig\s*=\s*JSON\.parse\(\'({.+?})\'\);',
131 webpage, 'config', default='{}'), video_id,
132 transform_source=lambda s: s.replace(
133 '\\\\', '\\').replace(r'\"', '"').replace(r"\'", "'"))
135 vod_id = config.get('vodId') or self._search_regex(
136 (r'\\"vodId\\"\s*:\s*\\"(.+?)\\"',
137 r'<[^>]+id=["\']vod-(\d+)'),
138 webpage, 'video_id', default=None)
140 # clip, no authentication required
142 player = self._parse_json(
144 r'vmmaplayer\(({.+?})\);', webpage, 'vmma player',
146 video_id, transform_source=lambda s: '[%s]' % s, fatal=False)
151 'url': video['videoUrl'],
152 'title': video['title'],
153 'thumbnail': video.get('imageUrl'),
154 'timestamp': int_or_none(video.get('createdDate')),
155 'duration': int_or_none(video.get('duration')),
158 info = self._parse_html5_media_entries(
159 url, webpage, video_id, m3u8_id='hls')[0]
162 'title': self._html_search_meta('description', webpage),
163 'duration': parse_duration(self._html_search_meta('duration', webpage)),
165 # vod, authentication required
167 if not self._logged_in:
170 settings = self._parse_json(
172 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
173 webpage, 'drupal settings', default='{}'),
176 def get(container, item):
178 settings, lambda x: x[container][item],
179 compat_str) or self._search_regex(
180 r'"%s"\s*:\s*"([^"]+)' % item, webpage, item,
183 app_id = get('vod', 'app_id') or self._SITE_TO_APP_ID.get(site_id, 'vtm_watch')
184 sso = get('vod', 'gigyaDatabase') or 'vtm-sso'
186 data = self._download_json(
187 'http://vod.medialaan.io/api/1.0/item/%s/video' % vod_id,
192 'UIDSignature': self._uid_signature,
193 'signatureTimestamp': self._signature_timestamp,
196 formats = self._extract_m3u8_formats(
197 data['response']['uri'], video_id, entry_protocol='m3u8_native',
198 ext='mp4', m3u8_id='hls')
200 self._sort_formats(formats)
207 api_key = get('vod', 'apiKey')
208 channel = get('medialaanGigya', 'channel')
211 videos = self._download_json(
212 'http://vod.medialaan.io/vod/v2/videos', video_id, fatal=False,
221 videos, lambda x: x['response']['videos'][0], dict)
223 def get(container, item, expected_type=None):
225 video, lambda x: x[container][item], expected_type)
227 def get_string(container, item):
228 return get(container, item, compat_str)
231 'series': get_string('program', 'title'),
232 'season': get_string('season', 'title'),
233 'season_number': int_or_none(get('season', 'number')),
234 'season_id': get_string('season', 'id'),
235 'episode': get_string('episode', 'title'),
236 'episode_number': int_or_none(get('episode', 'number')),
237 'episode_id': get_string('episode', 'id'),
238 'duration': int_or_none(
239 video.get('duration')) or int_or_none(
240 video.get('durationMillis'), scale=1000),
241 'title': get_string('episode', 'title'),
242 'description': get_string('episode', 'text'),
243 'timestamp': unified_timestamp(get_string(
244 'publication', 'begin')),
247 if not info.get('title'):
248 info['title'] = try_get(
249 config, lambda x: x['videoConfig']['title'],
250 compat_str) or self._html_search_regex(
251 r'\\"title\\"\s*:\s*\\"(.+?)\\"', webpage, 'title',
252 default=None) or self._og_search_title(webpage)
254 if not info.get('description'):
255 info['description'] = self._html_search_regex(
256 r'<div[^>]+class="field-item\s+even">\s*<p>(.+?)</p>',
257 webpage, 'description', default=None)