sya

split youtube audio tracks, with an optional pyqt gui
git clone git://src.gearsix.net/sya
Log | Files | Refs | Atom | README

commit 0c473246c62a73e9d587e5fc82aafc62ee6da65b
parent 0311ac7656dce68137162bd85419802f1f542e21
Author: GeaRSiX <gearsix@tuta.io>
Date:   Sun, 30 May 2021 17:37:57 +0100

started fixing up gui.py; added logging window. still WIP.

Diffstat:
Mgui.py | 146+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Msya.py | 11+++++------
2 files changed, 99 insertions(+), 58 deletions(-)

diff --git a/gui.py b/gui.py @@ -1,93 +1,126 @@ +#!/usr/bin/env python3 +# std import os import sys +import threading +# pip import PyQt5.QtCore as pyqt_core import PyQt5.QtWidgets as pyqt_widgets import PyQt5.QtGui as pyqt_gui -class Args: - def __init__(self, args): +def centerWidget(widget): + sg = pyqt_widgets.QDesktopWidget().screenGeometry() + wg = widget.geometry() + return pyqt_core.QPoint(sg.width() / 2 - wg.width() / 2, sg.height() / 2 - wg.height() / 2) + +class LogStream(pyqt_core.QObject): + txt = pyqt_core.pyqtSignal(str) + + def write(self, txt): + self.txt.emit(str(txt)) + +class SyaGui(pyqt_widgets.QMainWindow): + def __init__(self, fnSya, args): + super().__init__() + + self.fnSya = fnSya self.args = args self._edits = {} - self._app = pyqt_widgets.QApplication(sys.argv) - self._widget = pyqt_widgets.QWidget() + options = pyqt_widgets.QWidget() + options.setWindowTitle('sya') + options = self._init_options(options) + #options.setWindowIcon(pyqt_options.QIcon('')) + options.move(centerWidget(options)) + self._options = options + + logs = pyqt_widgets.QPlainTextEdit() + logs.setReadOnly(True) + logs.resize(350, 350) + logs.move(centerWidget(logs)) + self._logs = logs + sys.stdout = LogStream(txt=self.log) - layout = pyqt_widgets.QGridLayout() - self._tracklistKey = 'Tracklist:' - layout.addLayout(self._init_filepicker(self._tracklistKey, self._filepicker_tracklist), 0, 0, 1, 3) + self._options.show() + def _init_options(self, options): + layout = pyqt_widgets.QGridLayout() + # tracklist + self._tracklistLabel = 'Tracklist:' + layout.addLayout(self._init_filepicker(options, self._tracklistLabel, self._filepicker_tracklist), 0, 0, 1, 3) + # formats formats = ['mp3', 'flv', 'wav', 'ogg', 'aac'] - layout.addLayout(self._init_combobox('Format:', self._set_format, formats), 1, 0) - + layout.addLayout(self._init_combobox(options, 'Format:', self._set_format, formats), 1, 0) + # quality qualities = ['0 (better)', '1', '2', '3', '4', '5', '6', '7', '8', '9 (worse)'] - layout.addLayout(self._init_combobox('Quality:', self._set_quality, qualities), 2, 0) - + layout.addLayout(self._init_combobox(options, 'Quality:', self._set_quality, qualities), 2, 0) + # keep self.args.quality = '0' - keep = pyqt_widgets.QCheckBox('keep original', self._widget) + keep = pyqt_widgets.QCheckBox('keep original', options) keep.toggled.connect(self._keep_toggle) layout.addWidget(keep, 1, 1, 2, 1) - - self._outputKey = 'Output:' - layout.addLayout(self._init_filepicker(self._outputKey, self._filepicker_output), 3, 0, 1, 3) - - self._ok = pyqt_widgets.QPushButton('OK') - self._ok.clicked.connect(self._exit) - layout.addWidget(self._ok, 4, 1) - self._check_exit() - - self._widget.setWindowTitle('sya') - self._widget.setLayout(layout) - #widget.setWindowIcon(pyqt_widgets.QIcon('')) - sg = pyqt_widgets.QDesktopWidget().screenGeometry() - wg = self._widget.geometry() - self._widget.move(sg.width() / 2 - wg.width() / 2, sg.height() / 2 - wg.height() / 2) - self._widget.show() - self._app.exec() - - def _init_filepicker(self, labelText, filepickerFn): + # output + self._outputLabel = 'Output:' + layout.addLayout(self._init_filepicker(options, self._outputLabel, self._filepicker_output), 3, 0, 1, 3) + # ok + self._ok_btn = pyqt_widgets.QPushButton('OK') + self._ok_btn.clicked.connect(self._ok) + layout.addWidget(self._ok_btn, 4, 1) + self._check_ok() + + options.setLayout(layout) + return options + + def _init_filepicker(self, widget, labelText, filepickerFn): layout = pyqt_widgets.QHBoxLayout() - label = pyqt_widgets.QLabel(labelText, self._widget) + # label + label = pyqt_widgets.QLabel(labelText, widget) layout.addWidget(label) - self._edits[labelText] = pyqt_widgets.QLineEdit(self._widget) + # line edit + self._edits[labelText] = pyqt_widgets.QLineEdit(widget) layout.addWidget(self._edits[labelText]) + # filepicker btn button_logo = pyqt_gui.QIcon(os.path.dirname(__file__) + '/folder.png') - button = pyqt_widgets.QPushButton(button_logo, '', self._widget) + button = pyqt_widgets.QPushButton(button_logo, '', widget) button.clicked.connect(filepickerFn) layout.addWidget(button) + return layout - def _init_combobox(self, label, setFn, options): + def _init_combobox(self, widget, label, setFn, options): layout = pyqt_widgets.QHBoxLayout() - label = pyqt_widgets.QLabel(label, self._widget) + # label + label = pyqt_widgets.QLabel(label, widget) layout.addWidget(label) - combo = pyqt_widgets.QComboBox(self._widget) + # combobox + combo = pyqt_widgets.QComboBox(widget) combo.activated[str].connect(setFn) for opt in options: combo.addItem(opt) - layout.addWidget(label) layout.addWidget(combo) + layout.setStretch(0, 2) return layout def _filepicker_tracklist(self, signal): - file = pyqt_widgets.QFileDialog.getOpenFileName(self._widget, + file = pyqt_widgets.QFileDialog.getOpenFileName(self._options, 'Select a tracklist', os.path.expanduser("~"), "Plain-Text file (*.txt)") if len(file) > 0: self.args.tracklist = file[0] - self._edits[self._tracklistKey].setText(self.args.tracklist) - if len(self._edits[self._outputKey].text()) == 0: + self._edits[self._tracklistLabel].setText(self.args.tracklist) + if len(self._edits[self._outputLabel].text()) == 0: self.args.output = os.path.splitext(self.args.tracklist)[0] - self._edits[self._outputKey].setText(self.args.output) - self._check_exit() + self._edits[self._outputLabel].setText(self.args.output) + self._check_ok() def _filepicker_output(self, signal): - file = pyqt_widgets.QFileDialog.getExistingDirectory(self._widget, + file = pyqt_widgets.QFileDialog.getExistingDirectory(self._options, 'Select directory', os.path.expanduser('~')) if len(file) > 0: self.args.output = file - self._edits[self._outputKey].setText(file) - self._check_exit() + self._edits[self._outputLabel].setText(file) + self._check_ok() def _set_format(self, format): self.args.format = format @@ -98,12 +131,21 @@ class Args: def _keep_toggle(self): self.args.keep = not self.args.keep - def _check_exit(self): + def _check_ok(self): if self.args.tracklist != None and os.path.exists(self.args.tracklist) and len(self.args.output) > 0: - self._ok.setEnabled(True) + self._ok_btn.setEnabled(True) else: - self._ok.setEnabled(False) + self._ok_btn.setEnabled(False) + + def _ok(self): + del(self._options) + self._logs.show() + threading.Thread(target=self.fnSya, args=[self.args]).start() + + def log(self, msg): + cursor = self._logs.textCursor() + cursor.movePosition(pyqt_gui.QTextCursor.End) + cursor.insertText(msg) + self._logs.setTextCursor(cursor) + self._logs.ensureCursorVisible() - def _exit(self): - self.args.gui = False - self._app.quit() diff --git a/sya.py b/sya.py @@ -9,6 +9,8 @@ import sys import threading # sya import gui +# pip +import PyQt5.QtWidgets as pyqt_widgets Timestamp = re.compile('[\[,\(]?(:?\d{1,2}){3}[\],\)]?') @@ -154,11 +156,8 @@ def sya(args): if __name__ == '__main__': args = parse_args() if args.gui: - argsGui = gui.Args(args) - args = argsGui.args - del(argsGui) - if args.gui == True: # cancel exit - sys.exit() - logsGui = gui.Log(sya, [args]) + app = pyqt_widgets.QApplication(sys.argv) + options = gui.SyaGui(sya, args) + sys.exit(app.exec()) else: sya(args)