Skip to content

Commit

Permalink
Update download_transcript.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ParisNeo authored Aug 28, 2024
1 parent 62df82e commit 1ee216e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lollms/functions/youtube/download_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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"):
Expand All @@ -16,19 +17,20 @@
# 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])
Expand All @@ -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"}]
}

0 comments on commit 1ee216e

Please sign in to comment.