o
    jìEié  ã                   @   sx   d dl mZmZ d dlmZmZmZ G dd„ deƒZG dd„ deƒZ	G dd„ deƒZ
G d	d
„ d
e
ƒZG dd„ deƒZdS )é    )ÚABCÚabstractmethod)Ú	TypedDictÚOptionalÚListc                   @   s   e Zd ZdS )ÚInvalidProxyConfigN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú[/var/www/agentarbitrage/venv/lib/python3.10/site-packages/youtube_transcript_api/proxies.pyr      s    r   c                   @   s"   e Zd ZU dZeed< eed< dS )ÚRequestsProxyConfigDicta  
    This type represents the Dict that is used by the requests library to configure
    the proxies used. More information on this can be found in the official requests
    documentation: https://requests.readthedocs.io/en/latest/user/advanced/#proxies
    ÚhttpÚhttpsN)r   r	   r
   Ú__doc__ÚstrÚ__annotations__r   r   r   r   r   	   s   
 r   c                   @   sF   e Zd ZdZedefdd„ƒZedefdd„ƒZ	ede
fdd„ƒZd	S )
ÚProxyConfigz°
    The base class for all proxy configs. Anything can be a proxy config, as longs as
    it can be turned into a `RequestsProxyConfigDict` by calling `to_requests_dict`.
    Úreturnc                 C   ó   dS )a   
        Turns this proxy config into the Dict that is expected by the requests library.
        More information on this can be found in the official requests documentation:
        https://requests.readthedocs.io/en/latest/user/advanced/#proxies
        Nr   ©Úselfr   r   r   Úto_requests_dict   ó   zProxyConfig.to_requests_dictc                 C   r   )zá
        If you are using rotating proxies, it can be useful to prevent the HTTP
        client from keeping TCP connections alive, as your IP won't be rotated on
        every request, if your connection stays open.
        Fr   r   r   r   r   Ú!prevent_keeping_connections_alive#   r   z-ProxyConfig.prevent_keeping_connections_alivec                 C   r   )aE  
        Defines how many times we should retry if a request is blocked. When using
        rotating residential proxies with a large IP pool it can make sense to retry a
        couple of times when a blocked IP is encountered, since a retry will trigger
        an IP rotation and the next IP might not be blocked.
        r   r   r   r   r   r   Úretries_when_blocked,   s   z ProxyConfig.retries_when_blockedN)r   r	   r
   r   r   r   r   ÚpropertyÚboolr   Úintr   r   r   r   r   r      s    r   c                   @   s:   e Zd ZdZd
dee dee fdd„Zdefdd	„ZdS )ÚGenericProxyConfigaÜ  
    This proxy config can be used to set up any generic HTTP/HTTPS/SOCKS proxy. As it
    the requests library is used under the hood, you can follow the requests
    documentation to get more detailed information on how to set up proxies:
    https://requests.readthedocs.io/en/latest/user/advanced/#proxies

    If only an HTTP or an HTTPS proxy is provided, it will be used for both types of
    connections. However, you will have to provide at least one of the two.
    NÚhttp_urlÚ	https_urlc                 C   s    |s|st dƒ‚|| _|| _dS )aŒ  
        If only an HTTP or an HTTPS proxy is provided, it will be used for both types of
        connections. However, you will have to provide at least one of the two.

        :param http_url: the proxy URL used for HTTP requests. Defaults to `https_url`
            if None.
        :param https_url: the proxy URL used for HTTPS requests. Defaults to `http_url`
            if None.
        zPGenericProxyConfig requires you to define at least one of the two: http or httpsN)r   r    r!   )r   r    r!   r   r   r   Ú__init__B   s   
ÿ
zGenericProxyConfig.__init__r   c                 C   s   | j p| j| jp
| j dœS )N)r   r   )r    r!   r   r   r   r   r   T   s   

þz#GenericProxyConfig.to_requests_dict)NN)	r   r	   r
   r   r   r   r"   r   r   r   r   r   r   r   7   s    
