Skip to content

Commit 988c847

Browse files
committed
- fixed proxy support
1 parent 768acd0 commit 988c847

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

docs/source/guides/pkg-usage.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ You can switch with: `use_webmaster_api = True` or False.
3636
3737
client = phub.Client(language = 'de')
3838
39+
40+
41+
42+
Proxy support is also possible, but only SOCKS5 protocol is supported. You need to apply the proxy in the
43+
format "socks5://<ip>:<port>" and set it in the consts file. Here's an example:
44+
45+
.. code-block:: python
46+
import phub
47+
phub.consts.PROXY = "socks5://187.133.7.42:420"
48+
client = phub.Client() # This client has proxies enabled
49+
50+
NOTE:
51+
52+
There absolutely NO guarantee that this feature is perfectly functional. Your IP could always be leaked.
53+
3954
Fetching a video
4055
----------------
4156

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "phub"
3-
version = "4.7.6"
3+
version = "4.7.7"
44
description = "An API for Pornhub"
55
authors = [
66
{name = 'Egsagon', email = "[email protected]"},

src/phub/consts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
RSS = 'https://www.pornhub.com/video/webmasterss'
3939

4040
PROXY = None
41-
# Example Proxy dictionary:
42-
# {"http://": "http://4.20.69.42:1337"}
41+
# Needs to be a SOCKS5 in the format: "socks5://<host>:<port>"
4342

4443

4544
MAX_CALL_RETRIES = 4 # Maximum times a HTTPError can be reproduced
4645
MAX_CALL_TIMEOUT = .4 # Time to wait before retrying basic calls
4746
CALL_TIMEOUT = 30 # Time to wait before retrying calls (in case no error happens)
4847
CHALLENGE_TIMEOUT = 2 # Time to wait before injecting the new cookie for resolving the challenge (needs to be at least 1)
48+
DELAY = 0 # Minimum time between requests
4949

5050
DOWNLOAD_SEGMENT_MAX_ATTEMPS = 5
5151
DOWNLOAD_SEGMENT_ERROR_DELAY = .5

src/phub/core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def __init__(self,
3535
password: str = None,
3636
*,
3737
language: literals.language = 'en',
38-
delay: Union[int, float] = 0,
3938
login: bool = True,
4039
bypass_geo_blocking: bool = False,
4140
change_title_language: bool = True,
@@ -47,7 +46,6 @@ def __init__(self,
4746
email (str): Account email address.
4847
password (str): Account password.
4948
language (str): Client language (fr, en, ru, etc.)
50-
delay (int | float): Minimum delay between requests.
5149
login (bool): Whether to directly log in after initialization.
5250
bypass_geo_blocking (bool): Whether to bypass geo-blocking.
5351
change_title_language (bool): Whether to change title language into your language based on the input URL
@@ -71,7 +69,7 @@ def __init__(self,
7169
self.credentials = {'email': email,
7270
'password': password}
7371

74-
self.delay = delay
72+
self.delay = consts.DELAY
7573
self.start_delay = False
7674
self.last_request_time = None
7775

@@ -90,13 +88,17 @@ def reset(self) -> None:
9088
This is useful if you are keeping the client running
9189
for a long time and can help with Pornhub rate limit.
9290
'''
91+
verify = True
92+
if consts.PROXY is not None:
93+
verify = False
9394

9495
# Initialise session
9596
self.session = httpx.Client(
9697
headers = consts.HEADERS,
9798
cookies = consts.COOKIES,
9899
follow_redirects = True,
99-
proxies = consts.PROXY)
100+
proxy = consts.PROXY,
101+
verify = verify)
100102

101103
self._clear_granted_token()
102104

0 commit comments

Comments
 (0)