This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
118 lines (102 loc) · 3.21 KB
/
main.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
import os
import threading
try:
from pytube import YouTube
import pygame
import tkinter as tk
except ModuleNotFoundError:
os.system("python -m pip install pytube")
print("PyTube installed on your device!")
os.system("python -m pip install pygame")
print("Pygame installed on your device!")
if os.name != "nt":
os.system("sudo apt-get install python3-tk")
print("Run this script again! ;)")
exit()
def runDownloader(yt):
try:
music_dwn.configure(text=f"{yt.title} is downloading!")
print(yt.title,"is downloading! ⏳")
video = yt.streams.filter(only_audio=True).last()
out_file = video.download(output_path="Music")
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
print(yt.title + " has been successfully download! ✅\n---------------")
except:
music_dwn.configure(text="[Error!] - Check in console")
print("[Error!] - Please check your URLs or Folder and try again")
print("[Error!] - If can't download again please try to use runDownloader_debug() to download.")
print("[Error!] - You can edit code on line 39 to debug error")
btn_submit.configure(state="normal")
exit()
def runDownloader_debug(yt):
music_dwn.configure(text=f"{yt.title} is downloading!")
print(yt.title,"is downloading! ⏳")
video = yt.streams.filter(only_audio=True).last()
out_file = video.download(output_path="Music")
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
print(yt.title + " has been successfully download! ✅\n---------------")
pygame.init()
os.system('cls' if os.name=='nt' else 'clear')
complete_sound = pygame.mixer.Sound("complete.mp3")
def startDownload(link: list):
for l in link:
runDownloader(YouTube(l))
# runDownloader_debug(YouTube(l))
os.system('cls' if os.name=='nt' else 'clear')
print("=================== [✅] ===================")
print("Download successfully!")
print("=================== [✅] ===================")
complete_sound.play()
music_dwn.configure(text="Successfully!")
os.system('explorer Music' if os.name=='nt' else '')
btn_submit.configure(state="normal")
def start_cli():
btn_submit.configure(state="disabled")
link_all = link.get("1.0", "end-1c")
link_note = link_all.splitlines()
thr = threading.Thread(target=startDownload, args=[link_note])
thr.start()
root = tk.Tk()
root.title("YouTube Downloader")
root.geometry("720x600")
root.resizable(0,0)
root.configure(bg="#6C3428")
title = tk.Label(
root,
text="Music Downloader",
font=('',20),
bg="#C38154",
fg="#FFFFFF"
)
link = tk.Text(
root,
width=80
)
music_dwn = tk.Label(
root,
text="Wating for downloading!",
bg="#7D7463",
fg="#FFFFFF"
)
btn_submit = tk.Button(
root,
text="Download!",
bg="#C38154",
fg="#FFFFFF",
font=('',18),
command=start_cli
)
credit = tk.Label(
root,
text="Council PCSHSST (2565-2566) - IT Department",
)
title.pack(pady=20)
link.pack()
music_dwn.pack(pady=4)
btn_submit.pack(pady=15)
credit.pack(side=tk.BOTTOM)
root.mainloop()