o
    jEi|)                     @   s  d dl mZ d dlmZmZmZ d dlmZ ddl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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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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 ).    )Path)IterableOptionalList)	HTTPError   )	WATCH_URL)ProxyConfigGenericProxyConfigWebshareProxyConfigc                   @      e Zd ZdS )YouTubeTranscriptApiExceptionN__name__
__module____qualname__ r   r   [/var/www/agentarbitrage/venv/lib/python3.10/site-packages/youtube_transcript_api/_errors.pyr   
       r   c                   @   r   )CookieErrorNr   r   r   r   r   r      r   r   c                       "   e Zd Zdef fddZ  ZS )CookiePathInvalidcookie_pathc                       t  d|  d S )Nz%Can't load the provided cookie file: super__init__selfr   	__class__r   r   r      s   zCookiePathInvalid.__init__r   r   r   r   r   __classcell__r   r   r   r   r          r   c                       r   )CookieInvalidr   c                    r   )Nz7The cookies provided are not valid (may have expired): r   r   r   r   r   r      s   zCookieInvalid.__init__r!   r   r   r   r   r$      r#   r$   c                       sd   e Zd ZdZdZdZdZdZdef fddZ	d	efd
dZ
ed	efddZd	efddZ  ZS )CouldNotRetrieveTranscriptz8
    Raised if a transcript could not be retrieved.
    z;
Could not retrieve a transcript for the video {video_url}!z( This is most likely caused by:

{cause} a  

If you are sure that the described cause is not responsible for this error and that a transcript should be retrievable, please create an issue at https://github.com/jdepoix/youtube-transcript-api/issues. Please add which version of youtube_transcript_api you are using and provide the information needed to replicate the error. Also make sure that there are no open issues which already describe your problem!video_idc                    s   || _ t   d S N)r'   r   r   r   r'   r   r   r   r   3   s   z#CouldNotRetrieveTranscript.__init__returnc                 C   s>   | j jtj| jdd}| j}|r|| jj|d| j 7 }|S )N)r'   )	video_url)cause)ERROR_MESSAGEformatr   r'   r,   CAUSE_MESSAGE_INTROGITHUB_REFERRAL)r   error_messager,   r   r   r   _build_error_message7   s   z/CouldNotRetrieveTranscript._build_error_messagec                 C   s   | j S r(   )CAUSE_MESSAGEr   r   r   r   r,   D   s   z CouldNotRetrieveTranscript.causec                 C   s   |   S r(   )r2   r4   r   r   r   __str__H   s   z"CouldNotRetrieveTranscript.__str__)r   r   r   __doc__r-   r/   r3   r0   strr   r2   propertyr,   r5   r"   r   r   r   r   r%   "   s    	r%   c                   @      e Zd ZdZdS )YouTubeDataUnparsablezThe data required to fetch the transcript is not parsable. This should not happen, please open an issue (make sure to include the video ID)!Nr   r   r   r3   r   r   r   r   r:   L       r:   c                       s<   e Zd ZdZdedef fddZedefddZ  Z	S )	YouTubeRequestFailedz#Request to YouTube failed: {reason}r'   
http_errorc                    s   t || _t | d S r(   )r7   reasonr   r   )r   r'   r>   r   r   r   r   V   s   
zYouTubeRequestFailed.__init__r*   c                 C   s   | j j| jdS )Nr?   )r3   r.   r?   r4   r   r   r   r,   Z   s   zYouTubeRequestFailed.cause)
r   r   r   r3   r7   r   r   r8   r,   r"   r   r   r   r   r=   S   s
    r=   c                       sF   e Zd ZdZdZdedee dee f fddZe	dd	 Z
  ZS )
VideoUnplayablez:The video is unplayable for the following reason: {reason}z#

Additional Details:
{sub_reasons}r'   r?   sub_reasonsc                       || _ || _t | d S r(   )r?   rB   r   r   )r   r'   r?   rB   r   r   r   r   e   s   zVideoUnplayable.__init__c                 C   sT   | j d u rdn| j }| jr#ddd | jD }| | jj|d }| jj|dS )NzNo reason specified!
c                 s   s    | ]}d | V  qdS )z - Nr   ).0
sub_reasonr   r   r   	<genexpr>n   s    

z(VideoUnplayable.cause.<locals>.<genexpr>)rB   r@   )r?   rB   joinSUBREASON_MESSAGEr.   r3   )r   r?   rB   r   r   r   r,   j   s   
zVideoUnplayable.cause)r   r   r   r3   rI   r7   r   r   r   r8   r,   r"   r   r   r   r   rA   a   s    "rA   c                   @   r9   )VideoUnavailablez The video is no longer availableNr;   r   r   r   r   rJ   w       rJ   c                   @   r9   )InvalidVideoIdzYou provided an invalid video id. Make sure you are using the video id and NOT the url!

Do NOT run: `YouTubeTranscriptApi().fetch("https://www.youtube.com/watch?v=1234")`
Instead run: `YouTubeTranscriptApi().fetch("1234")`Nr;   r   r   r   r   rL   {   r<   rL   c                       sd   e Zd ZdZe dZdZdZdef fddZde	e
 d	d fd
dZed	ef fddZ  ZS )RequestBlockedab  YouTube is blocking requests from your IP. This usually is due to one of the following reasons:
- You have done too many requests and your IP has been blocked by YouTube
- You are doing requests from an IP belonging to a cloud provider (like AWS, Google Cloud Platform, Azure, etc.). Unfortunately, most IPs from cloud providers are blocked by YouTube.

