]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/youjizz.py
[cleanup] Use `_html_extract_title`
[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_extract_title(webpage)
40
41 formats = []
42
43 encodings = self._parse_json(
44 self._search_regex(
45 r'[Ee]ncodings\s*=\s*(\[.+?\]);\n', webpage, 'encodings',
46 default='[]'),
47 video_id, fatal=False)
48 for encoding in encodings:
49 if not isinstance(encoding, dict):
50 continue
51 format_url = url_or_none(encoding.get('filename'))
52 if not format_url:
53 continue
54 if determine_ext(format_url) == 'm3u8':
55 formats.extend(self._extract_m3u8_formats(
56 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
57 m3u8_id='hls', fatal=False))
58 else:
59 format_id = encoding.get('name') or encoding.get('quality')
60 height = int_or_none(self._search_regex(
61 r'^(\d+)[pP]', format_id, 'height', default=None))
62 formats.append({
63 'url': format_url,
64 'format_id': format_id,
65 'height': height,
66 })
67
68 if formats:
69 info_dict = {
70 'formats': formats,
71 }
72 else:
73 # YouJizz's HTML5 player has invalid HTML
74 webpage = webpage.replace('"controls', '" controls')
75 info_dict = self._parse_html5_media_entries(
76 url, webpage, video_id)[0]
77
78 duration = parse_duration(self._search_regex(
79 r'<strong>Runtime:</strong>([^<]+)', webpage, 'duration',
80 default=None))
81 uploader = self._search_regex(
82 r'<strong>Uploaded By:.*?<a[^>]*>([^<]+)', webpage, 'uploader',
83 default=None)
84
85 info_dict.update({
86 'id': video_id,
87 'title': title,
88 'age_limit': self._rta_search(webpage),
89 'duration': duration,
90 'uploader': uploader,
91 })
92
93 return info_dict