arkadaşlar merhaba. kendimi geliştirmek adına youtube downloader ile ilgili bir proje yapmaya çalışıyorum fakat dosya seçmeye çalışırken uygulama donuyor. Sebebini açıklar mısınız?
import yt_dlp
import os
from tkinter import *
from pyperclip import paste
from time import sleep
import threading
from customtkinter import *
import sqlite3
from tkinter import filedialog
con = sqlite3.connect("ytsave.db")
cursor = con.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS ytsaving (directory TEXT)")
con.commit()
window = Tk()
window.geometry("1030x720")
window.resizable(False,False)
window.config(border=0)
window.config(bg="white")
mp4 = PhotoImage(file="mp4.png")
mp3 = PhotoImage(file="mp3.png")
webm = PhotoImage(file="webm.png")
setting = PhotoImage(file="settings.png")
label = Label(window, text="Please Paste Youtube Link", fg="black", font="Thunderbolt", bg="white")
label.place(x= 50, y=20)
link = CTkEntry(window, width=405, font=(25), border=0, fg_color="#e3e1e1")
link.place(x=55, y= 55)
title = Label(window, text="", fg="black", bg="white")
title1 = Label(window, text="", fg="black", bg="white")
title2 = Label(window, text="", fg="black", bg="white")
title.place(x= 600, y=52)
title1.place(x= 600, y=80)
title2.place(x= 600, y=100)
opt = Label(window, fg="black", font=("Thunderbolt", 15), bg="white" )
opt.place(x=50, y=330)
frame = Frame(window, width=370, height=720, bg="#e3e1e1",)
frame.place(x= 1030)
a = Label(frame, text="", bg="#e3e1e1", height=720, width=570 ).pack()
b = Label(window, text="Select the directory where you want the video to be installed: ", bg="#e3e1e1").place(x= 1040, y=30)
direc = Entry(window, width=80, border=0, state=DISABLED)
direc.place(x=1040, y=60)
mp3button = Button(window, border=0, bg="white", activebackground="white", state=DISABLED)
mp3button.place(x= 240, y=400)
webmbutton = Button(window, image=webm, border=0, bg="white", activebackground="white", state=DISABLED)
webmbutton.place(x= 380, y=400)
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
#cursor.execute("Insert into ytsaving Values(?)", (desktop,))
#con.commit()
ydl = {
'format': 'bestvideo+bestaudio/best',
'postprocessors': [{
'key': 'FFmpegVideoConvertor',
'preferedformat': 'mp4'
}],
'outtmpl': desktop+'/%(title)s.%(ext)s',
'noplaylist':True
}
def download():
links = link.get()
ydl = {
'format': 'bestvideo+bestaudio/best',
'postprocessors': [{
'key': 'FFmpegVideoConvertor',
'preferedformat': 'mp4'
}],
'outtmpl': desktop+'/%(title)s.%(ext)s',
'noplaylist':True
}
try:
with yt_dlp.YoutubeDL(ydl) as ydll:
ydll.download([links])
except:
pass
def filee():
global filename
filename = filedialog.askdirectory()
#direc.delete(0, END)
direc.insert(END, filename)
file = Button(window, text="Select", command=filee)
file.place(x=1560, y=60)
button = True
def option():
global button
if button == True:
window.geometry("1600x720")
button = False
else:
window.geometry("1030x720")
button = True
mp4button = Button(window, border=0, bg="white", activebackground="white", state=DISABLED, command=download)
mp4button.place(x= 100, y=400)
settingss = Button(window, image=setting, border=0, bg= "white", activebackground="white", command=option)
settingss.place(x=7, y=10)
def past():
result = paste()
link.insert(0, result)
def dele():
link.delete(0, END)
def delandpast():
dele()
past()
delpas = Button(window, text="Delete", command=dele, font=("Thunderbolt", 10), bg="white")
delpas.place(x=480, y=60)
pas = Button(window, text="Paste", command=past,font=("Thunderbolt", 10), bg="white")
pas.place(x=480, y= 30)
def main():
links = link.get()
number = len(links)
if number>0:
try:
with yt_dlp.YoutubeDL(ydl) as ydll:
info = ydll.extract_info(links, download=False)
if info["duration"]/3600 <1:
min = info["duration"]//60
sec = info["duration"]%60
title1.config(text=f"{min:02d}:{sec:02d}")
if info["duration"]/3600 >=1:
hour = info["duration"]//3600
a = info["duration"]- hour*3600
min = a//60
sec = a%60
title1.config(text=f"{hour:02d}:{min:02d}:{sec:02d}")
title.config(text=info["title"])
title2.config(text=f"{info["height"]}P")
mp4button.config(image=mp4, state=ACTIVE)
mp3button.config(image=mp3, state=ACTIVE)
webmbutton.config(image= webm, state=ACTIVE)
opt.config(text="Download Options:")
except Exception as e:
print(f"Hata mesajı: {e}")
link.delete(0, END)
else:
lambda:None
def control():
while True:
links = link.get()
number = len(links)
if number== 0:
title.config(text="")
title1.config(text="")
title2.config(text="")
webmbutton.config(image="",state=DISABLED)
mp4button.config(image="", state=DISABLED)
mp3button.config(image="", state=DISABLED)
opt.config(text="")
while number == 0:
links = link.get()
number = len(links)
if number!= 0:
main()
sleep(1)
else:
lambda:None
t = threading.Thread(target=control, daemon=True)
t.start()
window.mainloop()