eshameo045 commited on
Commit
65203a5
·
1 Parent(s): 7c38093
Files changed (1) hide show
  1. utils/transcript_handler.py +8 -12
utils/transcript_handler.py CHANGED
@@ -31,24 +31,20 @@ def get_transcript(url: str) -> dict:
31
  return {"success": False, "error": "Invalid YouTube URL."}
32
 
33
  try:
34
- ytt_api = YouTubeTranscriptApi()
35
  try:
 
36
  transcript_data = ytt_api.fetch(video_id, languages=['en', 'hi', 'ur', 'en-US', 'en-GB'])
 
37
  except:
38
- transcript_list = ytt_api.list(video_id)
39
- transcript_data = transcript_list.find_transcript(
40
- [t.language_code for t in transcript_list]
41
- ).fetch()
42
-
43
- full_transcript = " ".join([entry.text for entry in transcript_data.snippets])
44
  full_transcript = clean_transcript(full_transcript)
45
 
46
  try:
47
- ydl_opts = {
48
- 'quiet': True,
49
- 'skip_download': True,
50
- 'no_warnings': True,
51
- }
52
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
53
  info = ydl.extract_info(url, download=False)
54
  video_title = info.get('title', f'Video {video_id}')
 
31
  return {"success": False, "error": "Invalid YouTube URL."}
32
 
33
  try:
34
+ # Pehle naya syntax try karo
35
  try:
36
+ ytt_api = YouTubeTranscriptApi()
37
  transcript_data = ytt_api.fetch(video_id, languages=['en', 'hi', 'ur', 'en-US', 'en-GB'])
38
+ full_transcript = " ".join([entry.text for entry in transcript_data.snippets])
39
  except:
40
+ # Purana syntax try karo
41
+ fetched = YouTubeTranscriptApi.get_transcript(video_id)
42
+ full_transcript = " ".join([entry['text'] for entry in fetched])
43
+
 
 
44
  full_transcript = clean_transcript(full_transcript)
45
 
46
  try:
47
+ ydl_opts = {'quiet': True, 'skip_download': True, 'no_warnings': True}
 
 
 
 
48
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
49
  info = ydl.extract_info(url, download=False)
50
  video_title = info.get('title', f'Video {video_id}')