]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/vidzi.py
[cleanup] Upgrade syntax
[yt-dlp.git] / yt_dlp / extractor / vidzi.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 decode_packed_codes,
6 js_to_json,
7 NO_DEFAULT,
8 PACKED_CODES_RE,
9 )
10
11
12 class VidziIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?vidzi\.(?:tv|cc|si|nu)/(?:embed-)?(?P<id>[0-9a-zA-Z]+)'
14 _TESTS = [{
15 'url': 'http://vidzi.tv/cghql9yq6emu.html',
16 'md5': '4f16c71ca0c8c8635ab6932b5f3f1660',
17 'info_dict': {
18 'id': 'cghql9yq6emu',
19 'ext': 'mp4',
20 'title': 'youtube-dl test video 1\\\\2\'3/4<5\\\\6ä7↭',
21 },
22 'params': {
23 # m3u8 download
24 'skip_download': True,
25 },
26 }, {
27 'url': 'http://vidzi.tv/embed-4z2yb0rzphe9-600x338.html',
28 'only_matching': True,
29 }, {
30 'url': 'http://vidzi.cc/cghql9yq6emu.html',
31 'only_matching': True,
32 }, {
33 'url': 'https://vidzi.si/rph9gztxj1et.html',
34 'only_matching': True,
35 }, {
36 'url': 'http://vidzi.nu/cghql9yq6emu.html',
37 'only_matching': True,
38 }]
39
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
42
43 webpage = self._download_webpage(
44 'http://vidzi.tv/%s' % video_id, video_id)
45 title = self._html_search_regex(
46 r'(?s)<h2 class="video-title">(.*?)</h2>', webpage, 'title')
47
48 codes = [webpage]
49 codes.extend([
50 decode_packed_codes(mobj.group(0)).replace('\\\'', '\'')
51 for mobj in re.finditer(PACKED_CODES_RE, webpage)])
52 for num, code in enumerate(codes, 1):
53 jwplayer_data = self._parse_json(
54 self._search_regex(
55 r'setup\(([^)]+)\)', code, 'jwplayer data',
56 default=NO_DEFAULT if num == len(codes) else '{}'),
57 video_id, transform_source=lambda s: js_to_json(
58 re.sub(r'\s*\+\s*window\[.+?\]', '', s)))
59 if jwplayer_data:
60 break
61
62 info_dict = self._parse_jwplayer_data(jwplayer_data, video_id, require_title=False)
63 info_dict['title'] = title
64
65 return info_dict