Program neden donuyor?

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()

Traceback (most recent call last):
  File "/tmp/a.py", line 23, in <module>
    mp4 = PhotoImage(file="mp4.png")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/tkinter/__init__.py", line 4151, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/usr/lib/python3.12/tkinter/__init__.py", line 4098, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "mp4.png": no such file or directory
Traceback (most recent call last):
  File "/tmp/a.py", line 31, in <module>
    link = CTkEntry(window, width=405, font=(25), border=0, fg_color="#e3e1e1")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.12/site-packages/customtkinter/windows/widgets/ctk_entry.py", line 71, in __init__
    self._font = CTkFont() if font is None else self._check_font_type(font)
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.12/site-packages/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py", line 166, in _check_font_type
    raise ValueError(f"Wrong font type {type(font)}\n" +
ValueError: Wrong font type <class 'int'>
For consistency, Customtkinter requires the font argument to be a tuple of len 2 to 6 or an instance of CTkFont.

Usage example:
font=customtkinter.CTkFont(family='<name>', size=<size in px>)
font=('<name>', <size in px>)
Traceback (most recent call last):
  File "/tmp/a.py", line 31, in <module>
    link = CTkEntry(window, width=405, font=('Sans',25), border=0, fg_color="#e3e1e1")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.12/site-packages/customtkinter/windows/widgets/ctk_entry.py", line 93, in __init__
    check_kwargs_empty(kwargs, raise_error=True)
  File "/tmp/venv/lib/python3.12/site-packages/customtkinter/windows/widgets/utility/utility_functions.py", line 18, in check_kwargs_empty
    raise ValueError(f"{list(kwargs_dict.keys())} are not supported arguments. Look at the documentation for supported arguments.")
ValueError: ['border'] are not supported arguments. Look at the documentation for supported arguments.
Traceback (most recent call last):
  File "/tmp/a.py", line 60, in <module>
    desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
                                        ~~~~~~~~~~^^^^^^^^^^^^^^^
  File "<frozen os>", line 685, in __getitem__
KeyError: 'USERPROFILE'

Hepsini duzeltince calisti:

[youtube] Extracting URL: https://www.youtube.com/watch?v=Ss_WGOlYIZU&pp=ygUKZG93bmxvYWRlcg%3D%3D
[youtube] Ss_WGOlYIZU: Downloading webpage
[youtube] Ss_WGOlYIZU: Downloading ios player API JSON
[youtube] Ss_WGOlYIZU: Downloading mweb player API JSON
[youtube] Ss_WGOlYIZU: Downloading player 62ccfae7
[youtube] Ss_WGOlYIZU: Downloading m3u8 information
[youtube] Extracting URL: https://www.youtube.com/watch?v=Ss_WGOlYIZU&pp=ygUKZG93bmxvYWRlcg%3D%3D
[youtube] Ss_WGOlYIZU: Downloading webpage
[youtube] Ss_WGOlYIZU: Downloading ios player API JSON
[youtube] Ss_WGOlYIZU: Downloading mweb player API JSON
[youtube] Ss_WGOlYIZU: Downloading m3u8 information
[info] Ss_WGOlYIZU: Downloading 1 format(s): 313+251
[download] Destination: /tmp/Downloader is back BUT... you need to do this first.f313.webm
[download]   7.6% of  235.91MiB at   13.58MiB/s ETA 00:16^C^\zsh: quit       venv/bin/python a.py
2 Beğeni

Elinize sağlık projenin bitti zaman son halini burada görmek isteriz.

1 Beğeni

teşekkür ederim hocam. bittiği zaman paylaşacağım

hocam kodu atar mısınız? Yeni başladığım için anlamadım açıkçası.

bir de uygulamada küçük değişiklikler yapmıştım siz yanıt atana kadar. Sorunları da az buz çözdüm. siz de attığınız zaman herhalde tüm optimizasyon sıkıntılarını halledeceğim gibi duruyor.

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=60)
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=NORMAL)
direc.place(x=1040, y=60)
direc.insert(END, os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop'))
direc.config(state=DISABLED)

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)



