
    j4                         d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	 d dl
mZ ddlmZmZ ddlmZmZmZ dd	lmZmZ d
eeef   defdZ G d d      Zy)    N)Path)OptionalIterableUnion)MozillaCookieJar	LoadError)Session   )ProxyConfigGenericProxyConfig)TranscriptListFetcherFetchedTranscriptTranscriptList)CookiePathInvalidCookieInvalidcookiesreturnc                     	 t               }|j                  t        |              |st        |       |S # t        t
        f$ r t        |       w xY w)N)r   loadstrr   FileNotFoundErrorr   r   )r   
cookie_jars     \/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/youtube_transcript_api/_api.py_load_cookie_jarr      sR    )%'
G%((y) )(()s	   25 Ac            	           e Zd Z	 	 	 ddeeeef      dee   dee   fdZ		 	 ddede
e   ded	efd
Zded	efdZedd       Ze	 	 	 	 	 dd       Ze	 	 	 	 dd       Zy)YouTubeTranscriptApiNcookie_pathproxy_confighttp_clientc                 "   |
t               n|}|j                  j                  ddi       |t        |      |_        |>|j                         |_        |j                  r|j                  j                  ddi       t        ||      | _	        y)a  
        Note on thread-safety: As this class will initialize a `requests.Session`
        object, it is not thread-safe. Make sure to initialize an instance of
        `YouTubeTranscriptApi` per thread, if used in a multi-threading scenario!

        :param cookie_path: Path to a text file containing YouTube authorization cookies
        :param proxy_config: an optional ProxyConfig object, defining proxies used for
            all network requests. This can be used to work around your IP being blocked
            by YouTube, as described 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)
        :param http_client: You can optionally pass in a requests.Session object, if you
            manually want to share cookies between different instances of
            `YouTubeTranscriptApi`, overwrite defaults, specify SSL certificates, etc.
        NzAccept-Languagezen-US
Connectionclose)r   )
r	   headersupdater   r   to_requests_dictproxies!prevent_keeping_connections_aliver   _fetcher)selfr   r   r   s       r   __init__zYouTubeTranscriptApi.__init__   s    * $/#6giK""$5w#?@""2;"?K#"."?"?"AK==##**L'+BC-kU    video_id	languagespreserve_formattingr   c                 b    | j                  |      j                  |      j                  |      S )a
  
        Retrieves the transcript for a single video. This is just a shortcut for
        calling:
        `YouTubeTranscriptApi().list(video_id).find_transcript(languages).fetch(preserve_formatting=preserve_formatting)`

        :param video_id: the ID of the video you want to retrieve the transcript for.
            Make sure that this is the actual ID, NOT the full URL to the video!
        :param languages: A list of language codes in a descending priority. For
            example, if this is set to ["de", "en"] it will first try to fetch the
            german transcript (de) and then fetch the english transcript (en) if
            it fails to do so. This defaults to ["en"].
        :param preserve_formatting: whether to keep select HTML text formatting
        r.   )listfind_transcriptfetch)r)   r,   r-   r.   s       r   r3   zYouTubeTranscriptApi.fetch;   s,    ( IIh_Y'U':U;	
r+   c                 8    | j                   j                  |      S )a  
        Retrieves the list of transcripts which are available for a given video. It
        returns a `TranscriptList` object which is iterable and provides methods to
        filter the list of transcripts for specific languages. While iterating over
        the `TranscriptList` the individual transcripts are represented by
        `Transcript` objects, which provide metadata and can either be fetched by
        calling `transcript.fetch()` or translated by calling `transcript.translate(
        'en')`. Example:

        ```
        ytt_api = YouTubeTranscriptApi()

        # retrieve the available transcripts
        transcript_list = ytt_api.list('video_id')

        # iterate over all available transcripts
        for transcript in transcript_list:
            # the Transcript object provides metadata properties
            print(
                transcript.video_id,
                transcript.language,
                transcript.language_code,
                # whether it has been manually created or generated by YouTube
                transcript.is_generated,
                # a list of languages the transcript can be translated to
                transcript.translation_languages,
            )

            # fetch the actual transcript data
            print(transcript.fetch())

            # translating the transcript will return another transcript object
            print(transcript.translate('en').fetch())

        # you can also directly filter for the language you are looking for, using the transcript list
        transcript = transcript_list.find_transcript(['de', 'en'])

        # or just filter for manually created transcripts
        transcript = transcript_list.find_manually_created_transcript(['de', 'en'])

        # or automatically generated ones
        transcript = transcript_list.find_generated_transcript(['de', 'en'])
        ```

        :param video_id: the ID of the video you want to retrieve the transcript for.
            Make sure that this is the actual ID, NOT the full URL to the video!
        )r(   r3   )r)   r,   s     r   r1   zYouTubeTranscriptApi.listT   s    f }}""8,,r+   c                    t        j                  dt               d}|r>t        |t              r|}n+t        |j                  d      |j                  d            }t        ||rt        |      nd      }|j                  |      S )a	  
        DEPRECATED: use the `list` method instead!

        Retrieves the list of transcripts which are available for a given video. It returns a `TranscriptList` object
        which is iterable and provides methods to filter the list of transcripts for specific languages. While iterating
        over the `TranscriptList` the individual transcripts are represented by `Transcript` objects, which provide
        metadata and can either be fetched by calling `transcript.fetch()` or translated by calling
        `transcript.translate('en')`. Example:

            # retrieve the available transcripts
            transcript_list = YouTubeTranscriptApi.list_transcripts('video_id')

            # iterate over all available transcripts
            for transcript in transcript_list:
                # the Transcript object provides metadata properties
                print(
                    transcript.video_id,
                    transcript.language,
                    transcript.language_code,
                    # whether it has been manually created or generated by YouTube
                    transcript.is_generated,
                    # a list of languages the transcript can be translated to
                    transcript.translation_languages,
                )

                # fetch the actual transcript data
                print(transcript.fetch())

                # translating the transcript will return another transcript object
                print(transcript.translate('en').fetch())

            # you can also directly filter for the language you are looking for, using the transcript list
            transcript = transcript_list.find_transcript(['de', 'en'])

            # or just filter for manually created transcripts
            transcript = transcript_list.find_manually_created_transcript(['de', 'en'])

            # or automatically generated ones
            transcript = transcript_list.find_generated_transcript(['de', 'en'])

        :param video_id: the youtube video id
        :type video_id: str
        :param proxies: a dictionary mapping of http and https proxies to be used for the network requests
        :type proxies: {'http': str, 'https': str} - http://docs.python-requests.org/en/master/user/advanced/#proxies
        :param cookies: a string of the path to a text file containing youtube authorization cookies
        :type cookies: str
        :return: the list of available transcripts
        :rtype TranscriptList:
        zh`list_transcripts` is deprecated and will be removed in a future version. Use the `list` method instead!Nhttphttps)http_url	https_url)r   r   )
