remove unnecessary function from youtube transcript (#4978)
* remove unnecessary function from youtube transctipt * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Hare <ericrhare@gmail.com>
This commit is contained in:
parent
53e00c8092
commit
a8470c89a2
1 changed files with 0 additions and 37 deletions
|
|
@ -225,40 +225,3 @@ class YouTubeTranscriptsComponent(Component):
|
|||
except Exception as exc: # noqa: BLE001
|
||||
# Using a specific error type for the return value
|
||||
return Data(data={"error": f"Failed to get YouTube transcripts: {exc!s}"})
|
||||
|
||||
def youtube_transcripts(
|
||||
self,
|
||||
url: str = "",
|
||||
transcript_format: TranscriptFormat = TranscriptFormat.TEXT,
|
||||
chunk_size_seconds: int = 120,
|
||||
language: str = "",
|
||||
translation: str = "",
|
||||
) -> Data | list[Data]:
|
||||
"""Helper method to handle transcripts outside of component calls.
|
||||
|
||||
Args:
|
||||
url: The YouTube URL to get transcripts from.
|
||||
transcript_format: Format of transcripts ('text' or 'chunks').
|
||||
chunk_size_seconds: Size of each transcript chunk in seconds.
|
||||
language: Comma-separated list of language codes.
|
||||
translation: Target language for translation.
|
||||
|
||||
Returns:
|
||||
Data | list[Data]: Video transcripts as single Data or list of Data.
|
||||
"""
|
||||
if isinstance(transcript_format, str):
|
||||
transcript_format = TranscriptFormat(transcript_format)
|
||||
loader = YoutubeLoader.from_youtube_url(
|
||||
url,
|
||||
transcript_format=TranscriptFormat.TEXT
|
||||
if transcript_format == TranscriptFormat.TEXT
|
||||
else TranscriptFormat.CHUNKS,
|
||||
chunk_size_seconds=chunk_size_seconds,
|
||||
language=language.split(",") if language else ["en"],
|
||||
translation=translation or None,
|
||||
)
|
||||
|
||||
transcripts = loader.load()
|
||||
if transcript_format == TranscriptFormat.TEXT and len(transcripts) > 0:
|
||||
return Data(data={"transcript": transcripts[0].page_content})
|
||||
return [Data(data={"content": doc.page_content, "metadata": doc.metadata}) for doc in transcripts]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue