Python subtitles from youtube

Advertisements

I wrote a code but it doesn’t work couly you help me to find a mistake?

from youtube_transcript_api import YouTubeTranscriptApi
import os

srt = YouTubeTranscriptApi.get_transcript("SW14tOda_kI")
text = ""
with open("file.txt", "w") as file:
    for i in srt:
    text += i["text"] + "\n"
    file.write(text)
os.startfile("file.txt")

>Solution :

You have indentation problem. the correct code is:

from youtube_transcript_api import YouTubeTranscriptApi
import os

srt = YouTubeTranscriptApi.get_transcript("SW14tOda_kI")
text = ""
with open("file.txt", "w") as file:
    for i in srt:
        text += i["text"] + "\n"
    file.write(text)
os.startfile("file.txt")

Leave a ReplyCancel reply