Release 2024.12.03
[yt-dlp3.git] / yt_dlp / extractor / youjizz.py
blobf7ef222c279c475b2fcf9376f2d1f406cdc372be
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 parse_duration,
6 url_or_none,
10 class YouJizzIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:\w+\.)?youjizz\.com/videos/(?:[^/#?]*-(?P<id>\d+)\.html|embed/(?P<embed_id>\d+))'
12 _TESTS = [{
13 'url': 'http://www.youjizz.com/videos/zeichentrick-1-2189178.html',
14 'md5': 'b1e1dfaa8bb9537d8b84eeda9cf4acf4',
15 'info_dict': {
16 'id': '2189178',
17 'ext': 'mp4',
18 'title': 'Zeichentrick 1',
19 'age_limit': 18,
20 'duration': 2874,
22 }, {
23 'url': 'http://www.youjizz.com/videos/-2189178.html',
24 'only_matching': True,
25 }, {
26 'url': 'https://www.youjizz.com/videos/embed/31991001',
27 'only_matching': True,
30 def _real_extract(self, url):
31 mobj = self._match_valid_url(url)
32 video_id = mobj.group('id') or mobj.group('embed_id')
34 webpage = self._download_webpage(url, video_id)
36 title = self._html_extract_title(webpage)
38 formats = []
40 encodings = self._parse_json(
41 self._search_regex(
42 r'[Ee]ncodings\s*=\s*(\[.+?\]);\n', webpage, 'encodings',
43 default='[]'),
44 video_id, fatal=False)
45 for encoding in encodings:
46 if not isinstance(encoding, dict):
47 continue
48 format_url = url_or_none(encoding.get('filename'))
49 if not format_url:
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,
65 if formats:
66 info_dict = {
67 'formats': formats,
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]
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)
82 info_dict.update({
83 'id': video_id,
84 'title': title,
85 'age_limit': self._rta_search(webpage),
86 'duration': duration,
87 'uploader': uploader,
90 return info_dict