generated from cheshire-cat-ai/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ce7d01
commit c31f569
Showing
7 changed files
with
49 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import re | ||
from abc import ABC | ||
from typing import Iterator | ||
|
||
from pytube import extract | ||
from youtube_transcript_api import YouTubeTranscriptApi | ||
from youtube_transcript_api.formatters import TextFormatter, JSONFormatter | ||
from langchain.docstore.document import Document | ||
from langchain.document_loaders.base import BaseBlobParser | ||
from langchain.document_loaders.blob_loaders.schema import Blob | ||
|
||
from cat.mad_hatter.decorators import hook | ||
|
||
|
||
def parse_youtube_url(url: str) -> str: | ||
data = re.findall(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url) | ||
if data: | ||
return data[0] | ||
return "" | ||
|
||
|
||
class YoutubeParser(BaseBlobParser, ABC): | ||
def __init__(self): | ||
self.formatter = TextFormatter() | ||
|
||
def lazy_parse(self, blob: Blob) -> Iterator[Document]: | ||
video_id = extract.video_id(blob.source) | ||
|
||
transcript = YouTubeTranscriptApi.get_transcripts([video_id], languages=["en", "it"], preserve_formatting=True) | ||
text = self.formatter.format_transcript(transcript[0][video_id]) | ||
|
||
yield Document(page_content=text, metadata={}) | ||
|
||
|
||
@hook | ||
def rabbithole_instantiates_parsers(file_handlers: dict, cat) -> dict: | ||
file_handlers["video/mp4"] = YoutubeParser() | ||
return file_handlers |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"name": "My plugin", | ||
"name": "Catube", | ||
"version": "0.0.1", | ||
"description": "Description of my_plugin.", | ||
"author_name": "Me", | ||
"author_url": "https://mywebsite.me", | ||
"plugin_url": "https://github.com/my_name/my_plugin", | ||
"tags": "cat, template, example", | ||
"thumb": "https://raw.githubusercontent.com/my_repo_path/my_plugin.png" | ||
"description": "Description of catube.", | ||
"author_name": "Nicola Corbellini", | ||
"author_url": "", | ||
"plugin_url": "https://github.com/Furrmidable-Crew/CaTube", | ||
"tags": "Cat, RabbitHole, DocumentsLoading", | ||
"thumb": "https://raw.githubusercontent.com/my_repo_path/catube.png" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
youtube-transcript-api | ||
pytube |