diff --git a/docs/source/api/errors.rst b/docs/source/api/errors.rst index 0a23890..e025fc9 100644 --- a/docs/source/api/errors.rst +++ b/docs/source/api/errors.rst @@ -24,3 +24,5 @@ PHUB can raise the following expressions. .. autoexception:: phub.errors.InvalidCategory .. autoexception:: phub.errors.VideoError + +.. autoexception:: phub.errors.RegionBlocked \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a208ba6..b942f6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "phub" -version = "4.7" +version = "4.7.1" description = "An API for Pornhub" authors = [ {name = 'Egsagon', email = "egsagon.git@gmail.com"}, diff --git a/src/phub/errors.py b/src/phub/errors.py index f6aa477..5c6d025 100644 --- a/src/phub/errors.py +++ b/src/phub/errors.py @@ -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 \ No newline at end of file diff --git a/src/phub/objects/video.py b/src/phub/objects/video.py index d2b0659..8f9a722 100644 --- a/src/phub/objects/video.py +++ b/src/phub/objects/video.py @@ -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()}