-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (55 loc) · 1.89 KB
/
main.py
File metadata and controls
74 lines (55 loc) · 1.89 KB
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
from PyQt5 import uic
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import os
import sys
import pytube
import resources
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'ui/dialog.ui'))
FORM_RES_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'ui/resolution.ui'))
class YoutubeDialog(QDialog, FORM_CLASS):
def __init__(self):
super(YoutubeDialog, self).__init__()
self.setupUi(self)
self.downloadButton.clicked.connect(self.__download)
self.saveButton.clicked.connect(self.__save)
self.closeButton.clicked.connect(self.__close)
def __download(self):
url = self.urlEdit.text()
# TODO: add url validator
if url and url is "":
QMessageBox.warning(self,
"URL Error",
"Please provide a valid URL")
return
if self.saveEdit.text() and self.saveEdit.text() is "":
QMessageBox.warning(self,
"Save path Error",
"Please provide a path")
return
# TODO: find better library
yt = pytube.YouTube(url)
videos = yt.get_videos()
vid = videos[2]
vid.download(self.saveEdit.text())
QMessageBox.success(self,
"Success",
yt.filename + "\nHas been successfully downloaded")
# TODO: add progressBar
def __save(self):
# Fix me
dateiname = QFileDialog.getExistingDirectory(
self, "Save", "/home/hka/", QFileDialog.ShowDirsOnly)
self.saveEdit.setText(dateiname)
def __close(self):
sys.exit()
def main():
app = QApplication(sys.argv)
form = YoutubeDialog()
form.show()
app.exec_()
if __name__ == '__main__':
main()