@@ -30,7 +30,8 @@ def extract_video_id(url: str) -> str:
3030 raise typer .Exit (1 )
3131
3232
33- def fetch_youtube_captions (video_id : str , language : Optional [str ], console : Console ) -> Optional [str ]:
33+ def fetch_youtube_captions (video_id : str , language : Optional [str ], console : Console ) -> Optional [tuple [str , bool ]]:
34+ """Returns (transcript_text, is_generated) or None if no captions available."""
3435 try :
3536 from youtube_transcript_api import YouTubeTranscriptApi
3637
@@ -53,11 +54,13 @@ def fetch_youtube_captions(video_id: str, language: Optional[str], console: Cons
5354 if transcript is None :
5455 return None
5556
57+ is_generated = getattr (transcript , "is_generated" , True )
5658 fetched = transcript .fetch ()
57- return "\n " .join (
59+ text = "\n " .join (
5860 s .text if hasattr (s , "text" ) else s ["text" ]
5961 for s in fetched
6062 )
63+ return text , is_generated
6164 except Exception :
6265 return None
6366
@@ -163,10 +166,12 @@ def main(
163166
164167 if not force_whisper :
165168 with console .status ("Fetching YouTube captions..." ):
166- transcript = fetch_youtube_captions (video_id , effective_language , console )
169+ captions_result = fetch_youtube_captions (video_id , effective_language , console )
167170
168- if transcript :
169- console .print ("[green]✓[/green] Found YouTube captions" )
171+ if captions_result :
172+ transcript , is_generated = captions_result
173+ label = "auto-generated captions" if is_generated else "captions"
174+ console .print (f"[green]✓[/green] Found YouTube { label } " )
170175 else :
171176 console .print ("[yellow]No captions found[/yellow] — falling back to Whisper" )
172177
@@ -202,10 +207,12 @@ def main(
202207
203208def _fetch_title (url : str ) -> Optional [str ]:
204209 try :
205- import yt_dlp
206- with yt_dlp .YoutubeDL ({"quiet" : True , "no_warnings" : True }) as ydl :
207- info = ydl .extract_info (url , download = False )
208- return info .get ("title" )
210+ import json
211+ import urllib .request
212+ oembed_url = f"https://www.youtube.com/oembed?url={ url } &format=json"
213+ with urllib .request .urlopen (oembed_url , timeout = 10 ) as resp :
214+ data = json .loads (resp .read ())
215+ return data .get ("title" )
209216 except Exception :
210217 return None
211218
0 commit comments