forked from Johnserf-Seed/TikTokDownload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTikTokMultiGUI.py
327 lines (306 loc) · 13.7 KB
/
TikTokMultiGUI.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Description:GUI.py
@Date :2022/08/18 14:39:03
@Author :JohnserfSeed
@version :1.0
@License :(C)Copyright 2019-2022, Liugroup-NLPR-CASIA
@Github :https://github.com/johnserf-seed
@Mail :[email protected]
-------------------------------------------------
Change Log :
2022/08/18 14:23:03 : Init
2022/08/18 14:39:03 : 添加多线程
2022/08/18 14:39:03 : 添加控制台显示
-------------------------------------------------
'''
# Form implementation generated from reading ui file 'main.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import sys
from Util.Resource import *
from TikTokTool import Util
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt, QPoint, QThread, QMutex
from PyQt5.QtCore import QObject, QEventLoop, QTimer
from PyQt5.QtGui import QMouseEvent, QTextCursor
# 多线程保持Qt运行中不产生界面卡死
class PreventFastClickThreadMutex(QThread):
qmut = QMutex() # 创建线程锁
def __init__(self):
super().__init__()
def run(self):
# 加锁
self.qmut.lock()
# 获取命令行参数
args = Util.Command().setting()
# 使用GUI的用户链接参数
args[0] = newuid
# 获取主页消息
profile = Util.Profile()
# 使用参数并下载
profile.getProfile((args))
# 解锁
self.qmut.unlock()
class Signal(QObject):
# 创建控制台内容更新信号
text_update = QtCore.pyqtSignal(str)
def write(self, text):
# 发送更新信号
self.text_update.emit(str(text))
# loop = QEventLoop()
# QTimer.singleShot(1, loop.quit)
# loop.exec_()
# QApplication.processEvents()
class Ui_Dialog(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
sys.stdout = Signal()
# QApplication.processEvents()
# 实时显示输出, 将控制台的输出重定向到界面中
sys.stdout.text_update.connect(self.updatetext)
def updatetext(self, text):
"""更新textBrowser
Args:
text : 控制台文本
"""
cursor = self.textBrowser.textCursor()
cursor.movePosition(QTextCursor.End)
# QApplication.processEvents()
self.textBrowser.append(text)
self.textBrowser.setTextCursor(cursor)
self.textBrowser.ensureCursorVisible()
def setupUi(self, Dialog):
Dialog.setObjectName("TikTokDownload")
Dialog.resize(1030, 600)
Dialog.setStyleSheet("")
self.Label_Left = QtWidgets.QLabel(Dialog)
self.Label_Left.setGeometry(QtCore.QRect(0, 0, 230, 600))
self.Label_Left.setStyleSheet("background-color: #060716;\n"
"border-bottom-left-radius: 25px;\n"
"border-top-left-radius: 25px;\n"
"font: 10pt \"微软雅黑\";\n"
"color: #FFFFFF;")
self.Label_Left.setText("")
self.Label_Left.setObjectName("Label_Left")
self.Label_Right = QtWidgets.QLabel(Dialog)
self.Label_Right.setGeometry(QtCore.QRect(230, 0, 800, 600))
self.Label_Right.setStyleSheet("background-color: rgb(255, 255, 255);\n"
"border-top-right-radius: 25px;\n"
"border-bottom-right-radius: 25px;")
self.Label_Right.setText("")
self.Label_Right.setObjectName("Label_Right")
self.Label_Logo = QtWidgets.QLabel(Dialog)
self.Label_Logo.setGeometry(QtCore.QRect(30, 50, 161, 41))
self.Label_Logo.setStyleSheet(
"background: url(:/img/logo-horizontal.svg) no-repeat;")
self.Label_Logo.setText("")
self.Label_Logo.setObjectName("Label_Logo")
self.Label_Version = QtWidgets.QLabel(Dialog)
self.Label_Version.setGeometry(QtCore.QRect(180, 90, 54, 12))
self.Label_Version.setStyleSheet("color: rgb(255, 255, 255);\n"
"font: 9pt \"微软雅黑\";")
self.Label_Version.setObjectName("Label_Version")
self.Button_Close = QtWidgets.QPushButton(Dialog)
self.Button_Close.setGeometry(QtCore.QRect(980, 20, 21, 21))
self.Button_Close.setStyleSheet("border-radius: 10px;\n"
"background-color: rgb(255, 81, 53);")
self.Button_Close.setText("")
self.Button_Close.setObjectName("Button_Close")
self.Button_Max = QtWidgets.QPushButton(Dialog)
self.Button_Max.setGeometry(QtCore.QRect(950, 20, 21, 21))
self.Button_Max.setStyleSheet("border-radius: 10px;\n"
"background-color: #FFC32D;")
self.Button_Max.setText("")
self.Button_Max.setObjectName("Button_Max")
self.Button_Min = QtWidgets.QPushButton(Dialog)
self.Button_Min.setGeometry(QtCore.QRect(920, 20, 21, 21))
self.Button_Min.setStyleSheet("border-radius: 10px;\n"
"background-color: #37C847;")
self.Button_Min.setText("")
self.Button_Min.setObjectName("Button_Min")
self.plainTextEdit = QtWidgets.QPlainTextEdit(Dialog)
self.plainTextEdit.setGeometry(QtCore.QRect(260, 90, 601, 41))
self.plainTextEdit.setAutoFillBackground(False)
self.plainTextEdit.setStyleSheet("background-color: #292B35;\n"
"border-radius: 10px;\n"
"font: 20pt \"微软雅黑\";\n"
"color: rgb(255, 255, 255);")
self.plainTextEdit.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.plainTextEdit.setVerticalScrollBarPolicy(
QtCore.Qt.ScrollBarAsNeeded)
self.plainTextEdit.setSizeAdjustPolicy(
QtWidgets.QAbstractScrollArea.AdjustIgnored)
self.plainTextEdit.setLineWrapMode(
QtWidgets.QPlainTextEdit.WidgetWidth)
self.plainTextEdit.setBackgroundVisible(False)
self.plainTextEdit.setCenterOnScroll(False)
self.plainTextEdit.setObjectName("plainTextEdit")
self.Button_Go = QtWidgets.QPushButton(Dialog)
self.Button_Go.setGeometry(QtCore.QRect(880, 90, 130, 41))
self.Button_Go.setStyleSheet("#Button_Go {\n"
" border-radius: 10px;\n"
" font: 19pt \"微软雅黑\";\n"
" color: rgb(0, 0, 0);\n"
" background-color: #B9BAC7;\n"
"}\n"
"\n"
"#Button_Go:hover {\n"
" color:#F72C51;\n"
"}\n"
"\n"
"#Button_Go:pressed, QPushButton:checked {\n"
" background-color: #9d9d9d;\n"
"}\n"
"")
self.Button_Go.setObjectName("Button_Go")
self.Label_Background = QtWidgets.QLabel(Dialog)
self.Label_Background.setGeometry(QtCore.QRect(230, 0, 800, 60))
self.Label_Background.setStyleSheet("background-color: rgb(199, 199, 199);\n"
"border-top-right-radius: 25px;")
self.Label_Background.setText("")
self.Label_Background.setObjectName("Label_Background")
self.widget = QtWidgets.QWidget(Dialog)
self.widget.setGeometry(QtCore.QRect(260, 190, 611, 351))
self.widget.setObjectName("widget")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(50, 390, 131, 61))
self.pushButton.setStyleSheet("border-radius: 25px;\n"
"font: 16pt \"微软雅黑\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(22, 23, 34);")
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(50, 490, 131, 61))
self.pushButton_2.setStyleSheet("border-radius: 25px;\n"
"font: 16pt \"微软雅黑\";\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(22, 23, 34);")
self.pushButton_2.setObjectName("pushButton_2")
self.Check_All = QtWidgets.QCheckBox(Dialog)
self.Check_All.setGeometry(QtCore.QRect(260, 140, 71, 16))
self.Check_All.setObjectName("Check_All")
self.Check_All.setStyleSheet("font: 10pt \"微软雅黑\";\n")
self.Check_Cover = QtWidgets.QCheckBox(Dialog)
self.Check_Cover.setGeometry(QtCore.QRect(340, 140, 101, 16))
self.Check_Cover.setObjectName("Check_Cover")
self.Check_Cover.setStyleSheet("font: 10pt \"微软雅黑\";\n")
self.Check_Music = QtWidgets.QCheckBox(Dialog)
self.Check_Music.setGeometry(QtCore.QRect(440, 140, 101, 16))
self.Check_Music.setObjectName("Check_Music")
self.Check_Music.setStyleSheet("font: 10pt \"微软雅黑\";\n")
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(260, 170, 750, 401))
self.textBrowser.setObjectName("textBrowser")
# 去除滚动条
self.textBrowser.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.textBrowser.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.textBrowser.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
# 去除边框
self.textBrowser.setStyleSheet("border-width:0;border-style:outset;")
self.Label_Right.raise_()
self.Label_Background.raise_()
self.Label_Left.raise_()
self.Label_Logo.raise_()
self.Label_Version.raise_()
self.Button_Close.raise_()
self.Button_Max.raise_()
self.Button_Min.raise_()
self.plainTextEdit.raise_()
self.Button_Go.raise_()
self.widget.raise_()
self.Check_All.raise_()
self.pushButton.raise_()
self.pushButton_2.raise_()
self.Check_Cover.raise_()
self.Check_Music.raise_()
self.textBrowser.raise_()
self.setMinimumHeight(600)
self.setMinimumWidth(900)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def mouseMoveEvent(self, e: QMouseEvent):
"""# 重写移动事件
Args:
e (QMouseEvent): 鼠标事件
"""
try:
self._endPos = e.pos() - self._startPos
self.move(self.pos() + self._endPos)
except:
pass
def mousePressEvent(self, e: QMouseEvent):
try:
if e.button() == Qt.LeftButton:
self._isTracking = True
self._startPos = QPoint(e.x(), e.y())
except:
pass
def mouseReleaseEvent(self, e: QMouseEvent):
try:
if e.button() == Qt.LeftButton:
self._isTracking = False
self._startPos = None
self._endPos = None
except:
pass
def btnClick(self):
"""咻咻按钮事件
"""
global newuid
newuid = self.plainTextEdit.toPlainText()
# 创建线程
self.thread_1 = PreventFastClickThreadMutex()
# 开始线程
self.thread_1.start()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("TikTokDownload", "TikTokDownload"))
self.Label_Version.setText(_translate("TikTokDownload", "v2.1.1"))
self.Button_Min.setToolTip('最小化')
self.Button_Max.setToolTip('最大化')
self.Button_Close.setToolTip('关闭')
self.Button_Go.setText(_translate("TikTokDownload", "咻咻"))
self.Check_All.setText(_translate("TikTokDownload", "全部下载"))
self.pushButton.setText(_translate("TikTokDownload", "设置"))
self.pushButton_2.setText(_translate("TikTokDownload", "关于"))
self.Check_Cover.setText(_translate("TikTokDownload", "全部封面下载"))
self.Check_Music.setText(_translate("TikTokDownload", "全部配乐下载"))
self.plainTextEdit.setPlainText("https://v.douyin.com/efrHYf2/")
self.Button_Go.clicked.connect(lambda: self.btnClick())
self.Button_Max.clicked.connect(lambda: self.MaxButton())
self.Button_Min.clicked.connect(lambda: self.MinButton())
self.Button_Close.clicked.connect(lambda: self.CloseButton())
def MaxButton(self):
"""最大化与还原的切换
"""
if self.isMaximized():
self.showNormal()
self.Button_Max.setToolTip('最大化')
else:
self.showMaximized()
self.Button_Max.setToolTip('还原')
def MinButton(self):
"""最小化
"""
self.showMinimized()
def CloseButton(self):
"""关闭
"""
sys.exit(0)
if __name__ == "__main__":
app = QApplication(sys.argv)
# 初始化控件
w = Ui_Dialog()
# 去掉窗口标题栏和按钮
w.setWindowFlags(Qt.FramelessWindowHint)
# 设置窗口真透明
w.setAttribute(Qt.WA_TranslucentBackground)
w.show()
sys.exit(app.exec_())