-# coding: utf-8
-from __future__ import unicode_literals
-
import functools
import itertools
import math
import re
from .common import InfoExtractor
-from ..compat import (
- compat_HTTPError,
- compat_str,
- compat_urllib_request,
-)
from .openload import PhantomJSwrapper
+from ..networking import Request
+from ..networking.exceptions import HTTPError
from ..utils import (
+ NO_DEFAULT,
+ ExtractorError,
clean_html,
determine_ext,
- ExtractorError,
+ format_field,
int_or_none,
merge_dicts,
- NO_DEFAULT,
orderedSet,
remove_quotes,
+ remove_start,
str_to_int,
update_url_query,
- urlencode_postdata,
url_or_none,
+ urlencode_postdata,
)
class PornHubBaseIE(InfoExtractor):
_NETRC_MACHINE = 'pornhub'
- _PORNHUB_HOST_RE = r'(?:(?P<host>pornhub(?:premium)?\.(?:com|net|org))|pornhubthbh7ap3u\.onion)'
+ _PORNHUB_HOST_RE = r'(?:(?P<host>pornhub(?:premium)?\.(?:com|net|org))|pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd\.onion)'
def _download_webpage_handle(self, *args, **kwargs):
def dl(*args, **kwargs):
r'document\.cookie\s*=\s*["\']RNKEY=',
r'document\.location\.reload\(true\)')):
url_or_request = args[0]
- url = (url_or_request.get_full_url()
- if isinstance(url_or_request, compat_urllib_request.Request)
+ url = (url_or_request.url
+ if isinstance(url_or_request, Request)
else url_or_request)
phantom = PhantomJSwrapper(self, required_version='2.0')
phantom.get(url, html=webpage)
def _real_initialize(self):
self._logged_in = False
+ def _set_age_cookies(self, host):
+ self._set_cookie(host, 'age_verified', '1')
+ self._set_cookie(host, 'accessAgeDisclaimerPH', '1')
+ self._set_cookie(host, 'accessAgeDisclaimerUK', '1')
+ self._set_cookie(host, 'accessPH', '1')
+
def _login(self, host):
if self._logged_in:
return
if username is None:
return
- login_url = 'https://www.%s/%slogin' % (host, 'premium/' if 'premium' in host else '')
+ login_url = 'https://www.{}/{}login'.format(host, 'premium/' if 'premium' in host else '')
login_page = self._download_webpage(
- login_url, None, 'Downloading %s login page' % site)
+ login_url, None, f'Downloading {site} login page')
def is_logged(webpage):
return any(re.search(p, webpage) for p in (
- r'class=["\']signOut',
- r'>Sign\s+[Oo]ut\s*<'))
+ r'id="profileMenuDropdown"',
+ r'class="ph-icon-logout"'))
if is_logged(login_page):
self._logged_in = True
login_form = self._hidden_inputs(login_page)
login_form.update({
- 'username': username,
+ 'email': username,
'password': password,
})
response = self._download_json(
- 'https://www.%s/front/authenticate' % host, None,
- 'Logging in to %s' % site,
+ f'https://www.{host}/front/authenticate', None,
+ f'Logging in to {site}',
data=urlencode_postdata(login_form),
headers={
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
message = response.get('message')
if message is not None:
raise ExtractorError(
- 'Unable to login: %s' % message, expected=True)
+ f'Unable to login: {message}', expected=True)
raise ExtractorError('Unable to log in')
class PornHubIE(PornHubBaseIE):
IE_DESC = 'PornHub and Thumbzilla'
- _VALID_URL = r'''(?x)
+ _VALID_URL = rf'''(?x)
https?://
(?:
(?:[^/]+\.)?
- %s
+ {PornHubBaseIE._PORNHUB_HOST_RE}
/(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
(?:www\.)?thumbzilla\.com/video/
)
(?P<id>[\da-z]+)
- ''' % PornHubBaseIE._PORNHUB_HOST_RE
+ '''
+ _EMBED_REGEX = [r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub(?:premium)?\.(?:com|net|org)/embed/[\da-z]+)']
_TESTS = [{
'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
'md5': 'a6391306d050e4547f62b3f485dd9ba9',
'categories': list,
'subtitles': {
'en': [{
- "ext": 'srt'
- }]
+ 'ext': 'srt',
+ }],
},
},
'params': {
'skip_download': True,
},
'skip': 'This video has been disabled',
+ }, {
+ 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph601dc30bae19a',
+ 'info_dict': {
+ 'id': 'ph601dc30bae19a',
+ 'uploader': 'Projekt Melody',
+ 'uploader_id': 'projekt-melody',
+ 'upload_date': '20210205',
+ 'title': '"Welcome to My Pussy Mansion" - CB Stream (02/03/21)',
+ 'thumbnail': r're:https?://.+',
+ },
}, {
'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
'only_matching': True,
'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5a9813bfa7156',
'only_matching': True,
}, {
- 'url': 'http://pornhubthbh7ap3u.onion/view_video.php?viewkey=ph5a9813bfa7156',
+ 'url': 'http://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/view_video.php?viewkey=ph5a9813bfa7156',
'only_matching': True,
}]
- @staticmethod
- def _extract_urls(webpage):
- return re.findall(
- r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub(?:premium)?\.(?:com|net|org)/embed/[\da-z]+)',
- webpage)
-
def _extract_count(self, pattern, webpage, name):
- return str_to_int(self._search_regex(
- pattern, webpage, '%s count' % name, fatal=False))
+ return str_to_int(self._search_regex(pattern, webpage, f'{name} count', default=None))
def _real_extract(self, url):
mobj = self._match_valid_url(url)
video_id = mobj.group('id')
self._login(host)
-
- self._set_cookie(host, 'age_verified', '1')
+ self._set_age_cookies(host)
def dl_webpage(platform):
self._set_cookie(host, 'platform', platform)
return self._download_webpage(
- 'https://www.%s/view_video.php?viewkey=%s' % (host, video_id),
- video_id, 'Downloading %s webpage' % platform)
+ f'https://www.{host}/view_video.php?viewkey={video_id}',
+ video_id, f'Downloading {platform} webpage')
webpage = dl_webpage('pc')
if error_msg:
error_msg = re.sub(r'\s+', ' ', error_msg)
raise ExtractorError(
- 'PornHub said: %s' % error_msg,
+ f'PornHub said: {error_msg}',
expected=True, video_id=video_id)
if any(re.search(p, webpage) for p in (
if not isinstance(definition, dict):
continue
video_url = definition.get('videoUrl')
- if not video_url or not isinstance(video_url, compat_str):
+ if not video_url or not isinstance(video_url, str):
continue
if video_url in video_urls_set:
continue
if not video_urls:
FORMAT_PREFIXES = ('media', 'quality', 'qualityItems')
js_vars = extract_js_vars(
- webpage, r'(var\s+(?:%s)_.+)' % '|'.join(FORMAT_PREFIXES),
+ webpage, r'(var\s+(?:{})_.+)'.format('|'.join(FORMAT_PREFIXES)),
default=None)
if js_vars:
for key, format_url in js_vars.items():
if not video_urls and re.search(
r'<[^>]+\bid=["\']lockedPlayer', webpage):
raise ExtractorError(
- 'Video %s is locked' % video_id, expected=True)
+ f'Video {video_id} is locked', expected=True)
if not video_urls:
js_vars = extract_js_vars(
default=None))
formats.append({
'url': format_url,
- 'format_id': '%dp' % height if height else None,
+ 'format_id': format_field(height, None, '%dp'),
'height': height,
})
continue
add_format(video_url)
- # field_preference is unnecessary here, but kept for code-similarity with youtube-dl
- self._sort_formats(
- formats, field_preference=('height', 'width', 'fps', 'format_id'))
-
+ model_profile = self._search_json(
+ r'var\s+MODEL_PROFILE\s*=', webpage, 'model profile', video_id, fatal=False)
video_uploader = self._html_search_regex(
r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?:(?:user|channel)s|model|pornstar)/|span\b[^>]+\bclass=["\']username)[^>]+>(.+?)<',
- webpage, 'uploader', default=None)
+ webpage, 'uploader', default=None) or model_profile.get('username')
def extract_vote_count(kind, name):
return self._extract_count(
- (r'<span[^>]+\bclass="votes%s"[^>]*>([\d,\.]+)</span>' % kind,
- r'<span[^>]+\bclass=["\']votes%s["\'][^>]*\bdata-rating=["\'](\d+)' % kind),
+ (rf'<span[^>]+\bclass="votes{kind}"[^>]*>([\d,\.]+)</span>',
+ rf'<span[^>]+\bclass=["\']votes{kind}["\'][^>]*\bdata-rating=["\'](\d+)'),
webpage, name)
view_count = self._extract_count(
def extract_list(meta_key):
div = self._search_regex(
- r'(?s)<div[^>]+\bclass=["\'].*?\b%sWrapper[^>]*>(.+?)</div>'
- % meta_key, webpage, meta_key, default=None)
+ rf'(?s)<div[^>]+\bclass=["\'].*?\b{meta_key}Wrapper[^>]*>(.+?)</div>',
+ webpage, meta_key, default=None)
if div:
return [clean_html(x).strip() for x in re.findall(r'(?s)<a[^>]+\bhref=[^>]+>.+?</a>', div)]
return merge_dicts({
'id': video_id,
'uploader': video_uploader,
+ 'uploader_id': remove_start(model_profile.get('modelProfileLink'), '/model/'),
'upload_date': upload_date,
'title': title,
'thumbnail': thumbnail,
return [
self.url_result(
- 'http://www.%s/%s' % (host, video_url),
+ f'http://www.{host}/{video_url}',
PornHubIE.ie_key(), video_title=title)
for video_url, title in orderedSet(re.findall(
r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
class PornHubUserIE(PornHubPlaylistBaseIE):
- _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?%s/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/?#&]+))(?:[?#&]|/(?!videos)|$)' % PornHubBaseIE._PORNHUB_HOST_RE
+ _VALID_URL = rf'(?P<url>https?://(?:[^/]+\.)?{PornHubBaseIE._PORNHUB_HOST_RE}/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/?#&]+))(?:[?#&]|/(?!videos)|$)'
_TESTS = [{
'url': 'https://www.pornhub.com/model/zoe_ph',
'playlist_mincount': 118,
'url': 'https://www.pornhubpremium.com/pornstar/lily-labeau',
'only_matching': True,
}, {
- 'url': 'https://pornhubthbh7ap3u.onion/model/zoe_ph',
+ 'url': 'https://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/model/zoe_ph',
'only_matching': True,
}]
def _real_extract(self, url):
mobj = self._match_valid_url(url)
user_id = mobj.group('id')
- videos_url = '%s/videos' % mobj.group('url')
+ videos_url = '{}/videos'.format(mobj.group('url'))
+ self._set_age_cookies(mobj.group('host'))
page = self._extract_page(url)
if page:
videos_url = update_url_query(videos_url, {'page': page})
VIDEOS = '/videos'
def download_page(base_url, num, fallback=False):
- note = 'Downloading page %d%s' % (num, ' (switch to fallback)' if fallback else '')
+ note = 'Downloading page {}{}'.format(num, ' (switch to fallback)' if fallback else '')
return self._download_webpage(
base_url, item_id, note, query={'page': num})
def is_404(e):
- return isinstance(e.cause, compat_HTTPError) and e.cause.code == 404
+ return isinstance(e.cause, HTTPError) and e.cause.status == 404
base_url = url
has_page = page is not None
item_id = mobj.group('id')
self._login(host)
+ self._set_age_cookies(host)
return self.playlist_result(self._entries(url, host, item_id), item_id)
class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
- _VALID_URL = r'https?://(?:[^/]+\.)?%s/(?!playlist/)(?P<id>(?:[^/]+/)*[^/?#&]+)' % PornHubBaseIE._PORNHUB_HOST_RE
+ _VALID_URL = rf'https?://(?:[^/]+\.)?{PornHubBaseIE._PORNHUB_HOST_RE}/(?!playlist/)(?P<id>(?:[^/]+/)*[^/?#&]+)'
_TESTS = [{
'url': 'https://www.pornhub.com/model/zoe_ph/videos',
'only_matching': True,
'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
'only_matching': True,
}, {
- 'url': 'https://pornhubthbh7ap3u.onion/model/zoe_ph/videos',
+ 'url': 'https://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/model/zoe_ph/videos',
'only_matching': True,
}]
def suitable(cls, url):
return (False
if PornHubIE.suitable(url) or PornHubUserIE.suitable(url) or PornHubUserVideosUploadIE.suitable(url)
- else super(PornHubPagedVideoListIE, cls).suitable(url))
+ else super().suitable(url))
class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
- _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?%s/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)' % PornHubBaseIE._PORNHUB_HOST_RE
+ _VALID_URL = rf'(?P<url>https?://(?:[^/]+\.)?{PornHubBaseIE._PORNHUB_HOST_RE}/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)'
_TESTS = [{
'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
'info_dict': {
'url': 'https://www.pornhub.com/model/zoe_ph/videos/upload',
'only_matching': True,
}, {
- 'url': 'http://pornhubthbh7ap3u.onion/pornstar/jenny-blighe/videos/upload',
+ 'url': 'http://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/pornstar/jenny-blighe/videos/upload',
'only_matching': True,
}]
class PornHubPlaylistIE(PornHubPlaylistBaseIE):
- _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?%s/playlist/(?P<id>[^/?#&]+))' % PornHubBaseIE._PORNHUB_HOST_RE
+ _VALID_URL = rf'(?P<url>https?://(?:[^/]+\.)?{PornHubBaseIE._PORNHUB_HOST_RE}/playlist/(?P<id>[^/?#&]+))'
_TESTS = [{
'url': 'https://www.pornhub.com/playlist/44121572',
'info_dict': {
page_entries = self._extract_entries(webpage, host)
def download_page(page_num):
- note = 'Downloading page {}'.format(page_num)
- page_url = 'https://www.{}/playlist/viewChunked'.format(host)
+ note = f'Downloading page {page_num}'
+ page_url = f'https://www.{host}/playlist/viewChunked'
return self._download_webpage(page_url, item_id, note, query={
'id': playlist_id,
'page': page_num,
page_entries = self._extract_entries(webpage, host)
if not page_entries:
break
- for e in page_entries:
- yield e
+ yield from page_entries
def _real_extract(self, url):
mobj = self._match_valid_url(url)
item_id = mobj.group('id')
self._login(host)
+ self._set_age_cookies(host)
return self.playlist_result(self._entries(mobj.group('url'), host, item_id), item_id)