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