aF  There are two things you can do to work around this:
1. Use proxies to hide your IP address, as explained in the "Working around IP bans" section of the README (https://github.com/jdepoix/youtube-transcript-api?tab=readme-ov-file#working-around-ip-bans-requestblocked-or-ipblocked-exception).
2. (NOT RECOMMENDED) If you authenticate your requests using cookies, you will be able to continue doing requests for a while. However, YouTube will eventually permanently ban the account that you have used to authenticate with! So only do this if you don't mind your account being banned!a  YouTube is blocking your requests, despite you using proxies. Keep in mind that a proxy is just a way to hide your real IP behind the IP of that proxy, but there is no guarantee that the IP of that proxy won't be blocked as well.

The only truly reliable way to prevent IP blocks is rotating through a large pool of residential IPs, by using a provider like Webshare (https://www.webshare.io/?referral_code=w0xno53eb50g), which provides you with a pool of >30M residential IPs (make sure to purchase "Residential" proxies, NOT "Proxy Server" or "Static Residential"!).

You will find more information on how to easily integrate Webshare here: https://github.com/jdepoix/youtube-transcript-api?tab=readme-ov-file#using-websharea  YouTube is blocking your requests, despite you using Webshare proxies. Please make sure that you have purchased "Residential" proxies and NOT "Proxy Server" or "Static Residential", as those won't work as reliably! The free tier also uses "Proxy Server" and will NOT work!

The only reliable option is using "Residential" proxies (not "Static Residential"), as this allows you to rotate through a pool of over 30M IPs, which means you will always find an IP that hasn't been blocked by YouTube yet!

You can support the development of this open source project by making your Webshare purchases through this affiliate link: https://www.webshare.io/?referral_code=w0xno53eb50g 

Thank you for your support! <3r'   c                    s   d | _ t | d S r(   )_proxy_configr   r   r)   r   r   r   r      s   zRequestBlocked.__init__proxy_configr*   c                 C   s
   || _ | S r(   )rN   )r   rO   r   r   r   with_proxy_config   s   z RequestBlocked.with_proxy_configc                    s,   t | jtr	| jS t | jtr| jS t jS r(   )
isinstancerN   r   !WITH_WEBSHARE_PROXY_CAUSE_MESSAGEr
    WITH_GENERIC_PROXY_CAUSE_MESSAGEr   r,   r4   r   r   r   r,      s
   zRequestBlocked.cause)r   r   r   BASE_CAUSE_MESSAGEr3   rS   rR   r7   r   r   r	   rP   r8   r,   r"   r   r   r   r   rM      s"    	
rM   c                   @   s   e Zd Zej dZdS )	IpBlockedzWays to work around this are explained in the "Working around IP bans" section of the README (https://github.com/jdepoix/youtube-transcript-api?tab=readme-ov-file#working-around-ip-bans-requestblocked-or-ipblocked-exception).
N)r   r   r   rM   rT   r3   r   r   r   r   rU      s    
rU   c                   @   r9   )TranscriptsDisabledz%Subtitles are disabled for this videoNr;   r   r   r   r   rV      rK   rV   c                   @   r9   )AgeRestrictedaS  This video is age-restricted. Therefore, you are unable to retrieve transcripts for it without authenticating yourself.

Unfortunately, Cookie Authentication is temporarily unsupported in youtube-transcript-api, as recent changes in YouTube's API broke the previous implementation. I will do my best to re-implement it as soon as possible.Nr;   r   r   r   r   rW      s    	rW   c                   @   r9   )NotTranslatablez*The requested language is not translatableNr;   r   r   r   r   rX      rK   rX   c                   @   r9   )TranslationLanguageNotAvailablez3The requested translation language is not availableNr;   r   r   r   r   rY      rK   rY   c                   @   r9   )FailedToCreateConsentCookiez6Failed to automatically give consent to saving cookiesNr;   r   r   r   r   rZ      rK   rZ   c                       sD   e Zd ZdZdedee ddf fddZedefd	d
Z  Z	S )NoTranscriptFoundzpNo transcripts were found for any of the requested language codes: {requested_language_codes}

{transcript_data}r'   requested_language_codestranscript_dataTranscriptListc                    rC   r(   )_requested_language_codes_transcript_datar   r   )r   r'   r\   r]   r   r   r   r      s   zNoTranscriptFound.__init__r*   c                 C   s   | j j| jt| jdS )N)r\   r]   )r3   r.   r_   r7   r`   r4   r   r   r   r,     s   zNoTranscriptFound.cause)
r   r   r   r3   r7   r   r   r8   r,   r"   r   r   r   r   r[      s    
r[   c                   @   r9   )PoTokenRequiredzhThe requested video cannot be retrieved without a PO Token. If this happens, please open a GitHub issue!Nr;   r   r   r   r   ra     r<   ra   N)"pathlibr   typingr   r   r   requestsr   	_settingsr   proxiesr	   r
   r   	Exceptionr   r   r   r$   r%   r:   r=   rA   rJ   rL   rM   rU   rV   rW   rX   rY   rZ   r[   ra   r   r   r   r   <module>   s0    	*F
