Код: Выделить всё
from tkinter import filedialog
from tkinter.ttk import Progressbar
import pytubefix.exceptions
from pytubefix import YouTube
import time
def openFile():
global filepath
filepath = filedialog.askdirectory()
print(filepath)
def info(stream, chunk, bytes_remaining):
print('run')
total_size = stream.filesize
bytes_downloaded = total_size - bytes_remaining
percentage = (bytes_downloaded / total_size) * 100
if bar['value'] < 100:
bar['value'] = percentage
window.update_idletasks()
else:
bar['value'] = 100
print("Done!")
#setup
window = Tk()
window.geometry("400x400")
window.title("Jun")
window.config(background='black')
label = Label(window, text='Youtube Video Downloader')
label.config(font=('Monospace', 22))
label.pack()
button = Button(window, text="Click me to select a directory!", command=openFile)
button.config(font=('Monospace',10))
button.pack()
entry = Entry()
entry.config(font=('Monospace', 20))
entry.insert(0, 'Enter link here')
bar = Progressbar(window, orient=HORIZONTAL, length=300)
bar.pack(pady=10)
def submit():
url = entry.get()
if not url or url == 'Enter link here':
print("Error: Please enter a valid YouTube link.")
try:
print("try block running")
yt = YouTube(url, on_progress_callback=info)
print(f"Video Name: {yt.title}")
ys = yt.streams.get_highest_resolution()
ys.download(output_path=filepath)
except NameError:
print("Enter a valid directory")
except pytubefix.exceptions.VideoUnavailable:
print("Video is unavailable")
download = Button(window, text="submit", command=submit)
entry.pack()
download.pack()
window.mainloop()
Имя видео: (название видео)
Процесс завершен с кодом выхода 0»
Подробнее здесь: https://stackoverflow.com/questions/798 ... es-not-run
Мобильная версия