Skip to content

Commit

Permalink
- fixed an issue with forced title changes which would prevent webmas…
Browse files Browse the repository at this point in the history
…ters API from being used making the API extremely slow at some features

- fixed an issue with the hosts of the other pornhub domain languages which would stop model and search functions from working, raising a client.call failed error
- (maybe) fixed an issue with thumbnails
  • Loading branch information
EchterAlsFake committed Nov 18, 2024
1 parent cb0234e commit a7964a2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
22 changes: 11 additions & 11 deletions src/phub/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@
# Supported languages
LANGUAGES = [ 'en', 'cn', 'de', 'fr', 'it', 'pt', 'pl', 'rt', 'nl', 'cz', 'jp' ]
LANGUAGE_MAPPING = {
"en": "www.pornhub.com",
"cn": "www.cn.pornhub.com",
"de": "www.de.pornhub.org",
"fr": "www.fr.pornhub.com",
"it": "www.it.pornhub.com",
"pt": "www.pt.pornhub.com",
"pl": "www.pl.pornhub.com",
"rt": "www.rt.pornhub.com",
"nl": "www.nl.pornhub.com",
"cz": "www.cz.pornhub.com",
"jp": "www.jp.pornhub.com"}
"en": "https://pornhub.com",
"cn": "https://cn.pornhub.com",
"de": "https://de.pornhub.org",
"fr": "https://fr.pornhub.com",
"it": "https://it.pornhub.com",
"pt": "https://pt.pornhub.com",
"pl": "https://pl.pornhub.com",
"rt": "https://rt.pornhub.com",
"nl": "https://nl.pornhub.com",
"cz": "https://cz.pornhub.com",
"jp": "https://jp.pornhub.com"}

GEO_BYPASS_IPs = [
"185.238.219.36",
Expand Down
9 changes: 4 additions & 5 deletions src/phub/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class Client:
Represents a client capable of handling requests
with Pornhub.
'''

use_webmaster_api = True

def __init__(self,
email: str = None,
password: str = None,
Expand Down Expand Up @@ -61,10 +62,10 @@ def __init__(self,
logger.debug('Initialised new Client %s', self)

# Initialise session
Client.use_webmaster_api = use_webmaster_api
self.language = language
self.change_title_language = change_title_language
self.bypass_geo_blocking = bypass_geo_blocking
self.use_webmaster_api = use_webmaster_api

self.reset()

Expand Down Expand Up @@ -160,7 +161,6 @@ def call(self,
host = consts.HOST

url = func if 'http' in func else utils.concat(host, func)

for i in range(consts.MAX_CALL_RETRIES):
try:
response = self.session.request(
Expand Down Expand Up @@ -281,8 +281,7 @@ def get(self, video: Union[str, Video]) -> Video:

url = utils.concat(consts.HOST, 'view_video.php?viewkey=' + key)

return Video(self, url, change_title_language=self.change_title_language,
use_webmaster_api=self.use_webmaster_api)
return Video(self, url, change_title_language=self.change_title_language)

def get_user(self, user: Union[str, User]) -> User:
'''
Expand Down
2 changes: 0 additions & 2 deletions src/phub/objects/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ def _parse_item(self, data: dict) -> Video:
def _parse_page(self, raw: str) -> list[dict]:

data = json.loads(raw)

videos = data.get('videos')

if data.get('code') == '2001':
raise errors.NoResult()

Expand Down
11 changes: 4 additions & 7 deletions src/phub/objects/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class Video:

# === Base methods === #

def __init__(self, client: Client, url: str, change_title_language: bool = True,
use_webmaster_api: bool = True) -> None:
def __init__(self, client: Client, url: str, change_title_language: bool = False) -> None:
'''
Initialise a new video object.
Expand All @@ -44,9 +43,8 @@ def __init__(self, client: Client, url: str, change_title_language: bool = True,
raise errors.URLError('Invalid video URL:', url)

self.client = client

self.change_titles = change_title_language
self.use_webmaster_api = use_webmaster_api
self.use_webmaster_api = self.client.use_webmaster_api
self.url = url
self.key = consts.re.get_viewkey(url)
self.data: dict = {} # The video webmasters data
Expand All @@ -64,6 +62,7 @@ def __init__(self, client: Client, url: str, change_title_language: bool = True,
self.ALLOW_QUERY_SIMULATION = False

logger.debug('Initialised new video object %s', self)
logger.debug(f"Video data: {self.data}")

def __repr__(self) -> str:

Expand Down Expand Up @@ -454,9 +453,7 @@ def image(self) -> Image:
'''
The video thumbnail.
'''

url = self.data.get('page@image_url')

url = self.data.get('page@image_url') or self.data.get('data@thumb')
if url:
servers = None

Expand Down

0 comments on commit a7964a2

Please sign in to comment.