Skip to content

Commit

Permalink
- added another exception for videos which are blocked in the users r…
Browse files Browse the repository at this point in the history
…egion
  • Loading branch information
EchterAlsFake committed Jul 11, 2024
1 parent 88f60cb commit 702fa2f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/source/api/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ PHUB can raise the following expressions.
.. autoexception:: phub.errors.InvalidCategory

.. autoexception:: phub.errors.VideoError

.. autoexception:: phub.errors.RegionBlocked
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"
version = "4.7.1"
description = "An API for Pornhub"
authors = [
{name = 'Egsagon', email = "[email protected]"},
Expand Down
7 changes: 7 additions & 0 deletions src/phub/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ class VideoError(Exception):
is not available).
'''


class RegionBlocked(Exception):
"""
Sometimes videos can be blocked in your region.
In this case PHUB can't fetch data.
"""

# EOF
7 changes: 6 additions & 1 deletion src/phub/objects/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ def fetch(self, key: str) -> Any:

if 'message' in data:
logger.warning('Video %s is not available. Error code: %s', self, data.get('code'))
raise errors.VideoError(f'Video is not available. Reason: {data["message"]}')

if data.get('code') == "2002":
raise errors.RegionBlocked("The video is not available in your country.")

else:
raise errors.VideoError(f'Video is not available. Reason: {data["message"]}')

self.data |= {f'data@{k}': v for k, v in data['video'].items()}

Expand Down

0 comments on commit 702fa2f

Please sign in to comment.