aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-12-20 18:55:06 -0500
committerJesús <heckyel@hyperbola.info>2019-12-20 18:55:06 -0500
commitdf2fc30636efd1b61f6da361446e4d6d4c41c07e (patch)
treeb069b71c6c82b92ca6362f643e617a19102c5efb
parent805bf77fae17dc41978e1810e7424029376de890 (diff)
downloadhypervideo-gui-df2fc30636efd1b61f6da361446e4d6d4c41c07e.tar.lz
hypervideo-gui-df2fc30636efd1b61f6da361446e4d6d4c41c07e.tar.xz
hypervideo-gui-df2fc30636efd1b61f6da361446e4d6d4c41c07e.zip
pep8
-rw-r--r--hypervideo_gui/main_ui.py187
1 files changed, 104 insertions, 83 deletions
diff --git a/hypervideo_gui/main_ui.py b/hypervideo_gui/main_ui.py
index 721d481..8ec63d0 100644
--- a/hypervideo_gui/main_ui.py
+++ b/hypervideo_gui/main_ui.py
@@ -67,8 +67,8 @@ class MainWindow(QMainWindow):
else:
self.msgbox("hypervideo not found\nPlease install hypervideo")
- self.default_formats_menu_items = ['Video/Audio - Best Quality',
- 'Audio Only - Best Quality']
+ self.dflt_fms_menu_items = ['Video/Audio - Best Quality',
+ 'Audio Only - Best Quality']
self.list = []
@@ -82,24 +82,35 @@ class MainWindow(QMainWindow):
btnwidth = 155
self.cmd = None
- self.process = QProcess(self)
- self.process.started.connect(lambda: self.show_message("Creating List"))
- self.process.started.connect(lambda: self.btn_get_formats.setEnabled(False))
- self.process.finished.connect(lambda: self.show_message("Finished creating List"))
- self.process.finished.connect(self.process_finished)
- self.process.finished.connect(lambda: self.btn_get_formats.setEnabled(True))
- self.process.readyRead.connect(self.process_output)
-
- self.download_process = QProcess(self)
- self.download_process.setProcessChannelMode(QProcess.MergedChannels)
- self.download_process.started.connect(lambda: self.show_message("Download started"))
- self.download_process.started.connect(lambda: self.download_button.setEnabled(False))
- self.download_process.started.connect(lambda: self.cancel_button.setEnabled(True))
- self.download_process.finished.connect(lambda: self.show_message("Download finished"))
- self.download_process.finished.connect(lambda: self.download_button.setEnabled(True))
- self.download_process.finished.connect(lambda: self.cancel_button.setEnabled(False))
- self.download_process.finished.connect(lambda: self.setWindowTitle(__title__))
- self.download_process.readyRead.connect(self.dl_process_out)
+ self.proc = QProcess(self)
+ self.proc.started.connect(
+ lambda: self.show_message("Creating List"))
+ self.proc.started.connect(
+ lambda: self.btn_get_fmts.setEnabled(False))
+ self.proc.finished.connect(
+ lambda: self.show_message("Finished creating List"))
+ self.proc.finished.connect(self.process_finished)
+ self.proc.finished.connect(
+ lambda: self.btn_get_fmts.setEnabled(True))
+ self.proc.readyRead.connect(self.process_output)
+
+ self.dl_proc = QProcess(self)
+ self.dl_proc.setProcessChannelMode(QProcess.MergedChannels)
+ self.dl_proc.started.connect(
+ lambda: self.show_message("Download started"))
+ self.dl_proc.started.connect(
+ lambda: self.dl_button.setEnabled(False))
+ self.dl_proc.started.connect(
+ lambda: self.cancel_button.setEnabled(True))
+ self.dl_proc.finished.connect(
+ lambda: self.show_message("Download finished"))
+ self.dl_proc.finished.connect(
+ lambda: self.dl_button.setEnabled(True))
+ self.dl_proc.finished.connect(
+ lambda: self.cancel_button.setEnabled(False))
+ self.dl_proc.finished.connect(
+ lambda: self.setWindowTitle(__title__))
+ self.dl_proc.readyRead.connect(self.dl_process_out)
self.setGeometry(0, 0, 600, 250)
self.setFixedSize(600, 250)
@@ -132,7 +143,8 @@ class MainWindow(QMainWindow):
lbl_url.setFixedWidth(btnwidth)
lbl_url.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
self.lbl_url_path = QLineEdit()
- self.lbl_url_path.setPlaceholderText('https://invidio.us/watch?v=8SdPLG-_wtA')
+ self.lbl_url_path.setPlaceholderText(
+ 'https://invidio.us/watch?v=8SdPLG-_wtA')
# Set up callback to update video formats when URL is changed
self.lbl_url_path.textChanged.connect(self.reset_video_formats)
@@ -155,31 +167,31 @@ class MainWindow(QMainWindow):
hlayout2.addWidget(self.lbl_out_path)
# Hypervideo path
- btn_hypervideo_path = QToolButton()
- btn_hypervideo_path.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
- btn_hypervideo_path.setText("Select hypervideo")
- btn_hypervideo_path.setFixedWidth(btnwidth)
- btn_hypervideo_path.clicked.connect(self.select_hyper_dl)
- self.lbl_hypervideo_path = QLineEdit(str(self.hypervideo_bin))
- self.lbl_hypervideo_path.textChanged.connect(self.update_hypervideo_path)
- self.lbl_hypervideo_path.setPlaceholderText("Insert Path to Hypervideo")
+ btn_exec_path = QToolButton()
+ btn_exec_path.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
+ btn_exec_path.setText("Select hypervideo")
+ btn_exec_path.setFixedWidth(btnwidth)
+ btn_exec_path.clicked.connect(self.select_hyper_dl)
+ self.lbl_exec_path = QLineEdit(str(self.hypervideo_bin))
+ self.lbl_exec_path.textChanged.connect(self.update_hypervideo_path)
+ self.lbl_exec_path.setPlaceholderText("Insert Path to Hypervideo")
hlayout3 = QHBoxLayout()
- hlayout3.addWidget(btn_hypervideo_path)
- hlayout3.addWidget(self.lbl_hypervideo_path)
-
- self.download_button = QToolButton()
- self.download_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
- self.download_button.setText("Download")
- self.download_button.clicked.connect(self.download_selected)
- self.download_button.setFixedWidth(btnwidth)
- self.download_button.setFixedHeight(32)
-
- self.btn_get_formats = QToolButton()
- self.btn_get_formats.setText('Get Formats')
- self.btn_get_formats.setFixedWidth(btnwidth)
- self.btn_get_formats.setFixedHeight(32)
- self.btn_get_formats.clicked.connect(self.fill_combo_formats)
+ hlayout3.addWidget(btn_exec_path)
+ hlayout3.addWidget(self.lbl_exec_path)
+
+ self.dl_button = QToolButton()
+ self.dl_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
+ self.dl_button.setText("Download")
+ self.dl_button.clicked.connect(self.download_selected)
+ self.dl_button.setFixedWidth(btnwidth)
+ self.dl_button.setFixedHeight(32)
+
+ self.btn_get_fmts = QToolButton()
+ self.btn_get_fmts.setText('Get Formats')
+ self.btn_get_fmts.setFixedWidth(btnwidth)
+ self.btn_get_fmts.setFixedHeight(32)
+ self.btn_get_fmts.clicked.connect(self.fill_combo_formats)
self.cancel_button = QToolButton()
self.cancel_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
@@ -189,9 +201,9 @@ class MainWindow(QMainWindow):
self.cancel_button.setFixedWidth(btnwidth)
self.cancel_button.setFixedHeight(32)
- self.video_format_combobox = QComboBox()
- self.populate_video_format_combobox(self.default_formats_menu_items)
- self.video_format_combobox.setFixedHeight(26)
+ self.vfms_cmbox = QComboBox()
+ self.populate_video_format_combobox(self.dflt_fms_menu_items)
+ self.vfms_cmbox.setFixedHeight(26)
self.pbar = QProgressBar()
self.pbar.setFixedHeight(16)
@@ -200,15 +212,15 @@ class MainWindow(QMainWindow):
self.pbar.setValue(0)
btn_layout = QHBoxLayout()
- btn_layout.addWidget(self.download_button)
- btn_layout.addWidget(self.btn_get_formats)
+ btn_layout.addWidget(self.dl_button)
+ btn_layout.addWidget(self.btn_get_fmts)
btn_layout.addWidget(self.cancel_button)
vlayout = QVBoxLayout()
vlayout.addLayout(hlayout)
vlayout.addLayout(hlayout2)
vlayout.addLayout(hlayout3)
- vlayout.addWidget(self.video_format_combobox)
+ vlayout.addWidget(self.vfms_cmbox)
vlayout.addWidget(self.pbar)
vlayout.addLayout(btn_layout)
@@ -229,8 +241,10 @@ class MainWindow(QMainWindow):
msg = QMessageBox()
msg.setWindowTitle('About us')
- msg.setText("<p align='center'>Written with Python3 and PyQt5<br>"
- "Version: %s <br> License: %s </p>" % (__version__, __license__))
+ msg.setText(
+ "<p align='center'>Written with Python3 and PyQt5<br>"
+ "Version: %s <br> License: %s </p>" %
+ (__version__, __license__))
msg.setIcon(QMessageBox.Information)
self.show()
@@ -271,12 +285,16 @@ class MainWindow(QMainWindow):
def update_output_path(self):
''' Update Path Output '''
self.out_folder_path = self.lbl_out_path.text()
- self.show_message("Output path changed to: %s" % self.lbl_out_path.text())
+ self.show_message(
+ "Output path changed to: %s" %
+ self.lbl_out_path.text())
def update_hypervideo_path(self):
''' Update Hypervideo Path Output '''
- self.hypervideo_bin = self.lbl_hypervideo_path.text()
- self.show_message("hypervideo path changed to: %s" % self.lbl_hypervideo_path.text())
+ self.hypervideo_bin = self.lbl_exec_path.text()
+ self.show_message(
+ "hypervideo path changed to: %s" %
+ self.lbl_exec_path.text())
def show_message(self, message):
''' Show Message in StatuBar '''
@@ -284,11 +302,11 @@ class MainWindow(QMainWindow):
def select_hyper_dl(self):
''' Select hypervideo executable '''
- file_name, _ = QFileDialog.getOpenFileName(self, "locate hypervideo",
- "/usr/bin/hypervideo", "exec Files (*)")
+ file_name, _ = QFileDialog.getOpenFileName(
+ self, "locate hypervideo", "/usr/bin/hypervideo", "exec Files (*)")
debugging('Value of filename is %s' % file_name)
if file_name is not None:
- self.lbl_hypervideo_path.setText(file_name)
+ self.lbl_exec_path.setText(file_name)
self.hypervideo_bin = file_name
def open_output_folder(self):
@@ -300,37 +318,39 @@ class MainWindow(QMainWindow):
self.lbl_out_path.setText(d_path)
def populate_video_format_combobox(self, labels):
- '''Populate the video format combobox with video formats. Clear the previous labels.
- labels {list} -- list of strings representing the video format combobox options
+ '''Populate the video format combobox with video formats.
+ Clear the previous labels.
+ labels {list} -- list of strings representing
+ the video format combobox options
'''
- self.video_format_combobox.clear()
+ self.vfms_cmbox.clear()
for label in labels:
- self.video_format_combobox.addItem(label)
+ self.vfms_cmbox.addItem(label)
def reset_video_formats(self):
''' Clean video formast '''
- idx = self.video_format_combobox.currentIndex()
+ idx = self.vfms_cmbox.currentIndex()
- self.populate_video_format_combobox(self.default_formats_menu_items)
+ self.populate_video_format_combobox(self.dflt_fms_menu_items)
# Preserve combobox index if possible
if idx > 1:
- self.video_format_combobox.setCurrentIndex(0)
+ self.vfms_cmbox.setCurrentIndex(0)
else:
- self.video_format_combobox.setCurrentIndex(idx)
+ self.vfms_cmbox.setCurrentIndex(idx)
def fill_combo_formats(self):
''' Scan formats and Add item to combobox '''
- self.video_format_combobox.clear()
+ self.vfms_cmbox.clear()
if QFile.exists(self.hypervideo_bin):
# Default options
- self.video_format_combobox.addItems(self.default_formats_menu_items[0:2])
+ self.vfms_cmbox.addItems(self.dflt_fms_menu_items[0:2])
self.list = []
self.url_catch = self.lbl_url_path.text()
if not self.lbl_url_path.text() == "":
debugging('Scan Formats')
- self.process.start(self.hypervideo_bin, ['-F', self.url_catch])
+ self.proc.start(self.hypervideo_bin, ['-F', self.url_catch])
else:
self.show_message("URL empty")
else:
@@ -339,9 +359,9 @@ class MainWindow(QMainWindow):
def process_output(self):
''' Process out '''
try:
- output = str(self.process.readAll(), encoding='utf8').rstrip()
+ output = str(self.proc.readAll(), encoding='utf8').rstrip()
except TypeError:
- output = str(self.process.readAll()).rstrip()
+ output = str(self.proc.readAll()).rstrip()
self.list.append(output)
def process_finished(self):
@@ -352,9 +372,9 @@ class MainWindow(QMainWindow):
mylist = out.rsplit('\n')
debugging('Formats process finished with list: %s' % mylist)
if mylist != ['']:
- self.video_format_combobox.addItems(mylist)
- count = self.video_format_combobox.count()
- self.video_format_combobox.setCurrentIndex(count-1)
+ self.vfms_cmbox.addItems(mylist)
+ count = self.vfms_cmbox.count()
+ self.vfms_cmbox.setCurrentIndex(count - 1)
else:
self.show_message("Formats empty or URL without video")
@@ -364,12 +384,12 @@ class MainWindow(QMainWindow):
self.pbar.setValue(0)
self.url_catch = self.lbl_url_path.text()
quality = None
- if self.video_format_combobox.currentText() == self.default_formats_menu_items[0]:
+ if self.vfms_cmbox.currentText() == self.dflt_fms_menu_items[0]:
quality = 'bestvideo+bestaudio/best'
options = []
options.append('-f')
options.append(quality)
- elif self.video_format_combobox.currentText() == self.default_formats_menu_items[1]:
+ elif self.vfms_cmbox.currentText() == self.dflt_fms_menu_items[1]:
quality = '--audio-quality'
options = []
options.append('-x')
@@ -378,7 +398,7 @@ class MainWindow(QMainWindow):
options.append(quality)
options.append('192')
else:
- quality = self.video_format_combobox.currentText().partition(" ")[0]
+ quality = self.vfms_cmbox.currentText().partition(" ")[0]
options = []
options.append('-f')
options.append(quality)
@@ -390,8 +410,8 @@ class MainWindow(QMainWindow):
self.show_message("Download started")
debugging('Download Selected Quality: %s' % quality)
debugging('Download URL: %s' % self.url_catch)
- self.download_process.setWorkingDirectory(self.out_folder_path)
- self.download_process.start(self.hypervideo_bin, options)
+ self.dl_proc.setWorkingDirectory(self.out_folder_path)
+ self.dl_proc.start(self.hypervideo_bin, options)
else:
self.show_message("List of available files is empty")
else:
@@ -402,9 +422,10 @@ class MainWindow(QMainWindow):
def dl_process_out(self):
''' Download process out '''
try:
- out = str(self.download_process.readAll(), encoding='utf8').rstrip()
+ out = str(self.dl_proc.readAll(),
+ encoding='utf8').rstrip()
except TypeError:
- out = str(self.download_process.readAll()).rstrip()
+ out = str(self.dl_proc.readAll()).rstrip()
out = out.rpartition("[download] ")[2]
self.show_message("Progress: %s" % out)
self.setWindowTitle(out)
@@ -418,9 +439,9 @@ class MainWindow(QMainWindow):
def cancel_download(self):
''' Cancel download'''
- if self.download_process.state() == QProcess.Running:
+ if self.dl_proc.state() == QProcess.Running:
debugging('Process is running, will be cancelled')
- self.download_process.close()
+ self.dl_proc.close()
self.show_message("Download cancelled")
self.pbar.setValue(0)
self.cancel_button.setEnabled(False)