-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube.py
62 lines (53 loc) · 2.06 KB
/
youtube.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
# coding: utf-8
import sys
from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from pyDownloader import getVideo,getAudio
import os
import platform
if platform.system() == 'Windows':
from win32com.shell import shell, shellcon
class Form(QtWidgets.QDialog):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self.ui = uic.loadUi("Youtube_main.ui")
self.ui.show()
self.initUI()
def initUI(self):
self.ui.outputButton.clicked.connect(self.on_click)
self.ui.buttonBox.accepted.connect(self.accept)
self.ui.buttonBox.rejected.connect(self.reject)
self.ui.videoRadio.setChecked(True)
if platform.system() == 'Windows':
self.ui.outputText.setText(shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0))
elif platform.system() == 'Darwin':
self.ui.outputText.setText(os.path.expanduser("~/Desktop/"))
else:
self.ui.outputText.setText(os.path.expanduser("~/"))
def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName = str(QFileDialog.getExistingDirectory(self, "Select Directory"))
if fileName:
print(fileName)
self.ui.outputText.setText(fileName)
@pyqtSlot()
def on_click(self):
print('PyQt5 button click')
self.openFileNameDialog()
@pyqtSlot()
def accept(self):
urls = self.ui.youtubeURL.toPlainText().splitlines()
if( self.ui.videoRadio.isChecked()):
getVideo(urls, outputPath=self.ui.outputText.text())
else:
getAudio(urls, outputPath=self.ui.outputText.text())
@pyqtSlot()
def reject(self):
self.exit()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = Form()
sys.exit(app.exec())