o
    óT·j�  ã                   @   sf   d dl 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
 ddlmZmZmZ G dd	„ d	ƒZdS )
é    N)ÚPackageNotFoundErrorÚversion)ÚListé   )ÚGenericProxyConfigÚWebshareProxyConfig)ÚFormatterLoader)ÚYouTubeTranscriptApiÚFetchedTranscriptÚTranscriptListc                   @   sV   e Zd Zdee fdd„Zdefdd„Zdedefdd	„Z	d
d„ Z
dd„ Zdd„ ZdS )ÚYouTubeTranscriptCliÚargsc                 C   s
   || _ d S ©N)Ú_args©Úselfr   © r   ú^/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/youtube_transcript_api/_cli.pyÚ__init__   s   
zYouTubeTranscriptCli.__init__Úreturnc           
      C   s4  |   ¡ }|jr|jrdS d }|jdks|jdkr t|j|jd�}|jd us*|jd ur2t|j|jd�}g }g }t	|d�}|j
D ]2}z| |¡}|jrO| |¡ n	| |  ||¡¡ W q> typ } z| |¡ W Y d }~q>d }~ww dd„ |D ƒ}	|r•|jrˆ|	 dd„ |D ƒ¡ n|	 tƒ  |j¡ |¡¡ d	 |	¡S )
NÚ )Úhttp_urlÚ	https_url)Úproxy_usernameÚproxy_password)Úproxy_configc                 S   s   g | ]}t |ƒ‘qS r   ©Ústr)Ú.0Ú	exceptionr   r   r   Ú
<listcomp>;   s    z,YouTubeTranscriptCli.run.<locals>.<listcomp>c                 s   s   � | ]}t |ƒV  qd S r   r   )r   Útranscript_listr   r   r   Ú	<genexpr>>   s   € 
ÿz+YouTubeTranscriptCli.run.<locals>.<genexpr>z

)Ú_parse_argsÚexclude_manually_createdÚexclude_generatedÚ
http_proxyÚhttps_proxyr   Úwebshare_proxy_usernameÚwebshare_proxy_passwordr   r	   Ú	video_idsÚlistÚlist_transcriptsÚappendÚ_fetch_transcriptÚ	ExceptionÚextendr   ÚloadÚformatÚformat_transcriptsÚjoin)
r   Úparsed_argsr   ÚtranscriptsÚ
exceptionsÚytt_apiÚvideo_idr!   r   Úprint_sectionsr   r   r   Úrun   s`   þ

þÿ

þÿ€€ÿ

ÿý
zYouTubeTranscriptCli.runr!   c                 C   sN   |j r
| |j¡}n|jr| |j¡}n| |j¡}|jr#| |j¡}| ¡ S r   )r$   Úfind_generated_transcriptÚ	languagesr%   Ú find_manually_created_transcriptÚfind_transcriptÚ	translateÚfetch)r   r5   r!   Ú
transcriptr   r   r   r.   J   s   ÿÿz&YouTubeTranscriptCli._fetch_transcriptc                 C   s    zt dƒW S  ty   Y dS w )Nzyoutube-transcript-apiÚunknown)r   r   )r   r   r   r   Ú_get_version_   s
   
ÿz!YouTubeTranscriptCli._get_versionc                 C   s  t jdd�}|jddd|  ¡ › �d� |jddd	d
dd� |jddtdd� |jdddgtdd� |jddd	d
dd� |jddd	d
dd� |jdtdttj ¡ ƒd� |jdddd � |jd!d td"d#� |jd$d td%d#� |jd&dd'd(d)� |jd*dd'd+d)� |  	| 
| j¡¡S ),NzéThis is a python API which allows you to get the transcripts/subtitles for a given YouTube video. It also works for automatically generated subtitles and it does not require a headless browser, like other selenium based solutions do!)Údescriptionz	--versionr   z%(prog)s, version )Úactionr   z--list-transcriptsÚstore_constTFzHThis will list the languages in which the given videos are available in.)rF   ÚconstÚdefaultÚhelpr*   ú+zList of YouTube video IDs.)ÚnargsÚtyperJ   z--languagesÚ*Úena‹  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. As I can't provide a complete list of all working language codes with full certainty, you may have to play around with the language codes a bit, to find the one which is working for you!)rL   rI   rM   rJ   z--exclude-generatedz[If this flag is set transcripts which have been generated by YouTube will not be retrieved.z--exclude-manually-createdzWIf this flag is set transcripts which have been manually created will not be retrieved.z--formatÚpretty)rM   rI   Úchoicesz--translater   zÏThe language code for the language you want this transcript to be translated to. Use the --list-transcripts feature to find out which languages are translatable and which translation languages are available.)rI   rJ   z--webshare-proxy-usernamez\Specify your Webshare "Proxy Username" found at https://dashboard.webshare.io/proxy/settings)rI   rM   rJ   z--webshare-proxy-passwordz\Specify your Webshare "Proxy Password" found at https://dashboard.webshare.io/proxy/settingsz--http-proxyÚURLzUse the specified HTTP proxy.)rI   ÚmetavarrJ   z--https-proxyzUse the specified HTTPS proxy.)ÚargparseÚArgumentParserÚadd_argumentrD   r   Útupler   ÚTYPESÚkeysÚ_sanitize_video_idsÚ
parse_argsr   )r   Úparserr   r   r   r#   e   s˜   þýûÿÿøûûüü	üüüüz YouTubeTranscriptCli._parse_argsc                 C   s   dd„ |j D ƒ|_ |S )Nc                 S   s   g | ]}|  d d¡‘qS )ú\r   )Úreplace)r   r9   r   r   r   r    Ê   s    z<YouTubeTranscriptCli._sanitize_video_ids.<locals>.<listcomp>)r*   r   r   r   r   rZ   É   s   z(YouTubeTranscriptCli._sanitize_video_idsN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r;   r   r
   r.   rD   r#   rZ   r   r   r   r   r      s    ;ý
üdr   )rT   Úimportlib.metadatar   r   Útypingr   Úproxiesr   r   Ú
formattersr   Ú_apir	   r
   r   r   r   r   r   r   Ú<module>   s    