-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
111 lines (88 loc) · 3.6 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
import sys, os
from PyQt6 import uic
from PyQt6.QtWidgets import QApplication, QMainWindow, QButtonGroup, QFileDialog
from downloader import Downloader
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.set_globals()
self.initUI()
# initialize button signals
self.download_button.clicked.connect(self.download)
self.copy_button.clicked.connect(self.copy)
self.clear_button.clicked.connect(self.clear)
# set the folder to which the files should be downloaded
self.outpath_button.clicked.connect(self.choose_outpath)
# set the folder with yt-dlp and ffmpeg
self.libpath_button.clicked.connect(self.choose_libpath)
# initialize checkbox signals
self.thumbnail_checkbox.stateChanged.connect(self.sync_checkbox)
# change variables if paths was changed
self.outpath_line.textChanged.connect(self.change_paths)
self.libpath_line.textChanged.connect(self.change_paths)
# set QLineEdit cursor to the first position
self.outpath_line.setCursorPosition(0)
self.libpath_line.setCursorPosition(0)
# initialize QThread class for download
self.downloader = Downloader(mainwindow=self)
# set global variables
def set_globals(self):
user = os.environ.get("USERNAME")
self.ydl_opts = {}
self.outpath = f"C:/Users/{user}/Desktop/"
self.libpath = f"{os.path.abspath(os.curdir)}/lib/".replace("\\", "/")
self.mode = "Video"
self.res = "Best"
def initUI(self):
# load most of widgets from file
uic.loadUi('ui/main.ui', self)
# set text to appropriate lines
self.outpath_line.setText(self.outpath)
self.libpath_line.setText(self.libpath)
# connect buttons with functions (signals)
self.video_button.toggled.connect(self.set_mode)
self.audio_button.toggled.connect(self.set_mode)
# make a group to radiobuttons
self.number_group1 = QButtonGroup(self)
self.number_group1.addButton(self.video_button)
self.number_group1.addButton(self.audio_button)
# sync checkbox state
def sync_checkbox(self):
if self.thumbnail_checkbox.isChecked() == False:
self.youtube_cover_checkbox.setEnabled(False)
else:
self.youtube_cover_checkbox.setEnabled(True)
# change variables if user changes paths
def change_paths(self):
self.outpath = self.outpath_line.text()
self.libpath = self.libpath_line.text()
# interface for selecting a folder manually
def choose_outpath(self):
self.outpath = QFileDialog.getExistingDirectory(None, 'Select a folder:', os.getcwd())
if self.outpath:
self.outpath_line.setText(self.outpath)
# interface for selecting a folder manually
def choose_libpath(self):
self.libpath = QFileDialog.getExistingDirectory(None, 'Select a folder:', os.getcwd())
if self.libpath:
self.libpath_line.setText(self.libpath)
# set mode (video or audio)
def set_mode(self):
radioBtn = self.sender()
if radioBtn.isChecked():
self.mode = radioBtn.text()
# copy button
def copy(self):
clipboard = QApplication.clipboard()
clipboard.setText(self.url_line.text())
# clear button
def clear(self):
self.url_line.clear()
# download the file
def download(self):
self.downloader.start()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWindow()
ex.show()
sys.exit(app.exec())