]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vidzi.py
[elpais] Fix typo and improve extraction (closes #12139)
[yt-dlp.git] / youtube_dl / extractor / vidzi.py
CommitLineData
5f6a1245 1# coding: utf-8
018e8355
PH
2from __future__ import unicode_literals
3
2b96b06b
S
4import re
5
8f4a2124
YCH
6from .jwplatform import JWPlatformBaseIE
7from ..utils import (
efbd6fb8 8 decode_packed_codes,
8f4a2124 9 js_to_json,
2b96b06b
S
10 NO_DEFAULT,
11 PACKED_CODES_RE,
8f4a2124 12)
018e8355 13
8f4a2124
YCH
14
15class VidziIE(JWPlatformBaseIE):
5c4dcf81
S
16 _VALID_URL = r'https?://(?:www\.)?vidzi\.tv/(?:embed-)?(?P<id>[0-9a-zA-Z]+)'
17 _TESTS = [{
2c26df76
PH
18 'url': 'http://vidzi.tv/cghql9yq6emu.html',
19 'md5': '4f16c71ca0c8c8635ab6932b5f3f1660',
95ee8442 20 'info_dict': {
2c26df76 21 'id': 'cghql9yq6emu',
95ee8442 22 'ext': 'mp4',
2c26df76 23 'title': 'youtube-dl test video 1\\\\2\'3/4<5\\\\6ä7↭',
bd93a12e
YCH
24 },
25 'params': {
26 # m3u8 download
27 'skip_download': True,
95ee8442 28 },
5c4dcf81
S
29 }, {
30 'url': 'http://vidzi.tv/embed-4z2yb0rzphe9-600x338.html',
31 'skip_download': True,
32 }]
95ee8442 33
34 def _real_extract(self, url):
018e8355 35 video_id = self._match_id(url)
5f6a1245 36
5c4dcf81
S
37 webpage = self._download_webpage(
38 'http://vidzi.tv/%s' % video_id, video_id)
018e8355 39 title = self._html_search_regex(
2c26df76 40 r'(?s)<h2 class="video-title">(.*?)</h2>', webpage, 'title')
5f6a1245 41
2b96b06b
S
42 packed_codes = [mobj.group(0) for mobj in re.finditer(
43 PACKED_CODES_RE, webpage)]
44 for num, pc in enumerate(packed_codes, 1):
45 code = decode_packed_codes(pc).replace('\\\'', '\'')
46 jwplayer_data = self._parse_json(
47 self._search_regex(
48 r'setup\(([^)]+)\)', code, 'jwplayer data',
49 default=NO_DEFAULT if num == len(packed_codes) else '{}'),
50 video_id, transform_source=js_to_json)
51 if jwplayer_data:
52 break
8f4a2124
YCH
53
54 info_dict = self._parse_jwplayer_data(jwplayer_data, video_id, require_title=False)
55 info_dict['title'] = title
56
57 return info_dict