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