-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuzikIndirici.py
220 lines (183 loc) · 7.02 KB
/
muzikIndirici.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Youtube Müzik İndirici
from tkinter import *
from yt_dlp import YoutubeDL as ytdl
from threading import Thread as thr
from time import sleep
import plyer.platforms.win.notification
from plyer import notification as bildirim
from os import path, getcwd
from sys import exit as exitt
win = Tk()
win.config(bg= "#7AC5CD")
win.geometry("800x535")
win.title("Müzikİndirici")
win.maxsize(900, 600)
win.minsize(680, 420)
Label(text= "YouTube Müzik İndirici").pack()
# Link girilen alan
giris = Entry(width= 50)
giris.place(anchor= CENTER, relx= 0.5, rely= 0.5)
linkyazi = Label(text= "Link:")
linkyazi.place(anchor= CENTER, relx= 0.25, rely= 0.5)
# Pencere üstünde bilgilendirme yazıları göstermeye yarayan class
class Yazan:
def __yaziYaz(self, metin, sure= 0, yer= "orta"):
global yazi1, yazi2, yazi3
if yer == "üst":
try: yazi1.destroy()
except: pass
yazi1 = Label(text= metin)
yazi1.place(anchor= CENTER, relx= 0.5, rely= 0.2)
if sure:
sleep(sure)
if not kapatildi: yazi1.destroy()
elif yer == "orta":
try: yazi2.destroy()
except: pass
yazi2 = Label(text= metin)
yazi2.place(anchor= CENTER, relx= 0.5, rely= 0.3)
if sure:
sleep(sure)
if not kapatildi: yazi2.destroy()
elif yer == "alt":
try: yazi3.destroy()
except: pass
yazi3 = Label(text= metin)
yazi3.place(anchor= CENTER, relx= 0.5, rely= 0.4)
if sure:
sleep(sure)
if not kapatildi: yazi3.destroy()
def hata(self):
def f(): self.__yaziYaz("Hata oluştu, linki kontrol edin..", 4, "alt")
thr(target= f).start()
def mesaj(self, mesaj):
def f(): self.__yaziYaz(mesaj, 4, "orta")
thr(target= f).start()
def txtmesaj(self, mesaj):
def f(): self.__yaziYaz(mesaj, 4, "üst")
thr(target= f).start()
yaz = Yazan()
# İndirme işlemi
def indir(url:str, noplaylist= True):
options = {
"noplaylist": noplaylist,
"format": "bestaudio",
}
with ytdl(options) as ydl:
ydl.download([url])
# İlk butonun işlevi
def Indir():
kilitle()
isimDegis("Ses İndiriliyor", "Ses İndiriliyor")
link = giris.get()
giris.delete(0, END)
try:
indir(link, noplaylist= not cekvar.get())
yaz.mesaj("Ses İndirildi")
if bildirimler == 1:
bildirim.notify("Ses İndirildi 🎶", f"{getcwd()} dizinine indirildi.")
except:
yaz.hata()
finally:
isimDegis("İndir", txtyazi())
kilitac()
def buton1():
t = thr(target= Indir)
t.daemon = True
t.start()
# İkinci butonun görevi için class
class Linklertxt:
def Indirtxt(self, linkmz):
global success, fail
try:
print("İndiliyor..")
indir(linkmz, noplaylist= True)
print("İndirildi.")
success += 1
return False
except:
fail += 1
print("İndirilemedi.")
return True
def islem(self):
global success, fail
isimDegis("txt dosyasındaki linkler İndiriliyor..", "Konsoldan takip edebilirsiniz..")
success, fail = 0, 0
try:
with open("linkler.txt", "r") as fff:
yaz.txtmesaj("txt Dosyasındaki Videolar İndiriliyor")
sleep(0.5)
uzunluk = len(fff.readlines())
fff.seek(0)
basarisizlar = []
for i, satir in enumerate(fff.readlines(), 1):
sıra = f"{i}/{uzunluk}"; print(sıra)
if self.Indirtxt(satir): basarisizlar.append(sıra)
print(f"İşlem {success} başarıyla, {fail} başarısızlıkla tamamlandı.")
if basarisizlar: print("Başarısız olanlar:", basarisizlar)
yaz.mesaj(f"İşlem {success} başarıyla, {fail} başarısızlıkla tamamlandı.")
isimDegis("İndir", txtyazi())
kilitac()
if bildirimler == 1:
bildirim.notify("İşlem Tamamlandı 🎶", f"Başarılı İndirme: {success} - Başarısız İndirme: {fail}")
print("\n")
except:
yaz.txtmesaj("linkler.txt dosyası bulunamadı.")
def txtrun(self):
if path.exists("linkler.txt"):
kilitle()
isimDegis("İndiriliyor", "İndiriliyor")
t = thr(target= self.islem)
t.daemon = True
t.start()
else:
with open("linkler.txt", "w") as fff:
yaz.txtmesaj("linkler.txt Dosyası Oluşturuldu")
txtbutonu['text'] = "linkler.txt dosyasındaki linkleri İndir"
def kilitle(): # butonları kilitler
indirbutonu['state'] = "disabled"
txtbutonu['state'] = "disabled"
def kilitac(): # butonların kilidini açar
indirbutonu['state'] = "active"
txtbutonu['state'] = "active"
def isimDegis(indirbuton, txtbuton): # butonların üzerindeki yazıları değiştirir
indirbutonu['text'] = indirbuton
txtbutonu['text'] = txtbuton
# Bildirim ayarlarını yapan buton(ların)un fonksiyonları
bildirimler = 0
def bildirimAktif():
global bildirimler, bildirAktif, bildirPasif
bildirimler = 1
bildirAktif.destroy()
bildirPasif = Button(text= "Bildirimleri kapat", width= 14, command= bildirimPasif)
bildirPasif.place(anchor= CENTER, relx= 0.9, rely= 0.85)
def bildirimPasif():
global bildirimler, bildirAktif, bildirPasif
bildirimler = 0
bildirPasif.destroy()
bildirAktif = Button(text= "Bildirimleri aç", width= 14, command= bildirimAktif)
bildirAktif.place(anchor= CENTER, relx= 0.9, rely= 0.85)
bildirAktif = Button(text= "Bildirimleri aç", width= 14, command= bildirimAktif)
bildirAktif.place(anchor= CENTER, relx= 0.9, rely= 0.85)
# İndir butonu
indirbutonu = Button(text= "İndir", width= 35, height= 2, command= buton1)
indirbutonu.place(anchor= CENTER, relx= 0.5, rely= 0.65)
# txt indirici butonu
def txtyazi():
if path.exists("linkler.txt"): return "linkler.txt dosyasındaki linkleri İndir"
else: return "linkler.txt dosyası oluştur"
txtbutonu = Button(text= txtyazi(), width= 35, height= 2, command= Linklertxt().txtrun)
txtbutonu.place(anchor= CENTER, relx= 0.5, rely= 0.75)
# Playlist indirme ayarı
cekvar = BooleanVar()
cek = Checkbutton(text= "Playlist ile beraber indir", variable= cekvar)
cek.place(relx= 0.9, rely= 0.78, anchor= CENTER)
kapatildi = 0
def kapat():
global kapatildi
kapatildi = 1
win.destroy(); exitt()
win.protocol("WM_DELETE_WINDOW", kapat)
Kapat = Button(text= "Kapat", width= 14, command= kapat)
Kapat.place(anchor= CENTER, relx= 0.9, rely= 0.92)
win.mainloop()