]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/youjizz.py
[youtube:comments] Add more options for limiting number of comments extracted (#1626)
[yt-dlp.git] / yt_dlp / extractor / youjizz.py
CommitLineData
0b76600d
JMF
1from __future__ import unicode_literals
2
a0a477b8 3
c3c77cec 4from .common import InfoExtractor
a0a477b8
S
5from ..utils import (
6 determine_ext,
7 int_or_none,
8 parse_duration,
3052a30d 9 url_or_none,
a0a477b8 10)
c3c77cec
PH
11
12
13class YouJizzIE(InfoExtractor):
a0a477b8 14 _VALID_URL = r'https?://(?:\w+\.)?youjizz\.com/videos/(?:[^/#?]*-(?P<id>\d+)\.html|embed/(?P<embed_id>\d+))'
84e8cca4 15 _TESTS = [{
0b76600d 16 'url': 'http://www.youjizz.com/videos/zeichentrick-1-2189178.html',
a0a477b8 17 'md5': 'b1e1dfaa8bb9537d8b84eeda9cf4acf4',
0b76600d 18 'info_dict': {
28465df1 19 'id': '2189178',
45aab4d3 20 'ext': 'mp4',
611c1dd9
S
21 'title': 'Zeichentrick 1',
22 'age_limit': 18,
a0a477b8 23 'duration': 2874,
6f5ac90c 24 }
84e8cca4
S
25 }, {
26 'url': 'http://www.youjizz.com/videos/-2189178.html',
27 'only_matching': True,
a0a477b8
S
28 }, {
29 'url': 'https://www.youjizz.com/videos/embed/31991001',
30 'only_matching': True,
84e8cca4 31 }]
c3c77cec
PH
32
33 def _real_extract(self, url):
5ad28e7f 34 mobj = self._match_valid_url(url)
a0a477b8
S
35 video_id = mobj.group('id') or mobj.group('embed_id')
36
c3c77cec 37 webpage = self._download_webpage(url, video_id)
28465df1 38
a0a477b8
S
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(
886d9859 46 r'[Ee]ncodings\s*=\s*(\[.+?\]);\n', webpage, 'encodings',
a0a477b8
S
47 default='[]'),
48 video_id, fatal=False)
49 for encoding in encodings:
50 if not isinstance(encoding, dict):
51 continue
3052a30d
S
52 format_url = url_or_none(encoding.get('filename'))
53 if not format_url:
a0a477b8
S
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)
c3c77cec 85
45aab4d3 86 info_dict.update({
0b76600d 87 'id': video_id,
a0a477b8
S
88 'title': title,
89 'age_limit': self._rta_search(webpage),
90 'duration': duration,
91 'uploader': uploader,
45aab4d3
YCH
92 })
93
94 return info_dict