JaMugen commited on
Commit
d33e87a
·
1 Parent(s): 0726053

Update Milestone5API.py

Browse files
Files changed (1) hide show
  1. Milestone5API.py +6 -2
Milestone5API.py CHANGED
@@ -74,7 +74,7 @@ def translate_text_file(input_text_path, output_text_path, source_lang='en', tar
74
  write_text_to_file(output_text_path, translated_lines)
75
  return translated_lines
76
 
77
- def download_video_transcript(video_url, source_lang='en', target_lang='fr'):
78
  try:
79
  video_id = re.search(r"(?<=v=)[\w-]+", video_url)
80
  if video_id:
@@ -96,7 +96,11 @@ def download_video_transcript(video_url, source_lang='en', target_lang='fr'):
96
  print('Download completed!')
97
 
98
  transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
99
- transcript = transcript_list.find_generated_transcript([source_lang]).fetch()
 
 
 
 
100
 
101
  original_captions = ""
102
  for i, line in enumerate(transcript):
 
74
  write_text_to_file(output_text_path, translated_lines)
75
  return translated_lines
76
 
77
+ def download_video_transcript(video_url, target_lang='fr'):
78
  try:
79
  video_id = re.search(r"(?<=v=)[\w-]+", video_url)
80
  if video_id:
 
96
  print('Download completed!')
97
 
98
  transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
99
+ transcript = transcript_list.find_generated_transcript(languages=['en'], allow_auto_translations=True).fetch()
100
+
101
+ if not transcript:
102
+
103
+ transcript = transcript_list.find_generated_transcript(languages=['auto']).fetch()
104
 
105
  original_captions = ""
106
  for i, line in enumerate(transcript):