mirror of
https://git.mirrors.martin98.com/https://github.com/open-webui/open-webui
synced 2025-08-19 10:35:59 +08:00
Update youtube.py
This commit is contained in:
parent
c69278c13c
commit
f65dc715f9
@ -83,7 +83,7 @@ class YoutubeLoader:
|
|||||||
'Could not import "youtube_transcript_api" Python package. '
|
'Could not import "youtube_transcript_api" Python package. '
|
||||||
"Please install it with `pip install youtube-transcript-api`."
|
"Please install it with `pip install youtube-transcript-api`."
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.proxy_url:
|
if self.proxy_url:
|
||||||
youtube_proxies = {
|
youtube_proxies = {
|
||||||
"http": self.proxy_url,
|
"http": self.proxy_url,
|
||||||
@ -93,7 +93,7 @@ class YoutubeLoader:
|
|||||||
log.debug(f"Using proxy URL: {self.proxy_url[:14]}...")
|
log.debug(f"Using proxy URL: {self.proxy_url[:14]}...")
|
||||||
else:
|
else:
|
||||||
youtube_proxies = None
|
youtube_proxies = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
transcript_list = YouTubeTranscriptApi.list_transcripts(
|
transcript_list = YouTubeTranscriptApi.list_transcripts(
|
||||||
self.video_id, proxies=youtube_proxies
|
self.video_id, proxies=youtube_proxies
|
||||||
@ -101,11 +101,11 @@ class YoutubeLoader:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception("Loading YouTube transcript failed")
|
log.exception("Loading YouTube transcript failed")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Make a copy of the language list to avoid modifying the original
|
# Make a copy of the language list to avoid modifying the original
|
||||||
languages_to_try = list(self.language)
|
languages_to_try = list(self.language)
|
||||||
|
|
||||||
# Add English as fallback, if not already in the list
|
# Add English as fallback if not already in the list
|
||||||
if "en" not in languages_to_try:
|
if "en" not in languages_to_try:
|
||||||
log.debug("Adding English as fallback language")
|
log.debug("Adding English as fallback language")
|
||||||
languages_to_try.append("en")
|
languages_to_try.append("en")
|
||||||
@ -129,8 +129,8 @@ class YoutubeLoader:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.info(f"Error finding transcript for language '{lang}'")
|
log.info(f"Error finding transcript for language '{lang}'")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# If we get here, all languages failed
|
# If we get here, all languages failed
|
||||||
languages_tried = ", ".join(languages_to_try)
|
languages_tried = ", ".join(languages_to_try)
|
||||||
log.warning(f"No transcript found for any of the specified languages: {languages_tried}")
|
log.warning(f"No transcript found for any of the specified languages: {languages_tried}. Verify if the video has transcripts, add more languages if needed.")
|
||||||
raise NoTranscriptFound(f"No transcript found for any supported language. Add additional supported languages and verify whether the video has any transcripts.")
|
raise NoTranscriptFound(f"No transcript found for any supported language. Verify if the video has transcripts, add more languages if needed.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user