Basic and advanced tab
First commit of the app Basic and advanced tab can be generated via code to the QPlainTextEdit
This commit is contained in:
parent
69255f64f2
commit
7cc07c2657
56
QT/main_window.ui
Normal file
56
QT/main_window.ui
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QWidget" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1214</width>
|
||||
<height>896</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="text">
|
||||
<string>Search</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="media_tracks_list_widget"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QPlainTextEdit" name="media_detail_plain_text_edit">
|
||||
<property name="undoRedoEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
68
QT/ui_main_window.py
Normal file
68
QT/ui_main_window.py
Normal file
@ -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
|
||||
|
134
file_cmds.py
Normal file
134
file_cmds.py
Normal file
@ -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
|
11
main.py
Normal file
11
main.py
Normal file
@ -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()
|
53
main_window.py
Normal file
53
main_window.py
Normal file
@ -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())
|
68
ui_main_window.py
Normal file
68
ui_main_window.py
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user