video_translator / youtubetranscript.py
Gotenks1893's picture
Upload 8 files
168a18b
raw
history blame contribute delete
592 Bytes
from youtube_transcript_api import YouTubeTranscriptApi
def getTranscript(videoId):
try:
srt = YouTubeTranscriptApi.get_transcript(videoId)
fname = "transcripts/" + videoId + ".txt"
with open(fname, "w") as f:
# iterating through each element of list srt
for i in srt:
# writing each element of srt on a new line
f.write("{}\n".format(i["text"]).replace("\xa0", " ").replace(" — ", " "))
return True
except:
print("A transcript error has occurred")
return False