From 7cc07c2657f907cc26672ff7e5c1437f04023953 Mon Sep 17 00:00:00 2001 From: cuissedemouche Date: Tue, 13 Dec 2022 14:51:50 +0000 Subject: [PATCH] Basic and advanced tab First commit of the app Basic and advanced tab can be generated via code to the QPlainTextEdit --- QT/main_window.ui | 56 ++++++++++++++++++ QT/ui_main_window.py | 68 ++++++++++++++++++++++ file_cmds.py | 134 +++++++++++++++++++++++++++++++++++++++++++ main.py | 11 ++++ main_window.py | 53 +++++++++++++++++ ui_main_window.py | 68 ++++++++++++++++++++++ 6 files changed, 390 insertions(+) create mode 100644 QT/main_window.ui create mode 100644 QT/ui_main_window.py create mode 100644 file_cmds.py create mode 100644 main.py create mode 100644 main_window.py create mode 100644 ui_main_window.py diff --git a/QT/main_window.ui b/QT/main_window.ui new file mode 100644 index 0000000..884f2cf --- /dev/null +++ b/QT/main_window.ui @@ -0,0 +1,56 @@ + + + MainWindow + + + + 0 + 0 + 1214 + 896 + + + + Form + + + + + + Qt::Horizontal + + + + + + + Search + + + + + + + + + + + false + + + QPlainTextEdit::NoWrap + + + true + + + + + + + + + + + + diff --git a/QT/ui_main_window.py b/QT/ui_main_window.py new file mode 100644 index 0000000..ac400f7 --- /dev/null +++ b/QT/ui_main_window.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file 'main_window.ui' +## +## Created by: Qt User Interface Compiler version 6.4.1 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QLineEdit, QListWidget, QListWidgetItem, + QPlainTextEdit, QSizePolicy, QSplitter, QVBoxLayout, + QWidget) + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + if not MainWindow.objectName(): + MainWindow.setObjectName(u"MainWindow") + MainWindow.resize(1214, 896) + self.verticalLayout_2 = QVBoxLayout(MainWindow) + self.verticalLayout_2.setObjectName(u"verticalLayout_2") + self.splitter = QSplitter(MainWindow) + self.splitter.setObjectName(u"splitter") + self.splitter.setOrientation(Qt.Horizontal) + self.layoutWidget = QWidget(self.splitter) + self.layoutWidget.setObjectName(u"layoutWidget") + self.verticalLayout = QVBoxLayout(self.layoutWidget) + self.verticalLayout.setObjectName(u"verticalLayout") + self.verticalLayout.setContentsMargins(0, 0, 0, 0) + self.lineEdit = QLineEdit(self.layoutWidget) + self.lineEdit.setObjectName(u"lineEdit") + + self.verticalLayout.addWidget(self.lineEdit) + + self.media_tracks_list_widget = QListWidget(self.layoutWidget) + self.media_tracks_list_widget.setObjectName(u"media_tracks_list_widget") + + self.verticalLayout.addWidget(self.media_tracks_list_widget) + + self.splitter.addWidget(self.layoutWidget) + self.media_detail_plain_text_edit = QPlainTextEdit(self.splitter) + self.media_detail_plain_text_edit.setObjectName(u"media_detail_plain_text_edit") + self.media_detail_plain_text_edit.setUndoRedoEnabled(False) + self.media_detail_plain_text_edit.setLineWrapMode(QPlainTextEdit.NoWrap) + self.media_detail_plain_text_edit.setReadOnly(True) + self.splitter.addWidget(self.media_detail_plain_text_edit) + + self.verticalLayout_2.addWidget(self.splitter) + + + self.retranslateUi(MainWindow) + + QMetaObject.connectSlotsByName(MainWindow) + # setupUi + + def retranslateUi(self, MainWindow): + MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"Form", None)) + self.lineEdit.setText(QCoreApplication.translate("MainWindow", u"Search", None)) + self.media_detail_plain_text_edit.setPlainText("") + # retranslateUi + diff --git a/file_cmds.py b/file_cmds.py new file mode 100644 index 0000000..7e516d9 --- /dev/null +++ b/file_cmds.py @@ -0,0 +1,134 @@ +import os, subprocess, json +from shlex import quote + +class FileCmds: + def __init__(self, filePath): + super().__init__() + self.filePath = filePath + + + def execute_bash(self, cmd): + ''' + Execute a bash command + + :type cmd: str + :return: output + ''' + process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + output, error = process.communicate() + return output + + + def file_exist(self): + if os.path.exists(self.filePath): + return True + else: + print("The file doesn't exist") + return False + + def get_mkv_infos(self): + ''' + Process MKV infos into a dictionary + + :rtype: list or None + ''' + + process = self.execute_bash(f"mediainfo --Output=JSON {quote(self.filePath)}") + mkvInfo = json.loads(process)["media"]["track"] + return mkvInfo + + # def get_video_track(self): + # ''' + # Get the video track infos + + # :rtype: dict or None + # ''' + # for track in self.mkvInfo: + # if track["@type"] == "Video": + # return track + # print("The file does not contain a video track") + # return(None) + + def media_inform(self, inform): + ''' + Execute mediainfo --Inform + + :type inform: rstr + :rtype: str + ''' + bashCommand = f"mediainfo --Inform={quote(inform)} {quote(self.filePath)}" + output = self.execute_bash(bashCommand).decode('utf-8') + return output + + + def tracksCount(self): + ''' + Return the number of track of each type + + :rtype: dict + ''' + trackTypes = [ + "Video", + "Audio", + "Text", + "Image", + "Menu", + ] + + output = {} + + for trackType in trackTypes: + count = self.media_inform(f"General;%{trackType}Count%").replace('\n', '') + if not count: + count = 0 + output[trackType] = count + + return output + + def generate_basic(self): + ''' + Return the basic tab + + :rtype: string + ''' + informGeneral = r"General;G: %Format%, %FileSize_String%, %Duration_String%, %BitRate_String%\n" + informVideo = r"Video;V: %Format%, %Format_Profile%, %StreamSize_String%, %Width%x%Height%, %FrameRate% FPS, %BitRate_String%\n" + informAudio = r"Audio;A: %Language_String%, %Format%, %StreamSize_String%, %BitRate_String%, %Channel(s)_String%, %SamplingRate_String%\n" + informText = r"Text;T: %Language_String%, %Format%\n" + + informs = [informGeneral] + + count = self.tracksCount() + + if not count["Video"] == 0: + informs.append(informVideo) + count = self.tracksCount() + + if not count["Audio"] == 0: + informs.append(informAudio) + count = self.tracksCount() + + if not count["Text"] == 0: + informs.append(informText) + + output = "" + + for inform in informs: + output += self.media_inform(inform) + + if not count["Menu"] == 0: + output += "M: Menu\n\n" + + output += "\n" + output += self.execute_bash(f"mediainfo {quote(self.filePath)}").decode('utf-8') + return(output) + + + def generate_advanced(self): + ''' + Return the advanced tab + + :rtype: string + ''' + output = self.execute_bash(f"mediainfo --Full {quote(self.filePath)}").decode('utf-8') + return output \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..15eabfe --- /dev/null +++ b/main.py @@ -0,0 +1,11 @@ +import sys + +from PySide6 import QtWidgets +from main_window import MainWindow + +app = QtWidgets.QApplication(sys.argv) + +window = MainWindow() +window.show() + +app.exec() \ No newline at end of file diff --git a/main_window.py b/main_window.py new file mode 100644 index 0000000..7570ff7 --- /dev/null +++ b/main_window.py @@ -0,0 +1,53 @@ +from PySide6.QtWidgets import QWidget +from ui_main_window import Ui_MainWindow +from file_cmds import FileCmds + + +class MainWindow(QWidget, Ui_MainWindow): + def __init__(self): + super().__init__() + self.setupUi(self) + self.setWindowTitle("mediainfoSama") + self.setAcceptDrops(True) + self.setupConnections() + + def setupConnections(self): + pass + + def dragEnterEvent(self, event): + event.accept() + + + def dragMoveEvent(self, event): + event.accept() + + + def dropEvent(self, event): + self.filePath = event.mimeData().urls()[0].toLocalFile() + self.fileCmds = FileCmds(self.filePath) + self.fileCmds.file_exist() + + if self.fileCmds.file_exist() == False: + return + + self.populate() + + + print("YEAH") + # videoTrack = self.mkv_infos.get_video_track() + # if videoTrack == None: + # return + + + + def populate(self, path = ''): + self.media_tracks_list_widget.clear() + informGeneral = r"General;G: %Format%, %FileSize_String%, %Duration_String%, %BitRate_String%\n" + informVideo = r"Video;V: %Format%, %Format_Profile%, %StreamSize_String%, %Width%x%Height%, %FrameRate% FPS, %BitRate_String%\n" + informAudio = r"Audio;A: %Language_String%, %Format%, %StreamSize_String%, %BitRate_String%, %Channel(s)_String%, %SamplingRate_String%\n" + informText = r"Text;T: %Language_String%, %Format%\n" + + text = self.fileCmds.generate_basic() + self.media_detail_plain_text_edit.setPlainText(text) + + print(self.fileCmds.tracksCount()) \ No newline at end of file diff --git a/ui_main_window.py b/ui_main_window.py new file mode 100644 index 0000000..ac400f7 --- /dev/null +++ b/ui_main_window.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file 'main_window.ui' +## +## Created by: Qt User Interface Compiler version 6.4.1 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QLineEdit, QListWidget, QListWidgetItem, + QPlainTextEdit, QSizePolicy, QSplitter, QVBoxLayout, + QWidget) + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + if not MainWindow.objectName(): + MainWindow.setObjectName(u"MainWindow") + MainWindow.resize(1214, 896) + self.verticalLayout_2 = QVBoxLayout(MainWindow) + self.verticalLayout_2.setObjectName(u"verticalLayout_2") + self.splitter = QSplitter(MainWindow) + self.splitter.setObjectName(u"splitter") + self.splitter.setOrientation(Qt.Horizontal) + self.layoutWidget = QWidget(self.splitter) + self.layoutWidget.setObjectName(u"layoutWidget") + self.verticalLayout = QVBoxLayout(self.layoutWidget) + self.verticalLayout.setObjectName(u"verticalLayout") + self.verticalLayout.setContentsMargins(0, 0, 0, 0) + self.lineEdit = QLineEdit(self.layoutWidget) + self.lineEdit.setObjectName(u"lineEdit") + + self.verticalLayout.addWidget(self.lineEdit) + + self.media_tracks_list_widget = QListWidget(self.layoutWidget) + self.media_tracks_list_widget.setObjectName(u"media_tracks_list_widget") + + self.verticalLayout.addWidget(self.media_tracks_list_widget) + + self.splitter.addWidget(self.layoutWidget) + self.media_detail_plain_text_edit = QPlainTextEdit(self.splitter) + self.media_detail_plain_text_edit.setObjectName(u"media_detail_plain_text_edit") + self.media_detail_plain_text_edit.setUndoRedoEnabled(False) + self.media_detail_plain_text_edit.setLineWrapMode(QPlainTextEdit.NoWrap) + self.media_detail_plain_text_edit.setReadOnly(True) + self.splitter.addWidget(self.media_detail_plain_text_edit) + + self.verticalLayout_2.addWidget(self.splitter) + + + self.retranslateUi(MainWindow) + + QMetaObject.connectSlotsByName(MainWindow) + # setupUi + + def retranslateUi(self, MainWindow): + MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"Form", None)) + self.lineEdit.setText(QCoreApplication.translate("MainWindow", u"Search", None)) + self.media_detail_plain_text_edit.setPlainText("") + # retranslateUi +