1 from __future__ import unicode_literals
6 from .common import InfoExtractor
8 compat_urllib_parse_unquote,
9 compat_urllib_parse_unquote_plus,
10 compat_urllib_parse_urlparse,
24 class PornHubIE(InfoExtractor):
25 _VALID_URL = r'https?://(?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)(?P<id>[0-9a-z]+)'
27 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
28 'md5': '1e19b41231a02eba417839222ac9d58e',
32 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
42 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
43 'only_matching': True,
45 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
46 'only_matching': True,
50 def _extract_url(cls, webpage):
52 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/\d+)\1', webpage)
54 return mobj.group('url')
56 def _extract_count(self, pattern, webpage, name):
57 return str_to_int(self._search_regex(
58 pattern, webpage, '%s count' % name, fatal=False))
60 def _real_extract(self, url):
61 video_id = self._match_id(url)
63 req = sanitized_Request(
64 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id)
65 req.add_header('Cookie', 'age_verified=1')
66 webpage = self._download_webpage(req, video_id)
68 error_msg = self._html_search_regex(
69 r'(?s)<div class="userMessageSection[^"]*".*?>(.*?)</div>',
70 webpage, 'error message', default=None)
72 error_msg = re.sub(r'\s+', ' ', error_msg)
74 'PornHub said: %s' % error_msg,
75 expected=True, video_id=video_id)
77 flashvars = self._parse_json(
79 r'var\s+flashv1ars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
82 video_title = flashvars.get('video_title')
83 thumbnail = flashvars.get('image_url')
84 duration = int_or_none(flashvars.get('video_duration'))
86 video_title, thumbnail, duration = [None] * 3
89 video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
91 video_uploader = self._html_search_regex(
92 r'(?s)From: .+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
93 webpage, 'uploader', fatal=False)
95 view_count = self._extract_count(
96 r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
97 like_count = self._extract_count(
98 r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
99 dislike_count = self._extract_count(
100 r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
101 comment_count = self._extract_count(
102 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
104 video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^']+)'", webpage)))
105 if webpage.find('"encrypted":true') != -1:
106 password = compat_urllib_parse_unquote_plus(
107 self._search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
108 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
111 for video_url in video_urls:
112 path = compat_urllib_parse_urlparse(video_url).path
113 extension = os.path.splitext(path)[1][1:]
114 format = path.split('/')[5].split('_')[:2]
115 format = '-'.join(format)
117 m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
122 height = int(m.group('height'))
123 tbr = int(m.group('tbr'))
133 self._sort_formats(formats)
137 'uploader': video_uploader,
138 'title': video_title,
139 'thumbnail': thumbnail,
140 'duration': duration,
141 'view_count': view_count,
142 'like_count': like_count,
143 'dislike_count': dislike_count,
144 'comment_count': comment_count,
150 class PornHubPlaylistBaseIE(InfoExtractor):
151 def _extract_entries(self, webpage):
153 self.url_result('http://www.pornhub.com/%s' % video_url, PornHubIE.ie_key())
154 for video_url in orderedSet(re.findall(
155 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"', webpage))
158 def _real_extract(self, url):
159 playlist_id = self._match_id(url)
161 webpage = self._download_webpage(url, playlist_id)
163 entries = self._extract_entries(webpage)
165 playlist = self._parse_json(
167 r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
170 return self.playlist_result(
171 entries, playlist_id, playlist.get('title'), playlist.get('description'))
174 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
175 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
177 'url': 'http://www.pornhub.com/playlist/6201671',
182 'playlist_mincount': 35,
186 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
187 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
189 'url': 'http://www.pornhub.com/users/rushandlia/videos',
193 'playlist_mincount': 13,
196 def _real_extract(self, url):
197 user_id = self._match_id(url)
199 webpage = self._download_webpage(url, user_id)
201 return self.playlist_result(self._extract_entries(webpage), user_id)