How to get the text or subtitles from a youtube video with GUI

This is an update version of the code to get text or subtitles from youtube videos.

# install in the cmd
# pip install youtube_transcript_api
from youtube_transcript_api import YouTubeTranscriptApi
import os
import tkinter as tk

def get_sub(address):
	srt = YouTubeTranscriptApi.get_transcript(address.split("/")[-1],
	languages=['it'])
	# text.insert("0.0", srt)
	for i in srt:
		for k, v in i.items():
			if k == "text":
				text.insert(tk.END, v + "\n")


	# YouTubeTranscriptApi.get_transcripts(video_ids, languages=['de', 'en'])
	testo = ""
	with open("file.txt", "w") as file:
		for i in srt:
			testo += i["text"] + " "

		file.write(testo)

	os.startfile("file.txt")

root = tk.Tk()
text0 = tk.Label(root,
	text="Inserisci indirizzo youtube/yt address")
text0.pack()
text1 = tk.Entry(root)
text1.pack()
button = tk.Button(root,
	text="Get Subtitles from that video",
	command=lambda: get_sub(text1.get()))
button.pack()
text = tk.Text(root)
text.pack()
root.mainloop()
# linee guida istruzione
# address = "https://youtu.be/kzktA0pVnbU"

Example

[hoops name=”all”[

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.