@@ -55,7 +55,6 @@ def run():
5555
5656 title = sanitize (info .get ("title" , "Unknown title" ))
5757
58- # Display formats with size
5958 for idx , fmt in enumerate (formats , 1 ):
6059 res = (
6160 fmt .get ("resolution" , "Audio Only" )
@@ -142,9 +141,6 @@ def run():
142141 "outtmpl" : str (video_out )
143142 }
144143
145-
146-
147-
148144 print ("\033 [36;1mStarting Video Download...\033 [0m\n " )
149145 t0 = int (time .time ())
150146 try :
@@ -186,5 +182,33 @@ def run():
186182 if Path ("audio_temp" ).exists ():
187183 shutil .rmtree ("audio_temp" , ignore_errors = True )
188184
185+ try :
186+ ask_subs = input ("\n \033 [36;1mDownload subtitles for this video? (y/n): \033 [0m" ).strip ().lower ()
187+ if ask_subs == "y" :
188+ print ("\033 [33;1mNote: YouTube may block subtitle extraction with HTTP 429. If that happens provide a cookies file.\033 [0m" )
189+ cookie_path = input ("\033 [36;1mEnter path to cookies file (optional, press Enter to skip): \033 [0m" ).strip ()
190+ lang = input ("\033 [36;1mEnter subtitle language code (e.g. en) or leave blank for all: \033 [0m" ).strip ()
191+ pref_auto = input ("\033 [36;1mAlso download automatic subtitles if manual not available? (y/n) [y]: \033 [0m" ).strip ().lower ()
192+ if pref_auto == "" :
193+ pref_auto = "y"
194+ cmd = ["yt-dlp" , "--skip-download" , "--write-sub" ]
195+ if pref_auto == "y" :
196+ cmd += ["--write-auto-sub" ]
197+ if lang :
198+ cmd += ["--sub-lang" , lang ]
199+ cmd += ["--convert-subs" , "srt" ]
200+ if cookie_path :
201+ cmd += ["--cookies" , cookie_path ]
202+ cmd += ["-o" , str (dest / f"{ safe_title } .%(ext)s" )]
203+ cmd += [url ]
204+ print ("\033 [36;1mDownloading subtitles...\033 [0m" )
205+ try :
206+ sp .run (cmd , check = True )
207+ print ("\033 [32;1mSubtitles downloaded (converted to .srt where possible).\033 [0m" )
208+ except Exception as e :
209+ print (f"\033 [31;1mSubtitle download error: { e } \033 [0m" )
210+ except Exception :
211+ pass
212+
189213if __name__ == "__main__" :
190214 run ()
0 commit comments