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