fix: improve YouTube transcript handling for manual captions

This commit is contained in:
Juanan Pereira 2025-01-09 09:36:24 +01:00
parent 49f462163a
commit f0f7a56c48
6 changed files with 40 additions and 19 deletions

View File

@ -137,21 +137,42 @@ class YoutubeLoader:
return [] return []
try: try:
# First try to get transcript in requested language # First try to get manual transcript in requested language
transcript = transcript_list.find_transcript(self.language) for lang in self.language:
except NoTranscriptFound: try:
# Fallback: try to get any available transcript available_transcripts = (
available_transcripts = list( transcript_list._manually_created_transcripts
transcript_list._generated_transcripts.values() )
) if lang in available_transcripts:
if available_transcripts: transcript = available_transcripts[lang]
transcript = available_transcripts[0] log.info(f"Found manual transcript in language: {lang}")
log.info( break
f"Using first available transcript in language: {transcript.language_code}" except NoTranscriptFound:
) continue
else: else:
log.error("No transcripts found for video") # If no manual transcript found, try auto-generated ones
return [] try:
transcript = transcript_list.find_transcript(self.language)
log.info(
f"Using auto-generated transcript in language: {transcript.language_code}"
)
except NoTranscriptFound:
# Final fallback: try to get any available transcript
available_transcripts = list(
transcript_list._manually_created_transcripts.values()
) + list(transcript_list._generated_transcripts.values())
if available_transcripts:
transcript = available_transcripts[0]
log.info(
f"Using first available transcript in language: {transcript.language_code}"
)
else:
log.error("No transcripts found for video")
return []
except Exception as e:
log.exception(f"Error fetching transcript: {str(e)}")
return []
transcript_pieces: List[Dict[str, Any]] = transcript.fetch() transcript_pieces: List[Dict[str, Any]] = transcript.fetch()

2
package-lock.json generated
View File

@ -12589,4 +12589,4 @@
} }
} }
} }
} }

View File

@ -110,4 +110,4 @@
"node": ">=18.13.0 <=22.x.x", "node": ">=18.13.0 <=22.x.x",
"npm": ">=6.0.0" "npm": ">=6.0.0"
} }
} }

View File

@ -1062,4 +1062,4 @@
"Your entire contribution will go directly to the plugin developer; Open WebUI does not take any percentage. However, the chosen funding platform might have its own fees.": "L'intégralité de votre contribution ira directement au développeur du plugin ; Open WebUI ne prend aucun pourcentage. Cependant, la plateforme de financement choisie peut avoir ses propres frais.", "Your entire contribution will go directly to the plugin developer; Open WebUI does not take any percentage. However, the chosen funding platform might have its own fees.": "L'intégralité de votre contribution ira directement au développeur du plugin ; Open WebUI ne prend aucun pourcentage. Cependant, la plateforme de financement choisie peut avoir ses propres frais.",
"Youtube": "YouTube", "Youtube": "YouTube",
"Youtube Loader Settings": "Paramètres de l'outil de téléchargement YouTube" "Youtube Loader Settings": "Paramètres de l'outil de téléchargement YouTube"
} }

View File

@ -1062,4 +1062,4 @@
"Your entire contribution will go directly to the plugin developer; Open WebUI does not take any percentage. However, the chosen funding platform might have its own fees.": "Rachaidh do ranníocaíocht iomlán go díreach chuig an bhforbróir breiseán; Ní ghlacann Open WebUI aon chéatadán. Mar sin féin, d'fhéadfadh a tháillí féin a bheith ag an ardán maoinithe roghnaithe.", "Your entire contribution will go directly to the plugin developer; Open WebUI does not take any percentage. However, the chosen funding platform might have its own fees.": "Rachaidh do ranníocaíocht iomlán go díreach chuig an bhforbróir breiseán; Ní ghlacann Open WebUI aon chéatadán. Mar sin féin, d'fhéadfadh a tháillí féin a bheith ag an ardán maoinithe roghnaithe.",
"Youtube": "Youtube", "Youtube": "Youtube",
"Youtube Loader Settings": "Socruithe Luchtaire Youtube" "Youtube Loader Settings": "Socruithe Luchtaire Youtube"
} }

View File

@ -1062,4 +1062,4 @@
"Your entire contribution will go directly to the plugin developer; Open WebUI does not take any percentage. However, the chosen funding platform might have its own fees.": "您的全部捐款将直接给到插件开发者Open WebUI 不会收取任何比例。但众筹平台可能会有服务费、抽成。", "Your entire contribution will go directly to the plugin developer; Open WebUI does not take any percentage. However, the chosen funding platform might have its own fees.": "您的全部捐款将直接给到插件开发者Open WebUI 不会收取任何比例。但众筹平台可能会有服务费、抽成。",
"Youtube": "YouTube", "Youtube": "YouTube",
"Youtube Loader Settings": "YouTube 爬取设置" "Youtube Loader Settings": "YouTube 爬取设置"
} }