-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPackageInterface.py
262 lines (225 loc) · 9.12 KB
/
PackageInterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QPixmap, QPainter, QColor
from PyQt5.QtWidgets import QWidget,QFileDialog,QApplication
from qfluentwidgets import InfoBarIcon, InfoBar, PushButton, setTheme, Theme, FluentIcon, InfoBarPosition, InfoBarManager
from functools import partial
import os
from threading import Thread
# 读取配置文件
import configparser
conf = configparser.ConfigParser()
conf.read('config.ini')
Scroll = conf.get('DEFAULT', 'ScrollUI')
if(Scroll == "0"):
from UI.Ui_package import Ui_Package
elif(Scroll == "1"):
from UI_test.Ui_package import Ui_Package
class PackageInterface(QWidget, Ui_Package):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
# 隐藏ProgressBar
self.ProgressBar1.setVisible(0)
self.ProgressBar2.setVisible(0)
self.ProgressBar3.setVisible(0)
# 文件选择
self.InputButton.clicked.connect(partial(self.FileSelect, self.InputLine))
self.OutputButton.clicked.connect(partial(self.FileSelect, self.OutputLine))
self.AudioButton.clicked.connect(partial(self.FileSelect, self.AudioLine))
self.InputButton_2.clicked.connect(partial(self.FileSelect, self.InputLine_2))
self.AudioButton_2.clicked.connect(partial(self.FileSelect, self.AudioLine_2))
self.OutputButton_2.clicked.connect(partial(self.FileSelect, self.OutputLine_2))
self.TextButton.clicked.connect(partial(self.FileSelect, self.TextLine))
self.OutputButton_3.clicked.connect(partial(self.FileSelect, self.OutputLine_3))
# 文件自动填充
self.InputLine.textChanged.connect(partial(self.AutoFill, self.InputLine, self.OutputLine, 1))
self.InputLine_2.textChanged.connect(partial(self.AutoFill, self.InputLine_2, self.OutputLine_2, 2))
# 粘贴地址
self.PasteButton.clicked.connect(partial(self.Paste, self.AddressLine))
# 操作开始按钮
self.MP4Start.clicked.connect(self.MP4Func)
self.MP4Start.setWindowIconText("")
self.MP4Start.windowIconTextChanged.connect(
self.MP4Complte)
self.MkvStart.clicked.connect(self.MkvFunc)
self.MkvStart.setWindowIconText("")
self.MkvStart.windowIconTextChanged.connect(
self.MkvComplte)
self.DownloadButton.clicked.connect(self.DownloadFunc)
self.DownloadButton.setWindowIconText("")
self.DownloadButton.windowIconTextChanged.connect(
self.DownloadComplte)
# 文件选择函数
'''
输入: 选择文件的目标LineEdit
输出: 无输出
'''
def FileSelect(self, TargetLine):
dir = QFileDialog()
dir.setDirectory(os.getcwd())
if dir.exec_(): # 判断是否选择了文件
FilePath = dir.selectedFiles()
TargetLine.setText(FilePath[0])
# 自动填充函数
'''
输入: 选择文件的源LineEdit, 自动同步的目标LineEdit, 自动填充后缀名类型 1是mp4 2是mkv
输出: 无输出
描述: 选择文件函数, 与界面上的浏览按钮绑定, 用于把资源管理器读取的地址传回输入框
'''
def AutoFill(self, SourceLine, TargetLine, Type):
FilePath = SourceLine.text()
if FilePath == "":
return
FileExt = os.path.splitext(FilePath)[1]
FilePath = os.path.splitext(FilePath)[0]
if(Type == 1):
NewFilePath = FilePath + '_output.mp4'
elif(Type == 2):
NewFilePath = FilePath + '_output.mkv'
TargetLine.setText(NewFilePath)
# 粘贴函数
'''
输入: 黏贴的目标地址
输出: 无输出
描述: 根据输入框内容自动填充输出框
'''
def Paste(self, TargetLine):
TargetLine.setText(QApplication.clipboard().text())
# MP4封装函数
def MP4Func(self):
# 地址缺失
if(self.InputLine.text() == '' or self.OutputLine.text() == ''):
InfoBar.error(
title='未定义地址',
content="请确认你是否已经设定了正确的输入输出地址",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
return
ProcseeCmd = "tools\\ffmpeg -hide_banner -i \"" + self.InputLine.text() + "\" "
# 封装音频
if(self.AudioLine.text() != ''):
ProcseeCmd += "-i \"" + self.AudioLine.text() + "\" "
ProcseeCmd += "-c:v copy -c:a copy -strict experimental -y \"" + self.OutputLine.text() + "\""
thread_01 = Thread(target=self.MP4Thread, args=(ProcseeCmd,))
thread_01.start()
# MP4封装线程
'''
输入: 处理指令
输出: 无输出
'''
def MP4Thread(self, ProcseeCmd):
self.MP4Start.setWindowIconText(" ")
self.ProgressBar1.setVisible(1)
self.MP4Start.setEnabled(0)
os.system(ProcseeCmd)
self.MP4Start.setWindowIconText("")
self.ProgressBar1.setVisible(0)
self.MP4Start.setEnabled(1)
# MP4封装完成
def MP4Complte(self):
if(self.MP4Start.windowIconText() == ""):
InfoBar.success(
title='封装完成',
content="请确认是否封装成功",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
# MKV封装函数
def MkvFunc(self):
# 地址缺失
if(self.InputLine_2.text() == '' or self.OutputLine_2.text() == ''):
InfoBar.error(
title='未定义地址',
content="请确认你是否已经设定了正确的输入输出地址",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
return
ProcseeCmd = "tools\\ffmpeg -hide_banner -i \"" + self.InputLine_2.text() + "\" "
# 封装音频
if(self.AudioLine_2.text() != ''):
ProcseeCmd += "-i \"" + self.AudioLine_2.text() + "\" "
# 封装字幕
if(self.TextLine.text() != ''):
ProcseeCmd += "-i \"" + self.TextLine.text() + "\" "
ProcseeCmd += "-c:v copy -c:a copy -strict experimental -y \"" + self.OutputLine_2.text() + "\""
thread_02 = Thread(target=self.MkvThread, args=(ProcseeCmd,))
thread_02.start()
# MKV封装线程
'''
输入: 处理指令
输出: 无输出
'''
def MkvThread(self, ProcseeCmd):
self.MkvStart.setWindowIconText(" ")
self.ProgressBar2.setVisible(1)
self.MkvStart.setEnabled(0)
os.system(ProcseeCmd)
self.MkvStart.setWindowIconText("")
self.ProgressBar2.setVisible(0)
self.MkvStart.setEnabled(1)
# MKV封装完成
def MkvComplte(self):
if(self.MkvStart.windowIconText() == ""):
InfoBar.success(
title='封装完成',
content="请确认是否封装成功",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
# 下载函数
def DownloadFunc(self):
# 地址缺失
if(self.AddressLine.text() == '' or self.OutputLine_3.text() == ''):
InfoBar.error(
title='未定义地址',
content="请确认你是否已经设定了正确的下载或输出地址",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
return
ProcseeCmd = "tools\\ffmpeg -i \"" + self.AddressLine.text() + "\" -y \"" + self.OutputLine_3.text() + "\""
thread_03 = Thread(target=self.DownloadThread, args=(ProcseeCmd,))
thread_03.start()
# 下载线程
'''
输入: 处理指令
输出: 无输出
'''
def DownloadThread(self, ProcseeCmd):
self.DownloadButton.setWindowIconText(" ")
self.ProgressBar3.setVisible(1)
self.DownloadButton.setEnabled(0)
os.system(ProcseeCmd)
self.DownloadButton.setWindowIconText("")
self.ProgressBar3.setVisible(0)
self.DownloadButton.setEnabled(1)
# 下载完成
def DownloadComplte(self):
if(self.DownloadButton.windowIconText() == ""):
InfoBar.success(
title='下载完成',
content="请确认是否下载成功",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)