pub struct WebshareProxyConfig {
pub proxy_username: String,
pub proxy_password: String,
pub domain_name: String,
pub proxy_port: u16,
pub retries: i32,
}
Expand description
§WebshareProxyConfig
Specialized proxy configuration for Webshare’s rotating residential proxies.
Webshare provides residential proxies that rotate IPs automatically, which is extremely useful for accessing YouTube without being blocked. This configuration is optimized for Webshare’s API format.
§Features
- Automatic IP rotation for each request
- Configurable retry mechanism for handling blocks
- Optimized for Webshare’s proxy service
§Important Note
For reliable YouTube access, use Webshare’s “Residential” proxies, not the “Proxy Server” or “Static Residential” options, as YouTube often blocks those IPs.
§Example Usage
// Create a Webshare proxy configuration with credentials
let proxy = WebshareProxyConfig::new(
"your_username".to_string(),
"your_password".to_string(),
5, // Retry up to 5 times if blocked
None, // Use default domain
None // Use default port
);
// Use it with the YouTube Transcript API
let api = YouTubeTranscriptApi::new(
None,
Some(Box::new(proxy)),
None
)?;
Fields§
§proxy_username: String
Your Webshare proxy username
proxy_password: String
Your Webshare proxy password
domain_name: String
The proxy domain name (default: “p.webshare.io”)
proxy_port: u16
The port number to use (default: 80)
retries: i32
Number of retries to attempt when blocked
Implementations§
Sourcepub const DEFAULT_DOMAIN_NAME: &'static str = "p.webshare.io"
pub const DEFAULT_DOMAIN_NAME: &'static str = "p.webshare.io"
Default domain name for Webshare proxies
Sourcepub const DEFAULT_PORT: u16 = 80u16
pub const DEFAULT_PORT: u16 = 80u16
Default port for Webshare proxies
Sourcepub fn new(
proxy_username: String,
proxy_password: String,
retries_when_blocked: i32,
domain_name: Option<String>,
proxy_port: Option<u16>,
) -> Self
pub fn new( proxy_username: String, proxy_password: String, retries_when_blocked: i32, domain_name: Option<String>, proxy_port: Option<u16>, ) -> Self
Creates a new Webshare proxy configuration.
This configuration is specifically designed for Webshare’s rotating proxy service. It automatically adds the rotation feature to your proxy.
§Parameters
proxy_username
- Your Webshare proxy usernameproxy_password
- Your Webshare proxy passwordretries_when_blocked
- Number of retries to attempt if blocked (recommended: 3-5)domain_name
- Optional custom domain name (default: “p.webshare.io”)proxy_port
- Optional custom port (default: 80)
§Returns
Self
- A new Webshare proxy configuration
§Example
// Basic configuration
let proxy = WebshareProxyConfig::new(
"username".to_string(),
"password".to_string(),
3, // Retry 3 times
None, // Use default domain
None // Use default port
);
// Custom domain and port
let proxy_custom = WebshareProxyConfig::new(
"username".to_string(),
"password".to_string(),
5,
Some("custom.webshare.io".to_string()),
Some(8080)
);
Sourcepub fn url(&self) -> String
pub fn url(&self) -> String
Generates the complete proxy URL for Webshare.
This formats the proxy URL with rotation enabled by appending “-rotate” to the username, which tells Webshare to provide a new IP for each request.
§Returns
String
- The formatted proxy URL
§Example (internal)
let proxy = WebshareProxyConfig::new(
"user123".to_string(),
"pass456".to_string(),
3,
None,
None
);
// Generates: "http://user123-rotate:pass456@p.webshare.io:80/"
let url = proxy.url();
Trait Implementations§
Source§fn clone(&self) -> WebshareProxyConfig
fn clone(&self) -> WebshareProxyConfig
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§fn to_requests_dict(&self) -> HashMap<String, String>
fn to_requests_dict(&self) -> HashMap<String, String>
Converts the Webshare proxy configuration to a reqwest-compatible dictionary.
Uses the same URL for both HTTP and HTTPS requests.
§Returns
HashMap<String, String>
- Map with “http” and “https” keys and proxy URLs
Source§fn prevent_keeping_connections_alive(&self) -> bool
fn prevent_keeping_connections_alive(&self) -> bool
Always returns true
to ensure connection rotation.
Webshare rotating proxies work best when a new connection is established for each request, ensuring you get a fresh IP address each time.
§Returns
bool
- Alwaystrue
for Webshare proxies
Source§fn retries_when_blocked(&self) -> i32
fn retries_when_blocked(&self) -> i32
Returns the configured number of retries.
This determines how many times the library will retry a request with a new IP address if YouTube blocks the request.
§Returns
i32
- The number of retries to attempt