File size: 592 Bytes
168a18b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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