]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/medialaan.py
1 from __future__
import unicode_literals
5 from .gigya
import GigyaBaseIE
7 from ..compat
import compat_str
16 class MedialaanIE(GigyaBaseIE
):
21 (?P<site_id>vtm|q2|vtmkzoom)\.be/
23 video(?:/[^/]+/id/|/?\?.*?\baid=)|
29 _NETRC_MACHINE
= 'medialaan'
30 _APIKEY
= '3_HZ0FtkMW_gOyKlqQzW5_0FHRC7Nd5XpXJZcDdXY4pk5eES2ZWmejRW5egwVm4ug-'
34 'vtmkzoom': 'vtmkzoom',
38 'url': 'http://vtm.be/video/volledige-afleveringen/id/vtm_20170219_VM0678361_vtmwatch',
40 'id': 'vtm_20170219_VM0678361_vtmwatch',
42 'title': 'Allemaal Chris afl. 6',
43 'description': 'md5:4be86427521e7b07e0adb0c9c554ddb2',
44 'timestamp': 1487533280,
45 'upload_date': '20170219',
47 'series': 'Allemaal Chris',
48 'season': 'Allemaal Chris',
50 'season_id': '256936078124527',
51 'episode': 'Allemaal Chris afl. 6',
53 'episode_id': '256936078591527',
56 'skip_download': True,
58 'skip': 'Requires account credentials',
61 'url': 'http://vtm.be/video?aid=168332',
65 'title': '"Veronique liegt!"',
66 'description': 'md5:1385e2b743923afe54ba4adc38476155',
67 'timestamp': 1489002029,
68 'upload_date': '20170308',
73 'url': 'http://vtm.be/video/volledige-afleveringen/id/257107153551000',
74 'only_matching': True,
77 'url': 'http://vtm.be/video?aid=163157',
78 'only_matching': True,
81 'url': 'http://www.q2.be/video/volledige-afleveringen/id/2be_20170301_VM0684442_q2',
82 'only_matching': True,
85 'url': 'http://vtmkzoom.be/k3-dansstudio/een-nieuw-seizoen-van-k3-dansstudio',
86 'only_matching': True,
89 'url': 'https://vtmkzoom.be/video?aid=45724',
91 'id': '257136373657000',
93 'title': 'K3 Dansstudio Ushuaia afl.6',
96 'skip_download': True,
98 'skip': 'Requires account credentials',
101 'url': 'https://nieuws.vtm.be/stadion/stadion/genk-nog-moeilijk-programma',
102 'only_matching': True,
105 def _real_initialize(self
):
106 self
._logged
_in
= False
109 username
, password
= self
._get
_login
_info
()
111 self
.raise_login_required()
114 'APIKey': self
._APIKEY
,
118 'password': password
,
121 auth_info
= self
._gigya
_login
(auth_data
)
123 self
._uid
= auth_info
['UID']
124 self
._uid
_signature
= auth_info
['UIDSignature']
125 self
._signature
_timestamp
= auth_info
['signatureTimestamp']
127 self
._logged
_in
= True
129 def _real_extract(self
, url
):
130 mobj
= re
.match(self
._VALID
_URL
, url
)
131 video_id
, site_id
= mobj
.group('id', 'site_id')
133 webpage
= self
._download
_webpage
(url
, video_id
)
135 config
= self
._parse
_json
(
137 r
'videoJSConfig\s*=\s*JSON\.parse\(\'({.+?
})\'\
);',
138 webpage, 'config
', default='{}'), video_id,
139 transform_source=lambda s: s.replace(
140 '\\\\', '\\').replace(r'\"', '"').replace(r"\'", "'"))
142 vod_id = config.get('vodId
') or self._search_regex(
143 (r'\\"vodId\\"\s
*:\s
*\\"(.+?)\\"',
144 r'"vodId"\s
*:\s
*"(.+?)"',
145 r'<[^
>]+id=["\']vod-(\d+)'),
146 webpage, 'video_id', default=None)
148 # clip, no authentication required
150 player = self._parse_json(
152 r'vmmaplayer\(({.+?})\);', webpage, 'vmma player',
154 video_id, transform_source=lambda s: '[%s]' % s, fatal=False)
157 if video['videoUrl'] in ('http', 'https'):
158 return self.url_result(video['url'], MedialaanIE.ie_key())
161 'url': video['videoUrl'],
162 'title': video['title'],
163 'thumbnail': video.get('imageUrl'),
164 'timestamp': int_or_none(video.get('createdDate')),
165 'duration': int_or_none(video.get('duration')),
168 info = self._parse_html5_media_entries(
169 url, webpage, video_id, m3u8_id='hls')[0]
172 'title': self._html_search_meta('description', webpage),
173 'duration': parse_duration(self._html_search_meta('duration', webpage)),
175 # vod, authentication required
177 if not self._logged_in:
180 settings = self._parse_json(
182 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
183 webpage, 'drupal settings', default='{}'),
186 def get(container, item):
188 settings, lambda x: x[container][item],
189 compat_str) or self._search_regex(
190 r'"%s"\s*:\s*"([^
"]+)' % item, webpage, item,
193 app_id = get('vod', 'app_id') or self._SITE_TO_APP_ID.get(site_id, 'vtm_watch')
194 sso = get('vod', 'gigyaDatabase') or 'vtm-sso'
196 data = self._download_json(
197 'http://vod.medialaan.io/api/1.0/item/%s/video' % vod_id,
202 'UIDSignature': self._uid_signature,
203 'signatureTimestamp': self._signature_timestamp,
206 formats = self._extract_m3u8_formats(
207 data['response']['uri'], video_id, entry_protocol='m3u8_native',
208 ext='mp4', m3u8_id='hls')
210 self._sort_formats(formats)
217 api_key = get('vod', 'apiKey')
218 channel = get('medialaanGigya', 'channel')
221 videos = self._download_json(
222 'http://vod.medialaan.io/vod/v2/videos', video_id, fatal=False,
231 videos, lambda x: x['response']['videos'][0], dict)
233 def get(container, item, expected_type=None):
235 video, lambda x: x[container][item], expected_type)
237 def get_string(container, item):
238 return get(container, item, compat_str)
241 'series': get_string('program', 'title'),
242 'season': get_string('season', 'title'),
243 'season_number': int_or_none(get('season', 'number')),
244 'season_id': get_string('season', 'id'),
245 'episode': get_string('episode', 'title'),
246 'episode_number': int_or_none(get('episode', 'number')),
247 'episode_id': get_string('episode', 'id'),
248 'duration': int_or_none(
249 video.get('duration')) or int_or_none(
250 video.get('durationMillis'), scale=1000),
251 'title': get_string('episode', 'title'),
252 'description': get_string('episode', 'text'),
253 'timestamp': unified_timestamp(get_string(
254 'publication', 'begin')),
257 if not info.get('title'):
258 info['title'] = try_get(
259 config, lambda x: x['videoConfig']['title'],
260 compat_str) or self._html_search_regex(
261 r'\\"title
\\"\s*:\s*\\"(.+?
)\\"', webpage, 'title',
262 default=None) or self._og_search_title(webpage)
264 if not info.get('description'):
265 info['description'] = self._html_search_regex(
266 r'<div[^>]+class="field
-item\s
+even
">\s*<p>(.+?)</p>',
267 webpage, 'description', default=None)