Skip to content

Commit

Permalink
- added an exception for Premium Only videos
Browse files Browse the repository at this point in the history
- release v4.7.4
  • Loading branch information
EchterAlsFake committed Dec 15, 2024
1 parent e1e5c05 commit 0dac461
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/source/api/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ PHUB can raise the following expressions.

.. autoexception:: phub.errors.VideoError

.. autoexception:: phub.errors.RegionBlocked
.. autoexception:: phub.errors.RegionBlocked

.. autoexception:: phub.errors.PremiumVideo
2 changes: 1 addition & 1 deletion docs/source/guides/gui-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GUI Usage
If you want a simpler usage of PHUB, you can check out
EchterAlsFake's `Porn Fetch`_ project.

.. image:: https://github.com/EchterAlsFake/Porn_Fetch/raw/9c634446b097f35d17fcf06e735e184ccd358c60/screenshot.png?raw=true
.. image:: https://github.com/EchterAlsFake/Porn_Fetch/blob/master/src/frontend/screenshots/1.png?raw=true
:width: 600

.. _Porn Fetch: https://github.com/EchterAlsFake/Porn_Fetch
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phub"
version = "4.7.3"
version = "4.7.4"
description = "An API for Pornhub"
authors = [
{name = 'Egsagon', email = "[email protected]"},
Expand Down
2 changes: 2 additions & 0 deletions src/phub/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ class re:
is_video_url = comp( p.fullmatch, _raw_root + r'view_video\.php\?viewkey=(?:ph)?[a-z\d]{3,}(&pkey=\d+)?' ) # Check if a video URL is valid
is_quality = comp( p.fullmatch, r'\d+p?' ) # Check if is a video quality
is_playlist = comp( p.fullmatch, r'^https?:\/\/(?:www\.)?(?:[a-z]{2}\.)?pornhub\.[a-z]{2,3}\/playlist\/\d+$' ) # Checks if it's a playlist
is_premium = comp(p.fullmatch, r'<span class="premium-logo bg-premium-logo straightLogo"')
fixed_title = find(engine.DOTALL, r'(?<="name": ")[^"]+')


# Attach regex names representation to their wrapper for error display purposes
_REGEXES_NAMES = {v.__doc__: k for k, v in vars(re).items() if v.__doc__}

Expand Down
4 changes: 4 additions & 0 deletions src/phub/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ class RegionBlocked(Exception):
This is a problem of PornHub itself and not related to PHUb!
"""

class PremiumVideo(Exception):
"""
Raises when a video is a PornHub premium video.
"""
# EOF
5 changes: 5 additions & 0 deletions src/phub/modules/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ def resolve(video: Video) -> dict:

logger.info('Resolving %s page', video)
region_blocked_regex = re.compile(r'<div\s+id=["\']js-player["\']\s+class=["\']videoGeoUnavailable["\']\s*>')
is_premium = re.compile(r'class="premium-logo bg-premium-logo straightLogo"')

if re.search(region_blocked_regex, video.page):
raise errors.RegionBlocked

if re.search(is_premium, video.page):
raise errors.PremiumVideo("This video is premium only")

flash, ctx = consts.re.get_flash(video.page)

try:
Expand Down

0 comments on commit 0dac461

Please sign in to comment.