]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/youporn.py
[cbs] Add support for ParamountPlus (#138)
[yt-dlp.git] / yt_dlp / extractor / youporn.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 int_or_none,
8 str_to_int,
9 unescapeHTML,
10 unified_strdate,
11 url_or_none,
12 )
13 from ..aes import aes_decrypt_text
14
15
16 class YouPornIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?youporn\.com/(?:watch|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
18 _TESTS = [{
19 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
20 'md5': '3744d24c50438cf5b6f6d59feb5055c2',
21 'info_dict': {
22 'id': '505835',
23 'display_id': 'sex-ed-is-it-safe-to-masturbate-daily',
24 'ext': 'mp4',
25 'title': 'Sex Ed: Is It Safe To Masturbate Daily?',
26 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'duration': 210,
29 'uploader': 'Ask Dan And Jennifer',
30 'upload_date': '20101217',
31 'average_rating': int,
32 'view_count': int,
33 'categories': list,
34 'tags': list,
35 'age_limit': 18,
36 },
37 }, {
38 # Unknown uploader
39 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4',
40 'info_dict': {
41 'id': '561726',
42 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show',
43 'ext': 'mp4',
44 'title': 'Big Tits Awesome Brunette On amazing webcam show',
45 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4',
46 'thumbnail': r're:^https?://.*\.jpg$',
47 'uploader': 'Unknown',
48 'upload_date': '20110418',
49 'average_rating': int,
50 'view_count': int,
51 'categories': list,
52 'tags': list,
53 'age_limit': 18,
54 },
55 'params': {
56 'skip_download': True,
57 },
58 'skip': '404',
59 }, {
60 'url': 'https://www.youporn.com/embed/505835/sex-ed-is-it-safe-to-masturbate-daily/',
61 'only_matching': True,
62 }, {
63 'url': 'http://www.youporn.com/watch/505835',
64 'only_matching': True,
65 }, {
66 'url': 'https://www.youporn.com/watch/13922959/femdom-principal/',
67 'only_matching': True,
68 }]
69
70 @staticmethod
71 def _extract_urls(webpage):
72 return re.findall(
73 r'<iframe[^>]+\bsrc=["\']((?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)',
74 webpage)
75
76 def _real_extract(self, url):
77 mobj = re.match(self._VALID_URL, url)
78 video_id = mobj.group('id')
79 display_id = mobj.group('display_id') or video_id
80
81 webpage = self._download_webpage(
82 'http://www.youporn.com/watch/%s' % video_id, display_id,
83 headers={'Cookie': 'age_verified=1'})
84
85 title = self._html_search_regex(
86 r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>',
87 webpage, 'title', default=None) or self._og_search_title(
88 webpage, default=None) or self._html_search_meta(
89 'title', webpage, fatal=True)
90
91 links = []
92
93 # Main source
94 definitions = self._parse_json(
95 self._search_regex(
96 r'mediaDefinition\s*[=:]\s*(\[.+?\])\s*[;,]', webpage,
97 'media definitions', default='[]'),
98 video_id, fatal=False)
99 if definitions:
100 for definition in definitions:
101 if not isinstance(definition, dict):
102 continue
103 video_url = url_or_none(definition.get('videoUrl'))
104 if video_url:
105 links.append(video_url)
106
107 # Fallback #1, this also contains extra low quality 180p format
108 for _, link in re.findall(r'<a[^>]+href=(["\'])(http(?:(?!\1).)+\.mp4(?:(?!\1).)*)\1[^>]+title=["\']Download [Vv]ideo', webpage):
109 links.append(link)
110
111 # Fallback #2 (unavailable as at 22.06.2017)
112 sources = self._search_regex(
113 r'(?s)sources\s*:\s*({.+?})', webpage, 'sources', default=None)
114 if sources:
115 for _, link in re.findall(r'[^:]+\s*:\s*(["\'])(http.+?)\1', sources):
116 links.append(link)
117
118 # Fallback #3 (unavailable as at 22.06.2017)
119 for _, link in re.findall(
120 r'(?:videoSrc|videoIpadUrl|html5PlayerSrc)\s*[:=]\s*(["\'])(http.+?)\1', webpage):
121 links.append(link)
122
123 # Fallback #4, encrypted links (unavailable as at 22.06.2017)
124 for _, encrypted_link in re.findall(
125 r'encryptedQuality\d{3,4}URL\s*=\s*(["\'])([\da-zA-Z+/=]+)\1', webpage):
126 links.append(aes_decrypt_text(encrypted_link, title, 32).decode('utf-8'))
127
128 formats = []
129 for video_url in set(unescapeHTML(link) for link in links):
130 f = {
131 'url': video_url,
132 }
133 # Video URL's path looks like this:
134 # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
135 # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
136 # /videos/201703/11/109285532/1080P_4000K_109285532.mp4
137 # We will benefit from it by extracting some metadata
138 mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url)
139 if mobj:
140 height = int(mobj.group('height'))
141 bitrate = int(mobj.group('bitrate'))
142 f.update({
143 'format_id': '%dp-%dk' % (height, bitrate),
144 'height': height,
145 'tbr': bitrate,
146 })
147 formats.append(f)
148 self._sort_formats(formats)
149
150 description = self._html_search_regex(
151 r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>',
152 webpage, 'description',
153 default=None) or self._og_search_description(
154 webpage, default=None)
155 thumbnail = self._search_regex(
156 r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1',
157 webpage, 'thumbnail', fatal=False, group='thumbnail')
158 duration = int_or_none(self._html_search_meta(
159 'video:duration', webpage, 'duration', fatal=False))
160
161 uploader = self._html_search_regex(
162 r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>',
163 webpage, 'uploader', fatal=False)
164 upload_date = unified_strdate(self._html_search_regex(
165 [r'UPLOADED:\s*<span>([^<]+)',
166 r'Date\s+[Aa]dded:\s*<span>([^<]+)',
167 r'(?s)<div[^>]+class=["\']videoInfo(?:Date|Time)["\'][^>]*>(.+?)</div>'],
168 webpage, 'upload date', fatal=False))
169
170 age_limit = self._rta_search(webpage)
171
172 average_rating = int_or_none(self._search_regex(
173 r'<div[^>]+class=["\']videoRatingPercentage["\'][^>]*>(\d+)%</div>',
174 webpage, 'average rating', fatal=False))
175
176 view_count = str_to_int(self._search_regex(
177 r'(?s)<div[^>]+class=(["\']).*?\bvideoInfoViews\b.*?\1[^>]*>.*?(?P<count>[\d,.]+)<',
178 webpage, 'view count', fatal=False, group='count'))
179 comment_count = str_to_int(self._search_regex(
180 r'>All [Cc]omments? \(([\d,.]+)\)',
181 webpage, 'comment count', default=None))
182
183 def extract_tag_box(regex, title):
184 tag_box = self._search_regex(regex, webpage, title, default=None)
185 if not tag_box:
186 return []
187 return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box)
188
189 categories = extract_tag_box(
190 r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories')
191 tags = extract_tag_box(
192 r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>',
193 'tags')
194
195 return {
196 'id': video_id,
197 'display_id': display_id,
198 'title': title,
199 'description': description,
200 'thumbnail': thumbnail,
201 'duration': duration,
202 'uploader': uploader,
203 'upload_date': upload_date,
204 'average_rating': average_rating,
205 'view_count': view_count,
206 'comment_count': comment_count,
207 'categories': categories,
208 'tags': tags,
209 'age_limit': age_limit,
210 'formats': formats,
211 }