1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_str
14 from ..aes import aes_decrypt_text
17 class YouPornIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?youporn\.com/watch/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
20 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
21 'md5': '3744d24c50438cf5b6f6d59feb5055c2',
24 'display_id': 'sex-ed-is-it-safe-to-masturbate-daily',
26 'title': 'Sex Ed: Is It Safe To Masturbate Daily?',
27 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?',
28 'thumbnail': r're:^https?://.*\.jpg$',
29 'uploader': 'Ask Dan And Jennifer',
30 'upload_date': '20101217',
31 'average_rating': int,
40 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4',
43 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show',
45 'title': 'Big Tits Awesome Brunette On amazing webcam show',
46 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4',
47 'thumbnail': r're:^https?://.*\.jpg$',
48 'uploader': 'Unknown',
49 'upload_date': '20110418',
50 'average_rating': int,
58 'skip_download': True,
62 def _real_extract(self, url):
63 mobj = re.match(self._VALID_URL, url)
64 video_id = mobj.group('id')
65 display_id = mobj.group('display_id')
67 request = sanitized_Request(url)
68 request.add_header('Cookie', 'age_verified=1')
69 webpage = self._download_webpage(request, display_id)
71 title = self._search_regex(
72 [r'(?:video_titles|videoTitle)\s*[:=]\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
73 r'<h1[^>]+class=["\']heading\d?["\'][^>]*>(?P<title>[^<]+)<'],
74 webpage, 'title', group='title',
75 default=None) or self._og_search_title(
76 webpage, default=None) or self._html_search_meta(
77 'title', webpage, fatal=True)
82 definitions = self._parse_json(
84 r'mediaDefinition\s*=\s*(\[.+?\]);', webpage,
85 'media definitions', default='[]'),
86 video_id, fatal=False)
88 for definition in definitions:
89 if not isinstance(definition, dict):
91 video_url = definition.get('videoUrl')
92 if isinstance(video_url, compat_str) and video_url:
93 links.append(video_url)
95 # Fallback #1, this also contains extra low quality 180p format
96 for _, link in re.findall(r'<a[^>]+href=(["\'])(http.+?)\1[^>]+title=["\']Download [Vv]ideo', webpage):
99 # Fallback #2 (unavailable as at 22.06.2017)
100 sources = self._search_regex(
101 r'(?s)sources\s*:\s*({.+?})', webpage, 'sources', default=None)
103 for _, link in re.findall(r'[^:]+\s*:\s*(["\'])(http.+?)\1', sources):
106 # Fallback #3 (unavailable as at 22.06.2017)
107 for _, link in re.findall(
108 r'(?:videoSrc|videoIpadUrl|html5PlayerSrc)\s*[:=]\s*(["\'])(http.+?)\1', webpage):
111 # Fallback #4, encrypted links (unavailable as at 22.06.2017)
112 for _, encrypted_link in re.findall(
113 r'encryptedQuality\d{3,4}URL\s*=\s*(["\'])([\da-zA-Z+/=]+)\1', webpage):
114 links.append(aes_decrypt_text(encrypted_link, title, 32).decode('utf-8'))
117 for video_url in set(unescapeHTML(link) for link in links):
121 # Video URL's path looks like this:
122 # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
123 # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
124 # We will benefit from it by extracting some metadata
125 mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+/', video_url)
127 height = int(mobj.group('height'))
128 bitrate = int(mobj.group('bitrate'))
130 'format_id': '%dp-%dk' % (height, bitrate),
135 self._sort_formats(formats)
137 description = self._og_search_description(webpage, default=None)
138 thumbnail = self._search_regex(
139 r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1',
140 webpage, 'thumbnail', fatal=False, group='thumbnail')
142 uploader = self._html_search_regex(
143 r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>',
144 webpage, 'uploader', fatal=False)
145 upload_date = unified_strdate(self._html_search_regex(
146 [r'Date\s+[Aa]dded:\s*<span>([^<]+)',
147 r'(?s)<div[^>]+class=["\']videoInfo(?:Date|Time)["\'][^>]*>(.+?)</div>'],
148 webpage, 'upload date', fatal=False))
150 age_limit = self._rta_search(webpage)
152 average_rating = int_or_none(self._search_regex(
153 r'<div[^>]+class=["\']videoRatingPercentage["\'][^>]*>(\d+)%</div>',
154 webpage, 'average rating', fatal=False))
156 view_count = str_to_int(self._search_regex(
157 r'(?s)<div[^>]+class=(["\']).*?\bvideoInfoViews\b.*?\1[^>]*>.*?(?P<count>[\d,.]+)<',
158 webpage, 'view count', fatal=False, group='count'))
159 comment_count = str_to_int(self._search_regex(
160 r'>All [Cc]omments? \(([\d,.]+)\)',
161 webpage, 'comment count', fatal=False))
163 def extract_tag_box(regex, title):
164 tag_box = self._search_regex(regex, webpage, title, default=None)
167 return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box)
169 categories = extract_tag_box(
170 r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories')
171 tags = extract_tag_box(
172 r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>',
177 'display_id': display_id,
179 'description': description,
180 'thumbnail': thumbnail,
181 'uploader': uploader,
182 'upload_date': upload_date,
183 'average_rating': average_rating,
184 'view_count': view_count,
185 'comment_count': comment_count,
186 'categories': categories,
188 'age_limit': age_limit,