mirror of
https://github.com/ParisNeo/lollms.git
synced 2024-12-18 20:27:58 +00:00
Update download_transcript.py
This commit is contained in:
parent
62df82e8e3
commit
1ee216e2f3
@ -8,6 +8,7 @@ from functools import partial
|
||||
from typing import List
|
||||
from lollms.utilities import PackageManager
|
||||
from ascii_colors import trace_exception
|
||||
from typing import Any
|
||||
|
||||
# Installing necessary packages
|
||||
if not PackageManager.check_package_installed("youtube_transcript_api"):
|
||||
@ -16,19 +17,20 @@ if not PackageManager.check_package_installed("youtube_transcript_api"):
|
||||
# Importing the package after installation
|
||||
from youtube_transcript_api import YouTubeTranscriptApi
|
||||
|
||||
def download_youtube_transcript(video_id: str) -> str:
|
||||
def download_youtube_transcript(video_id: str, language_code: str = 'en') -> str:
|
||||
"""
|
||||
This function downloads the transcript of a YouTube video given its video ID.
|
||||
|
||||
Parameters:
|
||||
video_id (str): The ID of the YouTube video.
|
||||
languages (tuple): A list of languages to extract.
|
||||
|
||||
Returns:
|
||||
str: The transcript of the video.
|
||||
"""
|
||||
try:
|
||||
# Fetching the transcript
|
||||
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
||||
transcript = YouTubeTranscriptApi.get_transcript(video_id, (language_code,))
|
||||
|
||||
# Combining the transcript into a single string
|
||||
transcript_text = " ".join([entry['text'] for entry in transcript])
|
||||
@ -42,5 +44,5 @@ def download_youtube_transcript_function():
|
||||
"function_name": "download_youtube_transcript",
|
||||
"function": download_youtube_transcript,
|
||||
"function_description": "This function goes online to YouTube and downloads the transcript from any video.",
|
||||
"function_parameters": [{"name": "video_id", "type": "str"}]
|
||||
"function_parameters": [{"name": "video_id", "type": "str"},{"name": "language_code", "type": "str"}]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user