Merge branch 'develop'

This commit is contained in:
Jarosław Wieczorek 2021-01-19 00:05:25 +01:00
commit e67c7e29c7
8 changed files with 180 additions and 32 deletions

View File

@ -614,6 +614,13 @@
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="progress_bar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
</layout>
<zorder>h_line</zorder>
<zorder>h_line_2</zorder>
@ -621,6 +628,7 @@
<zorder>h_line_3</zorder>
<zorder>v_spacer_1</zorder>
<zorder>check_box_connected_channels</zorder>
<zorder>progress_bar</zorder>
</widget>
<widget class="QMenuBar" name="menu_bar">
<property name="geometry">

View File

@ -9,12 +9,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>782</width>
<width>779</width>
<height>356</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>MagicPodcast - preview podcast</string>
</property>
<property name="windowIcon">
<iconset resource="../../../resources.qrc">
<normaloff>:/icons/src/gui/images/icons/preview.png</normaloff>:/icons/src/gui/images/icons/preview.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@ -37,7 +41,11 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="left_range"/>
<widget class="QLineEdit" name="left_range">
<property name="inputMethodHints">
<set>Qt::ImhPreferNumbers|Qt::ImhTime</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="right_label">
@ -47,12 +55,16 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="right_range"/>
<widget class="QLineEdit" name="right_range">
<property name="inputMethodHints">
<set>Qt::ImhPreferNumbers|Qt::ImhTime</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="create_preview_button">
<property name="text">
<string>utwórz podgląd</string>
<string>Utwórz podgląd</string>
</property>
</widget>
</item>
@ -70,14 +82,14 @@
<item>
<widget class="QPushButton" name="play_button">
<property name="text">
<string>start</string>
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stop_button">
<property name="text">
<string>stop</string>
<string>Stop</string>
</property>
</widget>
</item>
@ -85,6 +97,8 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../../resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -2,6 +2,7 @@ import os
import shutil
import subprocess
import tempfile
from pathlib import Path
from pydub.utils import mediainfo
@ -26,6 +27,7 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=parent)
self.connected_channels_status = False
self.translator = Translator()
self.installTranslator(self.translator)
self.lang = 'pl'
@ -35,11 +37,18 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
self.setup_detail()
self.retranslateUi(self.window())
self.aresample = "8000"
self.test_data()
self.image_extensions = ['.jpg', '.png']
self.audio_extensions = ['.mp3', '.wav']
self.progress_bar.setValue(0)
self.dialog = self.create_custom_dialog(
title='Process generowania podcastu',
msg='Sprawdzanie poprawności danych'
)
self.test_data()
def setup_logic(self):
"""Connect ui elements with methods."""
self.action_settings.triggered.connect(self.open_setting_dialog)
@ -52,7 +61,13 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
self.button_select_avatar_3.clicked.connect(lambda: self.open_image_import(image_number=3))
self.button_select_avatar_4.clicked.connect(lambda: self.open_image_import(image_number=4))
self.check_box_connected_channels.setChecked(True)
self.connected_channels_status = self.check_box_connected_channels.checkState()
self.check_box_connected_channels.stateChanged.connect(self.channels_connected)
self.threshold_slider.valueChanged.connect(self.update_lcd_threshold)
def on_progress_change(self, value):
"""Update progress bar value"""
self.progress_bar.setValue(value)
def change_language(self):
"""Retranslate user interface."""
@ -90,8 +105,6 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
self.preview_label_avatar_4.setPixmap(scaled_pixmap4)
self.preview_label_avatar_4.setProperty('path', './src/gui/images/right.png')
self.threshold_slider.valueChanged.connect(self.update_lcd_threshold)
def update_lcd_threshold(self, event):
"""Set threshold value from slider to lcd."""
self.threshold_lcd.display(event)
@ -191,7 +204,8 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
if audio_number == 1:
self.line_edit_audio_1.setText(file)
self.line_edit_audio_1.setProperty('duration', mediainfo(file)['duration'])
print(f"[*] Audio 1: {file} duration: {mediainfo(file)['duration']}")
print(f"[*] Audio 1: {file} duration: {self.line_edit_audio_1.property('duration')}")
elif audio_number == 2:
self.line_edit_audio_2.setText(file)
self.line_edit_audio_2.setProperty('duration', mediainfo(file)['duration'])
@ -213,7 +227,9 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
def channels_connected(self, checked):
"""Change information id channels connected."""
print(checked)
self.connected_channels_status = checked
if checked:
self.button_audio_2.setDisabled(True)
self.line_edit_audio_2.setDisabled(True)
self.line_edit_audio_1.setPlaceholderText("Plik audio rozmówców")
@ -225,11 +241,45 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
def preview_video_podcast(self):
"""Preview Video Podcast"""
preview_dialog = PreviewDialog(parent=self)
if not self.check_box_connected_channels.isChecked():
audio_files = [self.line_edit_audio_1.text(), self.line_edit_audio_2.text()]
if not all(self.check_file(x, self.audio_extensions) for x in audio_files):
return -1
self.line_edit_audio_1.setProperty(
'duration', mediainfo(self.line_edit_audio_1.text())['duration'])
self.line_edit_audio_2.setProperty(
'duration', mediainfo(self.line_edit_audio_2.text())['duration'])
audio_1 = float(self.line_edit_audio_1.property('duration'))
print(audio_1)
audio_2 = float(self.line_edit_audio_2.property('duration'))
print(f"[*] File duration audio_1: {audio_1}")
print(f"[*] File duration audio_2: {audio_2}")
end_time = audio_1 if audio_1 >= audio_2 else audio_2
preview_dialog = PreviewDialog(parent=self, start_time=0, end_time=end_time)
else:
audio_files = [self.line_edit_audio_1.text()]
if not all(self.check_file(x, self.audio_extensions) for x in audio_files):
return -1
self.line_edit_audio_1.setProperty(
'duration', mediainfo(self.line_edit_audio_1.text())['duration'])
end_time = float(self.line_edit_audio_1.property('duration'))
print(f"[*] File duration audio_2: {end_time}")
preview_dialog = PreviewDialog(parent=self, start_time=0, end_time=end_time)
preview_dialog.exec_()
def generate_video_podcast(self, start=None, end=None):
"""Generate podcast based on values from UI."""
self.progress_bar.setValue(0)
threshold_value = int(self.threshold_lcd.value())
generate_demuxer.set_up_threshold(threshold_value)
connected_channels = self.check_box_connected_channels.isChecked()
@ -242,12 +292,12 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
'right': self.preview_label_avatar_4.property('path')
}
audio_files = []
for image_path in image_files.values():
if not self.check_file(image_path, self.image_extensions):
self.create_custom_dialog(title='Błąd!', msg=f"Tworzenie podcastu zostało przerwane.")
return -1
self.create_custom_dialog(title='Błąd!', msg="Tworzenie podcastu zostało przerwane.")
return -1
audio_files = []
if not connected_channels:
audio_files.append({'file': self.line_edit_audio_1.text()})
audio_files.append({'file': self.line_edit_audio_2.text()})
@ -258,14 +308,16 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
for audio_path in audio_files:
if not Path(audio_path['file']).is_file():
if not self.check_file(audio_path['file'], self.audio_extensions):
self.create_custom_dialog(title='Błąd!', msg=f"Tworzenie podcastu zostało przerwane.")
self.create_custom_dialog(title='Błąd!', msg="Tworzenie podcastu zostało przerwane.")
return -1
# Split name and extension of the file
for dictionary in audio_files:
dictionary['ext'] = dictionary['file'].rsplit('.')[-1]
self.progress_bar.setValue(10)
with tempfile.TemporaryDirectory() as tmp_dir_name:
print(tmp_dir_name)
print(f'[*] Create temporary directory: {tmp_dir_name}')
tmp_out_dir = tmp_dir_name + "/out"
@ -273,6 +325,7 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
audio_dir = tmp_dir_name + "/audio"
video_dir = tmp_dir_name + "/video"
self.progress_bar.setValue(15)
print(F"[!] Create tmp out dir: {tmp_out_dir}")
os.mkdir(tmp_out_dir)
@ -291,6 +344,7 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
shutil.copy(image_files['left'], pics_dir + "/left.png")
shutil.copy(image_files['right'], pics_dir + "/right.png")
self.progress_bar.setValue(20)
print(f'[*] Copy audio to {audio_dir}\n')
if not self.check_box_connected_channels.isChecked():
audio_files[0]['tmp'] = audio_dir + "/left_channel" + "." + audio_files[0]['ext']
@ -306,6 +360,7 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
print(f'[*] Images in {pics_dir}: {os.listdir(pics_dir)}')
print(f'[*] Audo files in {audio_dir}: {os.listdir(audio_dir)}')
self.progress_bar.setValue(25)
subprocess.check_output(["echo", tmp_dir_name]).decode('utf-8')
if connected_channels:
@ -317,12 +372,14 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
audio_files[0]['tmp']])
print("[+] Split channels - done")
self.progress_bar.setValue(30)
print("[-] Create raw files - start:")
subprocess.check_output(['bash',
'bash_commands/create_raw_files.sh',
audio_dir, self.aresample])
print("[+] Create raw files - done")
self.progress_bar.setValue(60)
print("[-] Create demuxer - start:")
generate_demuxer.run(tmp_dir=tmp_dir_name)
print("[+] Create demuxer - done")
@ -332,8 +389,14 @@ class MainWindow(QMainWindow, QApplication, Ui_MainWindow):
['bash', 'bash_commands/generate_video_by_demuxer.sh', tmp_dir_name, video_dir])
print('[+] Create video - done')
self.progress_bar.setValue(75)
# while True: pass
print('[-] Create final podcast - start:')
subprocess.check_output(
['bash', 'bash_commands/connect_sound.sh', tmp_dir_name, audio_files[0]['file']])
print('[+] Create final podcast - done')
self.progress_bar.setValue(100)
dialog_done = self.create_custom_dialog(title="Informacja", msg="Zakończono generowanie podcastu.")
dialog_done.exec_()
self.progress_bar.setValue(0)

