Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion youtube_transcript_api/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ def url(self) -> str:
location_codes = "".join(
f"-{location_code.upper()}" for location_code in self._filter_ip_locations
)
username = self.proxy_username
suffix = "-rotate"
if username.endswith(suffix):
username = username[: -len(suffix)]
return (
f"http://{self.proxy_username}{location_codes}-rotate:{self.proxy_password}"
f"http://{username}{location_codes}{suffix}:{self.proxy_password}"
f"@{self.domain_name}:{self.proxy_port}/"
)

Expand Down
12 changes: 12 additions & 0 deletions youtube_transcript_api/test/test_proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ def test_to_requests_dict__with_multiple_location_filters(self):
"http": "http://user-DE-US-rotate:password@p.webshare.io:80/",
"https": "http://user-DE-US-rotate:password@p.webshare.io:80/",
}

def test_to_requests_dict__with_rotate_suffix_in_username(self):
proxy_config = WebshareProxyConfig(
proxy_username="user-rotate", proxy_password="password"
)

request_dict = proxy_config.to_requests_dict()

assert request_dict == {
"http": "http://user-rotate:password@p.webshare.io:80/",
"https": "http://user-rotate:password@p.webshare.io:80/",
}