warningswarnDeprecationWarning
isinstancer   r   getr   r   r1   )clsr,   r&   r   r   ytt_apis         r   list_transcriptsz%YouTubeTranscriptApi.list_transcripts   s~    f 	-	
 ';/&1$[[0GKK<P  '%)0Wd
 ||H%%r+   c                 
   t        j                  dt               t        |t              sJ d       i }g }|D ]  }		 | j                  |	||||      ||	<    ||fS # t        $ r}
|s|
|j                  |	       Y d}
~
Ed}
~
ww xY w)a  
        DEPRECATED: use the `fetch` method instead!

        Retrieves the transcripts for a list of videos.

        :param video_ids: a list of youtube video ids
        :type video_ids: list[str]
        :param languages: A list of language codes in a descending priority. For example, if this is set to ['de', 'en']
        it will first try to fetch the german transcript (de) and then fetch the english transcript (en) if it fails to
        do so.
        :type languages: list[str]
        :param continue_after_error: if this is set the execution won't be stopped, if an error occurs while retrieving
        one of the video transcripts
        :type continue_after_error: bool
        :param proxies: a dictionary mapping of http and https proxies to be used for the network requests
        :type proxies: {'http': str, 'https': str} - http://docs.python-requests.org/en/master/user/advanced/#proxies
        :param cookies: a string of the path to a text file containing youtube authorization cookies
        :type cookies: str
        :param preserve_formatting: whether to keep select HTML text formatting
        :type preserve_formatting: bool
        :return: a tuple containing a dictionary mapping video ids onto their corresponding transcripts, and a list of
        video ids, which could not be retrieved
        :rtype ({str: [{'text': str, 'start': float, 'end': float}]}, [str]}):
        zh`get_transcripts` is deprecated and will be removed in a future version. Use the `fetch` method instead!z%`video_ids` must be a list of stringsN)r:   r;   r<   r=   r1   get_transcript	Exceptionappend)r?   	video_idsr-   continue_after_errorr&   r   r.   dataunretrievable_videosr,   	exceptions              r   get_transcriptsz$YouTubeTranscriptApi.get_transcripts   s    D 	.	
 )T*S,SS*!! 		6H6!$!3!3i';N"X		6 )))  6+#O$++H55	6s   A	B#A==Bc                     t        j                  dt               t        |t              sJ d       | j                  |||      j                  |      j                  |      j                         S )a  
        DEPRECATED: use the `fetch` method instead!

        Retrieves the transcript for a single video. This is just a shortcut for calling::

            YouTubeTranscriptApi.list_transcripts(video_id, proxies).find_transcript(languages).fetch()

        :param video_id: the youtube video id
        :type video_id: str
        :param languages: A list of language codes in a descending priority. For example, if this is set to ['de', 'en']
        it will first try to fetch the german transcript (de) and then fetch the english transcript (en) if it fails to
        do so.
        :type languages: list[str]
        :param proxies: a dictionary mapping of http and https proxies to be used for the network requests
        :type proxies: {'http': str, 'https': str} - http://docs.python-requests.org/en/master/user/advanced/#proxies
        :param cookies: a string of the path to a text file containing youtube authorization cookies
        :type cookies: str
        :param preserve_formatting: whether to keep select HTML text formatting
        :type preserve_formatting: bool
        :return: a list of dictionaries containing the 'text', 'start' and 'duration' keys
        :rtype [{'text': str, 'start': float, 'end': float}]:
        zg`get_transcript` is deprecated and will be removed in a future version. Use the `fetch` method instead!z`video_id` must be a stringr0   )	r:   r;   r<   r=   r   rA   r2   r3   to_raw_data)r?   r,   r-   r&   r   r.   s         r   rC   z#YouTubeTranscriptApi.get_transcript  se    > 	.	
 (C(G*GG(  7G<_Y'U':U;[]		
r+   )NNN)enF)NN)rN   FNNF)rN   NNF)__name__
__module____qualname__r   r   r   r   r   r	   r*   r   boolr   r3   r   r1   classmethodrA   rK   rC    r+   r   r   r      s     37.2)-	VeD#I./V {+V g&	VD $+$)	

 C=
 "	

 

23-3- 
3-j E& E&N  "!7* 7*r  !*
 *
r+   r   )r:   pathlibr   typingr   r   r   http.cookiejarr   r   requestsr	   r&   r   r   _transcriptsr   r   r   _errorsr   r   r   r   r   rU   r+   r   <module>r\      sL      , , 6  4 R R 5)eD#I. )3C )[
 [
r+   