r   c                   @   s¦   e Zd ZdZdZdZddeefdededeee  d	e	d
ede	fdd„Z
edefdd„ƒZedefdd„ƒZedefdd„ƒZedefdd„ƒZede	fdd„ƒZdS )ÚWebshareProxyConfigaB  
    Webshare is a provider offering rotating residential proxies, which is the
    most reliable way to work around being blocked by YouTube.

    If you don't have a Webshare account yet, you will have to create one
    at https://www.webshare.io/?referral_code=w0xno53eb50g and purchase a "Residential"
    proxy package that suits your workload, to be able to use this proxy config (make
    sure NOT to purchase "Proxy Server" or "Static Residential"!).

    Once you have created an account you only need the "Proxy Username" and
    "Proxy Password" that you can find in your Webshare settings
    at https://dashboard.webshare.io/proxy/settings to set up this config class, which
    will take care of setting up your proxies as needed, by defaulting to rotating
    proxies.

    Note that referral links are used here and any purchases made through these links
    will support this Open Source project, which is very much appreciated! :)
    However, you can of course integrate your own proxy solution by using the
    `GenericProxyConfig` class, if that's what you prefer.
    zp.webshare.ioéP   Né
   Úproxy_usernameÚproxy_passwordÚfilter_ip_locationsr   Údomain_nameÚ
proxy_portc                 C   s,   || _ || _|| _|| _|pg | _|| _dS )aZ  
        Once you have created a Webshare account at
        https://www.webshare.io/?referral_code=w0xno53eb50g and purchased a
        "Residential" package (make sure NOT to purchase "Proxy Server" or
        "Static Residential"!), this config class allows you to easily use it,
        by defaulting to the most reliable proxy settings (rotating residential
        proxies).

        :param proxy_username: "Proxy Username" found at
            https://dashboard.webshare.io/proxy/settings
        :param proxy_password: "Proxy Password" found at
            https://dashboard.webshare.io/proxy/settings
        :param filter_ip_locations: If you want to limit the pool of IPs that you will
            be rotating through to those located in specific countries, you can provide
            a list of location codes here. By choosing locations that are close to the
            machine that is running this code, you can reduce latency. Also, this can
            be used to work around location-based restrictions.
            You can find the full list of available locations (and how many IPs are
            available in each location) at
            https://www.webshare.io/features/proxy-locations?referral_code=w0xno53eb50g
        :param retries_when_blocked: Define how many times we should retry if a request
            is blocked. When using rotating residential proxies with a large IP pool it
            makes sense to retry a couple of times when a blocked IP is encountered,
            since a retry will trigger an IP rotation and the next IP might not be
            blocked. Defaults to 10.
        N)r&   r'   r)   r*   Ú_filter_ip_locationsÚ_retries_when_blocked)r   r&   r'   r(   r   r)   r*   r   r   r   r"   t   s   #

zWebshareProxyConfig.__init__r   c              
   C   s@   d  dd„ | jD ƒ¡}d| j› |› d| j› d| j› d| j› d
S )	NÚ c                 s   s    | ]
}d |  ¡ › V  qdS )Ú-N)Úupper)Ú.0Úlocation_coder   r   r   Ú	<genexpr>    s   € 
ÿz*WebshareProxyConfig.url.<locals>.<genexpr>zhttp://z-rotate:ú@ú:ú/)Újoinr+   r&   r'   r)   r*   )r   Úlocation_codesr   r   r   Úurlž   s   
ÿÿÿÿzWebshareProxyConfig.urlc                 C   ó   | j S ©N©r8   r   r   r   r   r    ¨   ó   zWebshareProxyConfig.http_urlc                 C   r9   r:   r;   r   r   r   r   r!   ¬   r<   zWebshareProxyConfig.https_urlc                 C   r   )NTr   r   r   r   r   r   °   s   z5WebshareProxyConfig.prevent_keeping_connections_alivec                 C   r9   r:   )r,   r   r   r   r   r   ´   r<   z(WebshareProxyConfig.retries_when_blocked)r   r	   r
   r   ÚDEFAULT_DOMAIN_NAMEÚDEFAULT_PORTr   r   r   r   r"   r   r8   r    r!   r   r   r   r   r   r   r   r#   [   s>    ùþý
üûú
ù*	r#   N)Úabcr   r   Útypingr   r   r   Ú	Exceptionr   r   r   r   r#   r   r   r   r   Ú<module>   s    #$