
    }i                     l    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	      Zy)
    N)PackageNotFoundErrorversion)List   )GenericProxyConfigWebshareProxyConfig)FormatterLoader)YouTubeTranscriptApiFetchedTranscriptTranscriptListc                   L    e Zd Zdee   fdZdefdZdedefdZ	d Z
d Zd	 Zy
)YouTubeTranscriptCliargsc                     || _         y N)_args)selfr   s     F/usr/local/lib/python3.12/dist-packages/youtube_transcript_api/_cli.py__init__zYouTubeTranscriptCli.__init__   s	    
    returnc                    | j                         }|j                  r|j                  ryd }|j                  dk7  s|j                  dk7  r!t        |j                  |j                        }|j                  |j                  !t        |j                  |j                        }g }g }t        |      }|j                  D ]S  }	 |j                  |      }|j                  r|j                  |       n!|j                  | j                  ||             U |D cg c]  }t!        |       }	}|rf|j                  r|	j#                  d |D               nA|	j                  t%               j'                  |j(                        j+                  |             dj-                  |	      S # t        $ r}|j                  |       Y d }~d }~ww xY wc c}w )N )http_url	https_url)proxy_usernameproxy_password)proxy_configc              3   2   K   | ]  }t        |        y wr   )str).0transcript_lists     r   	<genexpr>z+YouTubeTranscriptCli.run.<locals>.<genexpr>>   s      &-<C(&s   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	Exceptionr    extendr	   loadformatformat_transcriptsjoin)
r   parsed_argsr   transcripts
exceptionsytt_apivideo_idr"   	exceptionprint_sectionss
             r   runzYouTubeTranscriptCli.run   s   &&(//K4Q4Q!!R';+B+Bb+H-$//%11L //;22>.*BB*BBL
 
&%
 $-- 	-H-"),,x"8//&&7&&..'+	- ;EEY#i.EE++%% &@K&  %%#%T+,,-''4 {{>**!  -!!),,- Fs   AF'G'	G0GGr"   c                 F   |j                   r|j                  |j                        }nC|j                  r|j	                  |j                        }n|j                  |j                        }|j                  r|j                  |j                        }|j                         S r   )r%   find_generated_transcript	languagesr&    find_manually_created_transcriptfind_transcript	translatefetch)r   r6   r"   
transcripts       r   r/   z&YouTubeTranscriptCli._fetch_transcriptJ   s    
 //(BB%%J **(II%%J )889N9NOJ  #--k.C.CDJ!!r   c                 8    	 t        d      S # t        $ r Y yw xY w)Nzyoutube-transcript-apiunknown)r   r   )r   s    r   _get_versionz!YouTubeTranscriptCli._get_version_   s%    	344# 		s   
 	c           	         t        j                  d      }|j                  ddd| j                                 |j                  ddd	d
d       |j                  ddt        d       |j                  dddgt        d       |j                  ddd	d
d       |j                  ddd	d
d       |j                  dt        dt        t        j                  j                                      |j                  ddd        |j                  d!d t        d"#       |j                  d$d t        d%#       |j                  d&dd'd()       |j                  d*dd'd+)       | j                  |j                  | j                              S ),NzThis 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.)rK   constdefaulthelpr+   +zList of YouTube video IDs.)nargstyperO   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!)rQ   rN   rR   rO   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)rR   rN   choicesz--translater   zThe 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.)rN   rO   z--webshare-proxy-usernamez\Specify your Webshare "Proxy Username" found at https://dashboard.webshare.io/proxy/settings)rN   rR   rO   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.)rN   metavarrO   z--https-proxyzUse the specified HTTPS proxy.)argparseArgumentParseradd_argumentrH   r    tupler	   TYPESkeys_sanitize_video_ids
parse_argsr   )r   parsers     r   r$   z YouTubeTranscriptCli._parse_argse   s   ((5
 	():):)<(=> 	 	

 	  [ 	 	
 	s3O 	 	
 	 s 	 	
 	! n 	 	
 	( j 	 	
 	///4467	 	 	
 	+	 	 	
 	'o	 	 	
 	'o	 	 	
 	0	 	 	
 	1	 	 	
 ''(9(9$**(EFFr   c                 n    |j                   D cg c]  }|j                  dd       c}|_         |S c c}w )N\r   )r+   replace)r   r   r:   s      r   r_   z(YouTubeTranscriptCli._sanitize_video_ids   s0    EI^^T(**44T Us   2N)__name__
__module____qualname__r   r    r   r=   r   r   r/   rH   r$   r_    r   r   r   r      sJ    T#Y 9+S 9+v" (" 
	"*bGHr   r   )rY   importlib.metadatar   r   typingr   proxiesr   r   
formattersr	   _apir
   r   r   r   rh   r   r   <module>rn      s&     <  < ' I I@ @r   