Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python subtitles from youtube

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading