2 from __future__ import unicode_literals
8 from .common import InfoExtractor
11 # compat_urllib_parse_unquote,
12 # compat_urllib_parse_unquote_plus,
13 # compat_urllib_parse_urlparse,
28 class PornHubIE(InfoExtractor):
29 IE_DESC = 'PornHub and Thumbzilla'
33 (?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)|
34 (?:www\.)?thumbzilla\.com/video/
39 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
40 'md5': '1e19b41231a02eba417839222ac9d58e',
44 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
57 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
62 'uploader': 'cj397186295',
73 'skip_download': True,
76 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
77 'only_matching': True,
79 # removed at the request of cam4.com
80 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
81 'only_matching': True,
83 # removed at the request of the copyright owner
84 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
85 'only_matching': True,
88 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
89 'only_matching': True,
92 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
93 'only_matching': True,
95 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
96 'only_matching': True,
100 def _extract_urls(webpage):
102 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/[\da-z]+)',
105 def _extract_count(self, pattern, webpage, name):
106 return str_to_int(self._search_regex(
107 pattern, webpage, '%s count' % name, fatal=False))
109 def _real_extract(self, url):
110 video_id = self._match_id(url)
112 def dl_webpage(platform):
113 return self._download_webpage(
114 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id,
116 'Cookie': 'age_verified=1; platform=%s' % platform,
119 webpage = dl_webpage('pc')
121 error_msg = self._html_search_regex(
122 r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
123 webpage, 'error message', default=None, group='error')
125 error_msg = re.sub(r'\s+', ' ', error_msg)
126 raise ExtractorError(
127 'PornHub said: %s' % error_msg,
128 expected=True, video_id=video_id)
130 tv_webpage = dl_webpage('tv')
132 video_url = self._search_regex(
133 r'<video[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//.+?)\1', tv_webpage,
134 'video url', group='url')
136 title = self._search_regex(
137 r'<h1>([^>]+)</h1>', tv_webpage, 'title', default=None)
139 # video_title from flashvars contains whitespace instead of non-ASCII (see
140 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
142 title = title or self._html_search_meta(
143 'twitter:title', webpage, default=None) or self._search_regex(
144 (r'<h1[^>]+class=["\']title["\'][^>]*>(?P<title>[^<]+)',
145 r'<div[^>]+data-video-title=(["\'])(?P<title>.+?)\1',
146 r'shareTitle\s*=\s*(["\'])(?P<title>.+?)\1'),
147 webpage, 'title', group='title')
149 flashvars = self._parse_json(
151 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
154 thumbnail = flashvars.get('image_url')
155 duration = int_or_none(flashvars.get('video_duration'))
157 title, thumbnail, duration = [None] * 3
159 video_uploader = self._html_search_regex(
160 r'(?s)From: .+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
161 webpage, 'uploader', fatal=False)
163 view_count = self._extract_count(
164 r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
165 like_count = self._extract_count(
166 r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
167 dislike_count = self._extract_count(
168 r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
169 comment_count = self._extract_count(
170 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
172 page_params = self._parse_json(self._search_regex(
173 r'page_params\.zoneDetails\[([\'"])[^\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
174 webpage, 'page parameters', group='data', default='{}'),
175 video_id, transform_source=js_to_json, fatal=False)
176 tags = categories = None
178 tags = page_params.get('tags', '').split(',')
179 categories = page_params.get('categories', '').split(',')
184 'uploader': video_uploader,
186 'thumbnail': thumbnail,
187 'duration': duration,
188 'view_count': view_count,
189 'like_count': like_count,
190 'dislike_count': dislike_count,
191 'comment_count': comment_count,
192 # 'formats': formats,
195 'categories': categories,
199 class PornHubPlaylistBaseIE(InfoExtractor):
200 def _extract_entries(self, webpage):
203 'http://www.pornhub.com/%s' % video_url,
204 PornHubIE.ie_key(), video_title=title)
205 for video_url, title in orderedSet(re.findall(
206 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
210 def _real_extract(self, url):
211 playlist_id = self._match_id(url)
213 webpage = self._download_webpage(url, playlist_id)
215 # Only process container div with main playlist content skipping
216 # drop-down menu that uses similar pattern for videos (see
217 # https://github.com/rg3/youtube-dl/issues/11594).
218 container = self._search_regex(
219 r'(?s)(<div[^>]+class=["\']container.+)', webpage,
220 'container', default=webpage)
222 entries = self._extract_entries(container)
224 playlist = self._parse_json(
226 r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
229 return self.playlist_result(
230 entries, playlist_id, playlist.get('title'), playlist.get('description'))
233 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
234 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
236 'url': 'http://www.pornhub.com/playlist/4667351',
239 'title': 'Nataly Hot',
241 'playlist_mincount': 2,
245 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
246 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
248 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
252 'playlist_mincount': 171,
254 'url': 'http://www.pornhub.com/users/rushandlia/videos',
255 'only_matching': True,
258 def _real_extract(self, url):
259 user_id = self._match_id(url)
262 for page_num in itertools.count(1):
264 webpage = self._download_webpage(
265 url, user_id, 'Downloading page %d' % page_num,
266 query={'page': page_num})
267 except ExtractorError as e:
268 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
270 page_entries = self._extract_entries(webpage)
273 entries.extend(page_entries)
275 return self.playlist_result(entries, user_id)