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