Skip to content

Commit

Permalink
Merge pull request #62 from EchterAlsFake/domain_language_fix
Browse files Browse the repository at this point in the history
- fixing the subdomain URLs to use www.pornhub.com/org format
  • Loading branch information
EchterAlsFake authored Aug 12, 2024
2 parents 8c21c55 + 9964f71 commit 0f8a6a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/phub/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def call(self,
ConnectionError: If the request was blocked by Pornhub.
HTTPError: If the request failed, for any reason.
'''

func = utils.fix_url(func)
logger.log(logging.DEBUG if silent else logging.INFO, 'Fetching %s', func or '/')

# Delay mechanism
Expand Down
1 change: 1 addition & 0 deletions src/phub/objects/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, client: Client, url: str, change_title_language: bool = True,
url (str): The video URL.
'''

url = utils.fix_url(url)
if not consts.re.is_video_url(url):
raise errors.URLError('Invalid video URL:', url)

Expand Down
21 changes: 20 additions & 1 deletion src/phub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Generator, Iterable, Iterator, Union

from . import errors
from . import consts

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -242,4 +243,22 @@ def head(client: object, url: str) -> Union[str, bool]:
return res.url
return False

# EOF

def fix_url(url: str):
"""
Changes a URL which includes the specific language site of PornHub to the default www.pornhub.com/org format,
so that PornHub respects the accept-language header, so that we can apply our own custom language into the Client.
Args:
url: (str): The video URL to be changed
Returns:
str: The video URL without the language site.
"""

for language, root_url in consts.LANGUAGE_MAPPING.items():
if f"{language}.pornhub" in url:
url = url.replace(language, "www", 1)
return url

return url # Sometimes URL doesn't need to be changed. In this case, just return it.

0 comments on commit 0f8a6a8

Please sign in to comment.