#cursor.execute("Insert into ytsaving Values(?)", (desktop,))
#con.commit()
ydl = {
        'format': 'bestvideo+bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegVideoConvertor',
            'preferedformat': 'mp4'
        }],
        'outtmpl': direc.get()+'/%(title)s.%(ext)s',
        'noplaylist':True
}
def download():
    links = link.get()
    ydl = {
        'format': 'bestvideo+bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegVideoConvertor',
            'preferedformat': 'mp4'
        }],
        'outtmpl': direc.get()+'/%(title)s.%(ext)s',
        'noplaylist':True

    }
    try:    
        with yt_dlp.YoutubeDL(ydl) as ydll:
            ydll.download([links])
    except:
        pass
def filee():
    global filename
    direc.config(state=NORMAL)
    filename = filedialog.askdirectory()
    direc.delete(0, END)
    direc.insert(END,filename)
    direc.config(state=DISABLED)

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:
            delpas.config(state=DISABLED)
            pas.config(state=DISABLED)
            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:")
                delpas.config(state=NORMAL)
                pas.config(state=NORMAL)
        except Exception as e:
            print(f"Hata mesajı: {e}")
            link.delete(0, END)
    else:
        lambda:None
numbe = 0
def hece():
    global numbe
    while True:
        links = link.get()
        numbe = len(links)
        sleep(3)
a = threading.Thread(target=hece, daemon=True)
a.start()
numb = 0 
def heces():
    global numb
    while True:
        links = link.get()
        numb = len(links)
        sleep(0.5)
he = threading.Thread(target=heces, daemon=True)
he.start()
def control():
    while True:
        if numb == 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 numbe == 0:
            delpas.config(state=NORMAL)
            pas.config(state=NORMAL)
            main()
            sleep(1)
            
            
        
t = threading.Thread(target=control, daemon=True)
t.start()



window.mainloop()

mp3
mp4
settings
webm

Hayir.
Hata mesajlarini okuyup, nedenlerini arastirip cozme vaktiniz geldi.

Eksik dosyalari cozmussunuz zaten.
CTkEntry satiri sizde calistigina gore kullandiginiz versiyon eski olabilir. Ben sunlari kullaniyorum:

10:24:31 0 aib@apollon:/tmp% venv/bin/pip freeze
customtkinter==5.2.2
darkdetect==0.8.0
packaging==24.2
pyperclip==1.9.0
tk==0.1.0
yt-dlp==2024.12.6

sikintili parametreleri silince oldu.
USERPROFILE da sadece Windows’ta kullanilan bir degisken.

evet hocam böyle daha mantıklı gibi duruyor

teşekkür ederim buna bir except atayacağım.

neden hocam? custom tkinter yeni sürümünde entryler çalışmıyor mu?

hocalarım merhaba. son bilgilendirme için yazıyorum. Normalde aklımda uygulamaya ekleyecek bir çok özellik vardı fakat uygulama biraz hantal çalışıyor. mesela yüklemeye başlanıldığı anda pencerede yanıt vermiyor yazıyor, donuyor fakat arkada indirme devam ediyor ve indirme sonunda uygulama eski haline geri dönüyordu. Benim zaten yapmak istediğim özellikler video indirilirken ekleyeceklerimdi fakat uygulamaya video indirme sırasında pencere donuyor.
ve şöyle bir şey de var, 10 dakika dan fazla mp4 videolar biraz fazla sürede iniyorlar fakat altı kabul edilecek derecede hızlı. mp3 ve webmden bahsetmeye gerek yok onlar zaten çok hızlı iniyor.
dediğim gibi bu projeye daha devam etmeyeceğim. bu projeyi yaparkenki asıl amacım algoritma, kodlama yeteneğimi geliştirmekti. aksilikler yüzünden bitirdim.
sizler de son halini görün diye paylaşıyorum. @AngaraliJoo , @aib

2 Beğeni