mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-10 07:10:31 +00:00
Update utils.py with a class to transcribe YouTube Videos
Added Class Transcribe with method youtube which accepts a video id as a parameter. Returns the transcript.
This commit is contained in:
parent
f4f337d699
commit
e0683024c1
@ -7,6 +7,7 @@ import platform
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import HTTPError
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
from youtube_transcript_api import YouTubeTranscriptApi
|
||||||
|
|
||||||
current_directory = os.path.dirname(os.path.realpath(__file__))
|
current_directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
config_directory = os.path.expanduser("~/.config/fabric")
|
config_directory = os.path.expanduser("~/.config/fabric")
|
||||||
@ -369,3 +370,35 @@ class Setup:
|
|||||||
apikey = input("Please enter your OpenAI API key\n")
|
apikey = input("Please enter your OpenAI API key\n")
|
||||||
self.api_key(apikey.strip())
|
self.api_key(apikey.strip())
|
||||||
self.patterns()
|
self.patterns()
|
||||||
|
|
||||||
|
|
||||||
|
class Transcribe:
|
||||||
|
def youtube(video_id):
|
||||||
|
"""
|
||||||
|
This method gets the transciption
|
||||||
|
of a YouTube video designated with the video_id
|
||||||
|
|
||||||
|
Input:
|
||||||
|
the video id specifing a YouTube video
|
||||||
|
an example url for a video: https://www.youtube.com/watch?v=vF-MQmVxnCs&t=306s
|
||||||
|
the video id is vF-MQmVxnCs&t=306s
|
||||||
|
|
||||||
|
Output:
|
||||||
|
a transcript for the video
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
an exception and prints error
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
|
||||||
|
transcript = ""
|
||||||
|
for segment in transcript_list:
|
||||||
|
transcript += segment['text'] + " "
|
||||||
|
return transcript.strip()
|
||||||
|
except Exception as e:
|
||||||
|
print("Error:", e)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user