]>
Commit | Line | Data |
---|---|---|
0b76600d JMF |
1 | from __future__ import unicode_literals |
2 | ||
a0a477b8 S |
3 | import re |
4 | ||
c3c77cec | 5 | from .common import InfoExtractor |
a0a477b8 S |
6 | from ..compat import compat_str |
7 | from ..utils import ( | |
8 | determine_ext, | |
9 | int_or_none, | |
10 | parse_duration, | |
11 | ) | |
c3c77cec PH |
12 | |
13 | ||
14 | class YouJizzIE(InfoExtractor): | |
a0a477b8 | 15 | _VALID_URL = r'https?://(?:\w+\.)?youjizz\.com/videos/(?:[^/#?]*-(?P<id>\d+)\.html|embed/(?P<embed_id>\d+))' |
84e8cca4 | 16 | _TESTS = [{ |
0b76600d | 17 | 'url': 'http://www.youjizz.com/videos/zeichentrick-1-2189178.html', |
a0a477b8 | 18 | 'md5': 'b1e1dfaa8bb9537d8b84eeda9cf4acf4', |
0b76600d | 19 | 'info_dict': { |
28465df1 | 20 | 'id': '2189178', |
45aab4d3 | 21 | 'ext': 'mp4', |
611c1dd9 S |
22 | 'title': 'Zeichentrick 1', |
23 | 'age_limit': 18, | |
a0a477b8 | 24 | 'duration': 2874, |
6f5ac90c | 25 | } |
84e8cca4 S |
26 | }, { |
27 | 'url': 'http://www.youjizz.com/videos/-2189178.html', | |
28 | 'only_matching': True, | |
a0a477b8 S |
29 | }, { |
30 | 'url': 'https://www.youjizz.com/videos/embed/31991001', | |
31 | 'only_matching': True, | |
84e8cca4 | 32 | }] |
c3c77cec PH |
33 | |
34 | def _real_extract(self, url): | |
a0a477b8 S |
35 | mobj = re.match(self._VALID_URL, url) |
36 | video_id = mobj.group('id') or mobj.group('embed_id') | |
37 | ||
c3c77cec | 38 | webpage = self._download_webpage(url, video_id) |
28465df1 | 39 | |
a0a477b8 S |
40 | title = self._html_search_regex( |
41 | r'<title>(.+?)</title>', webpage, 'title') | |
42 | ||
43 | formats = [] | |
44 | ||
45 | encodings = self._parse_json( | |
46 | self._search_regex( | |
47 | r'encodings\s*=\s*(\[.+?\]);\n', webpage, 'encodings', | |
48 | default='[]'), | |
49 | video_id, fatal=False) | |
50 | for encoding in encodings: | |
51 | if not isinstance(encoding, dict): | |
52 | continue | |
53 | format_url = encoding.get('filename') | |
54 | if not isinstance(format_url, compat_str): | |
55 | continue | |
56 | if determine_ext(format_url) == 'm3u8': | |
57 | formats.extend(self._extract_m3u8_formats( | |
58 | format_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
59 | m3u8_id='hls', fatal=False)) | |
60 | else: | |
61 | format_id = encoding.get('name') or encoding.get('quality') | |
62 | height = int_or_none(self._search_regex( | |
63 | r'^(\d+)[pP]', format_id, 'height', default=None)) | |
64 | formats.append({ | |
65 | 'url': format_url, | |
66 | 'format_id': format_id, | |
67 | 'height': height, | |
68 | }) | |
69 | ||
70 | if formats: | |
71 | info_dict = { | |
72 | 'formats': formats, | |
73 | } | |
74 | else: | |
75 | # YouJizz's HTML5 player has invalid HTML | |
76 | webpage = webpage.replace('"controls', '" controls') | |
77 | info_dict = self._parse_html5_media_entries( | |
78 | url, webpage, video_id)[0] | |
79 | ||
80 | duration = parse_duration(self._search_regex( | |
81 | r'<strong>Runtime:</strong>([^<]+)', webpage, 'duration', | |
82 | default=None)) | |
83 | uploader = self._search_regex( | |
84 | r'<strong>Uploaded By:.*?<a[^>]*>([^<]+)', webpage, 'uploader', | |
85 | default=None) | |
c3c77cec | 86 | |
45aab4d3 | 87 | info_dict.update({ |
0b76600d | 88 | 'id': video_id, |
a0a477b8 S |
89 | 'title': title, |
90 | 'age_limit': self._rta_search(webpage), | |
91 | 'duration': duration, | |
92 | 'uploader': uploader, | |
45aab4d3 YCH |
93 | }) |
94 | ||
95 | return info_dict |