View File

@ -1,18 +1,22 @@
from pathlib import Path
from PyQt5.QtMultimedia import QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
from src.python.classes.range_slider import QRangeSlider
from src.python.ui.preview_dialog_ui import Ui_PreviewDialog
from PyQt5.QtWidgets import QDialog, QLabel, QStyle
from PyQt5.QtWidgets import QDialog, QStyle
class PreviewDialog(QDialog, Ui_PreviewDialog):
"""
Dialog to show preview of podcast.
"""
def __init__(self, parent=None, start_time=0, end_time=15):
super(PreviewDialog, self).__init__(parent=parent)
self.setupUi(self)
self.mediaPlayer = QMediaPlayer(parent=self, flags=QMediaPlayer.VideoSurface)
@ -21,8 +25,39 @@ class PreviewDialog(QDialog, Ui_PreviewDialog):
self.v_layout_1.addWidget(self.video_widget)
self.v_layout_1.addWidget(self.range_slider)
self.range_slider.setRangeLimit(minimum=int(start_time), maximum=int(end_time))
self.range_slider.setRange(start=int(start_time), end=int(end_time))
self.range_slider.c.range_changed.connect(self.update_line_edit_values)
self.left_range.setText(str(self.range_slider.first_position))
self.right_range.setText(str(self.range_slider.second_position))
def update_line_edit_values(self, x, y):
"""Update values."""
if x == 1:
self.left_range.setText(str(y))
elif x == 2:
self.right_range.setText(str(y))
def get_audio_files(self):
"""Load time of audio files"""
audio_files = []
if not self.connected_channels_status:
audio_files.append({'file': self.line_edit_audio_1.text()})
audio_files.append({'file': self.line_edit_audio_2.text()})
else:
audio_files.append({'file': self.line_edit_audio_1.text()})
for audio_path in audio_files:
if not Path(audio_path['file']).is_file():
if not self.check_file(audio_path['file'], self.audio_extensions):
self.create_custom_dialog(title='Błąd!', msg="Tworzenie podcastu zostało przerwane.")
return -1
return audio_files
def setup_video_logic(self):
"""
Setup connections to events
@ -35,7 +70,6 @@ class PreviewDialog(QDialog, Ui_PreviewDialog):
def media_state_changed(self, state):
"""
:param state:
"""
if self.mediaPlayer.state() == QMediaPlayer.PlayingState:

View File

@ -1,15 +1,21 @@
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt, QRect, QSize, pyqtSignal, QObject
from PyQt5.QtGui import QPaintEvent, QPainter, QPalette, QBrush, QMouseEvent
from PyQt5.QtWidgets import QApplication, QAbstractSlider, QSizePolicy, QSlider, QStyle, QStyleOptionSlider
class Communicate(QObject):
range_changed = pyqtSignal(int, int)
class QRangeSlider(QAbstractSlider):
"""
QRangeSlider
"""
def __init__(self, parent=None):
super().__init__(parent)
self.c = Communicate()
self.first_position = 1
self.second_position = 8
@ -23,26 +29,35 @@ class QRangeSlider(QAbstractSlider):
self.setSizePolicy(
QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed, QSizePolicy.Slider)
)
self.c.range_changed.connect(self.handle_emit)
def handle_emit(self, x, y):
print(x, y)
def setRangeLimit(self, minimum: int, maximum: int):
"""Set new range limit."""
self.opt.minimum = minimum
self.opt.maximum = maximum
def setRange(self, start: int, end: int):
"""Set new range."""
self.first_position = start
self.second_position = end
def getRange(self):
"""Get selected current range."""
return self.first_position, self.second_position
def setTickPosition(self, position: QSlider.TickPosition):
"""Set tick position."""
self.opt.tickPosition = position
def setTickInterval(self, ti: int):
"""Set tick interval."""
self.opt.tickInterval = ti
def paintEvent(self, event: QPaintEvent):
"""Handle paint event."""
painter = QPainter(self)
# Draw rule
@ -99,7 +114,7 @@ class QRangeSlider(QAbstractSlider):
self.style().drawComplexControl(QStyle.CC_Slider, self.opt, painter)
def mousePressEvent(self, event: QMouseEvent):
"""Handle mouse press event."""
self.opt.sliderPosition = self.first_position
self._first_sc = self.style().hitTestComplexControl(
QStyle.CC_Slider, self.opt, event.pos(), self
@ -111,7 +126,7 @@ class QRangeSlider(QAbstractSlider):
)
def mouseMoveEvent(self, event: QMouseEvent):
"""Handle mouse move event."""
distance = self.opt.maximum - self.opt.minimum
pos = self.style().sliderValueFromPosition(
@ -121,16 +136,19 @@ class QRangeSlider(QAbstractSlider):
if self._first_sc == QStyle.SC_SliderHandle:
if pos <= self.second_position:
self.first_position = pos
self.c.range_changed.emit(1, pos)
self.update()
return
if self._second_sc == QStyle.SC_SliderHandle:
if pos >= self.first_position:
self.second_position = pos
self.c.range_changed.emit(2, pos)
self.update()
return
def sizeHint(self):
""" override """
""" Override sizeHint """
SliderLength = 84
TickSpace = 5

View File

@ -5,7 +5,7 @@ from PyQt5.QtCore import QTranslator
class Translator(QTranslator):
"""Translator to change language for user interface."""
def __init__(self):
QTranslator.__init__(self)

View File

@ -261,11 +261,16 @@ class Ui_MainWindow(object):
self.button_generate.setObjectName("button_generate")
self.h_layout_preview_or_generate.addWidget(self.button_generate)
self.verticalLayout.addLayout(self.h_layout_preview_or_generate)
self.progress_bar = QtWidgets.QProgressBar(self.central_widget)
self.progress_bar.setProperty("value", 24)
self.progress_bar.setObjectName("progress_bar")
self.verticalLayout.addWidget(self.progress_bar)
self.h_line.raise_()
self.h_line_2.raise_()
self.threshold_slider.raise_()
self.h_line_3.raise_()
self.check_box_connected_channels.raise_()
self.progress_bar.raise_()
MainWindow.setCentralWidget(self.central_widget)
self.menu_bar = QtWidgets.QMenuBar(MainWindow)
self.menu_bar.setGeometry(QtCore.QRect(0, 0, 554, 32))

View File

@ -15,7 +15,10 @@ class Ui_PreviewDialog(object):
def setupUi(self, PreviewDialog):
PreviewDialog.setObjectName("PreviewDialog")
PreviewDialog.setWindowModality(QtCore.Qt.NonModal)
PreviewDialog.resize(782, 356)
PreviewDialog.resize(779, 356)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icons/src/gui/images/icons/preview.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
PreviewDialog.setWindowIcon(icon)
self.verticalLayout = QtWidgets.QVBoxLayout(PreviewDialog)
self.verticalLayout.setObjectName("verticalLayout")
self.v_layout_1 = QtWidgets.QVBoxLayout()
@ -32,12 +35,14 @@ class Ui_PreviewDialog(object):
self.left_label.setObjectName("left_label")
self.h_layout_range_values.addWidget(self.left_label)
self.left_range = QtWidgets.QLineEdit(PreviewDialog)
self.left_range.setInputMethodHints(QtCore.Qt.ImhPreferNumbers|QtCore.Qt.ImhTime)
self.left_range.setObjectName("left_range")
self.h_layout_range_values.addWidget(self.left_range)
self.right_label = QtWidgets.QLabel(PreviewDialog)
self.right_label.setObjectName("right_label")
self.h_layout_range_values.addWidget(self.right_label)
self.right_range = QtWidgets.QLineEdit(PreviewDialog)
self.right_range.setInputMethodHints(QtCore.Qt.ImhPreferNumbers|QtCore.Qt.ImhTime)
self.right_range.setObjectName("right_range")
self.h_layout_range_values.addWidget(self.right_range)
self.create_preview_button = QtWidgets.QPushButton(PreviewDialog)
@ -64,12 +69,13 @@ class Ui_PreviewDialog(object):
def retranslateUi(self, PreviewDialog):
_translate = QtCore.QCoreApplication.translate
PreviewDialog.setWindowTitle(_translate("PreviewDialog", "Dialog"))
PreviewDialog.setWindowTitle(_translate("PreviewDialog", "MagicPodcast - preview podcast"))
self.left_label.setText(_translate("PreviewDialog", "Czas rozpoczęcia:"))
self.right_label.setText(_translate("PreviewDialog", "Czas zakończenia:"))
self.create_preview_button.setText(_translate("PreviewDialog", "utwórz podgląd"))
self.play_button.setText(_translate("PreviewDialog", "start"))
self.stop_button.setText(_translate("PreviewDialog", "stop"))
self.create_preview_button.setText(_translate("PreviewDialog", "Utwórz podgląd"))
self.play_button.setText(_translate("PreviewDialog", "Start"))
self.stop_button.setText(_translate("PreviewDialog", "Stop"))
import resources_rc
if __name__ == "__main__":