-
Notifications
You must be signed in to change notification settings - Fork 103
/
DD监控室.py
1331 lines (1197 loc) · 60.7 KB
/
DD监控室.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
DD监控室主界面进程 包含对所有子页面的初始化、排版管理
同时卡片和播放窗口的交互需要通过主界面线程通信
以及软件启动和退出后的一些操作
新增全局鼠标坐标跟踪 用于刷新鼠标交互效果
"""
import log
# 找不到 dll
# https://stackoverflow.com/questions/54110504/dynlib-dll-was-no-found-when-the-application-was-frozen-when-i-make-a-exe-fil
import ctypes
import os
import sys
import json
import time
import shutil
import logging
import platform
import threading
from PyQt5.QtWidgets import * # QAction,QFileDialog
from PyQt5.QtGui import * # QIcon,QPixmap
from PyQt5.QtCore import * # QSize
from LayoutPanel import LayoutSettingPanel
# from VideoWidget import PushButton, Slider, VideoWidget # 已弃用
from VideoWidget_vlc import PushButton, Slider, VideoWidget
from LiverSelect import LiverPanel
from pay import pay
import codecs
import dns.resolver
from ReportException import thraedingExceptionHandler, uncaughtExceptionHandler,\
unraisableExceptionHandler, loggingSystemInfo
from danmu import TextOpation, ToolButton
# 程序所在路径
application_path = ""
def _translate(context, text, disambig):
return QApplication.translate(context, text, disambig)
class ControlWidget(QWidget):
heightValue = pyqtSignal(int)
def __init__(self):
super(ControlWidget, self).__init__()
def resizeEvent(self, QResizeEvent):
self.heightValue.emit(self.height())
class ScrollArea(QScrollArea):
multipleTimes = pyqtSignal(int)
addLiver = pyqtSignal()
clearAll = pyqtSignal()
def __init__(self):
super(ScrollArea, self).__init__()
self.multiple = self.width() // 169
self.horizontalScrollBar().setVisible(False)
def sizeHint(self):
return QSize(100, 90)
def mouseReleaseEvent(self, QMouseEvent):
if QMouseEvent.button() == Qt.RightButton:
menu = QMenu()
addLiver = menu.addAction('添加直播间')
menu.addSeparator() # 添加分割线,防止误操作
clearAll = menu.addAction('清空')
action = menu.exec_(self.mapToGlobal(QMouseEvent.pos()))
if action == addLiver:
self.addLiver.emit()
elif action == clearAll:
self.clearAll.emit()
def wheelEvent(self, QEvent):
if QEvent.angleDelta().y() < 0:
value = self.verticalScrollBar().value()
self.verticalScrollBar().setValue(value + 80)
elif QEvent.angleDelta().y() > 0:
value = self.verticalScrollBar().value()
self.verticalScrollBar().setValue(value - 80)
def resizeEvent(self, QResizeEvent):
multiple = self.width() // 169
if multiple and multiple != self.multiple: # 按卡片长度的倍数调整且不为0
self.multiple = multiple
self.multipleTimes.emit(multiple)
class DockWidget(QDockWidget):
def __init__(self, title):
super(DockWidget, self).__init__()
self.setWindowTitle(title)
self.setObjectName(f'dock-{title}')
self.setFloating(False)
self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea | Qt.TopDockWidgetArea)
class StartLiveWindow(QWidget):
"""开播提醒弹窗"""
def __init__(self):
super(StartLiveWindow, self).__init__()
self.setWindowTitle('开播提醒')
self.setWindowFlag(Qt.WindowStaysOnTopHint)
self.resize(240, 70)
self.tipLabel = QLabel()
self.tipLabel.setStyleSheet('color:#293038;background-color:#eeeeee')
self.tipLabel.setFont(QFont('微软雅黑', 15, QFont.Bold))
layout = QGridLayout(self)
layout.setContentsMargins(3, 3, 3, 3)
layout.addWidget(self.tipLabel)
self.hideTimer = QTimer()
self.hideTimer.setInterval(10000)
self.hideTimer.timeout.connect(self.hide) # 10秒倒计时结束隐藏
def mousePressEvent(self, QMouseEvent): # 点击的话就停止倒计时
self.hideTimer.stop()
class CacheSetting(QWidget):
"""缓存设置窗口"""
setting = pyqtSignal(list)
def __init__(self):
super(CacheSetting, self).__init__()
self.resize(400, 200)
self.setWindowTitle('缓存设置')
layout = QGridLayout(self)
layout.addWidget(QLabel('最大缓存(GB)'), 0, 0, 1, 1)
self.maxCacheEdit = QLineEdit()
self.maxCacheEdit.setValidator(QIntValidator(1, 9))
layout.addWidget(self.maxCacheEdit, 0, 1, 1, 3)
layout.addWidget(QLabel('缓存自动备份至以上路径 (若不填则默认删除)'), 2, 0, 1, 3)
selectButton = QPushButton('备份路径')
selectButton.setStyleSheet('background-color:#31363b;border-width:1px')
selectButton.clicked.connect(self.selectCopyPath)
layout.addWidget(selectButton, 1, 0, 1, 1)
self.savePathEdit = QLineEdit()
layout.addWidget(self.savePathEdit, 1, 1, 1, 3)
okButton = QPushButton('OK')
okButton.setStyleSheet('background-color:#3daee9;border-width:1px')
okButton.clicked.connect(self.sendSetting)
layout.addWidget(okButton, 2, 3, 1, 1)
def selectCopyPath(self):
savePath = QFileDialog.getExistingDirectory(self, "选择备份缓存路径", None, QFileDialog.ShowDirsOnly)
if savePath:
self.savePathEdit.setText(savePath)
def sendSetting(self):
self.setting.emit([self.maxCacheEdit.text(), self.savePathEdit.text()])
self.hide()
class Version(QWidget):
"""版本说明窗口"""
def __init__(self):
super(Version, self).__init__()
self.resize(350, 150)
self.setWindowTitle('当前版本')
layout = QGridLayout(self)
layout.addWidget(QLabel('DD监控室 v2.8正式版'), 0, 0, 1, 2)
layout.addWidget(QLabel('by 神君Channel'), 1, 0, 1, 2)
layout.addWidget(QLabel('特别鸣谢:大锅饭 美东矿业 inkydragon 聪_哥'), 2, 0, 1, 2)
releases_url = QLabel('')
releases_url.setOpenExternalLinks(True)
releases_url.setText(_translate("MainWindow", "<html><head/><body><p><a href=\"https://space.bilibili.com/637783\">\
<span style=\" text-decoration: underline; color:#cccccc;\">https://space.bilibili.com/637783</span></a></p></body></html>", None))
layout.addWidget(releases_url, 1, 1, 1, 2, Qt.AlignRight)
checkButton = QPushButton('检查更新')
checkButton.setFixedHeight(40)
checkButton.clicked.connect(self.checkUpdate)
layout.addWidget(checkButton, 0, 2, 1, 1)
def checkUpdate(self):
QDesktopServices.openUrl(QUrl(r'https://github.com/zhimingshenjun/DD_Monitor/releases/tag/DD_Monitor'))
class HotKey(QWidget):
"""热键说明窗口"""
def __init__(self):
super(HotKey, self).__init__()
self.resize(350, 150)
self.setWindowTitle('快捷键')
layout = QGridLayout(self)
layout.addWidget(QLabel('F、f —— 全屏'), 0, 0)
layout.addWidget(QLabel('H、h —— 隐藏控制条'), 1, 0)
layout.addWidget(QLabel('M、m、S、s —— 除当前鼠标悬停窗口外全部静音'), 2, 0)
class DumpConfig(QThread):
"""导出配置"""
def __init__(self, config):
super(DumpConfig, self).__init__()
self.config = config
self.backupNumber = 1
def run(self):
try:
configJSONPath = os.path.join(application_path, r'utils/config.json')
with codecs.open(configJSONPath, 'w', encoding='utf-8') as f:
f.write(json.dumps(self.config, ensure_ascii=False))
except:
logging.exception('config.json 写入失败')
try: # 备份 防止存储config时崩溃
configJSONPath = os.path.join(application_path, r'utils/config_备份%d.json' % self.backupNumber)
self.backupNumber += 1
if self.backupNumber == 4:
self.backupNumber = 1
# with open(configJSONPath, 'w') as f:
# f.write(json.dumps(self.config, ensure_ascii=False))
with codecs.open(configJSONPath, 'w', encoding='utf-8') as f:
f.write(json.dumps(self.config, ensure_ascii=False))
except:
logging.exception('config_备份.json 备份配置文件写入失败')
class CheckDanmmuProvider(QThread):
"""检查弹幕服务器域名解析状态"""
def __init__(self):
super(CheckDanmmuProvider,self).__init__()
def run(self):
try:
anwsers = dns.resolver.resolve('broadcastlv.chat.bilibili.com', 'A')
danmu_ip = anwsers[0].to_text()
logging.info("弹幕IP: %s" % danmu_ip)
except Exception as e:
logging.error("解析弹幕域名失败")
logging.error(str(e))
class MainWindow(QMainWindow):
"""主窗口"""
def __init__(self, cacheFolder, progressBar, progressText):
super(MainWindow, self).__init__()
self.setWindowTitle('DD监控室')
self.resize(1600, 900)
self.maximumToken = True
self.soloToken = False # 记录静音除鼠标悬停窗口以外的其他所有窗口的标志位 True就是恢复所有房间声音
self.cacheFolder = cacheFolder
# ---- json 配置文件加载 ----
self.configJSONPath = os.path.join(
application_path, r'utils/config.json')
self.config = {}
# 读取默认的 config
if os.path.exists(self.configJSONPath):
if os.path.getsize(self.configJSONPath):
try:
with codecs.open(self.configJSONPath, 'r', encoding='utf-8') as f:
self.config = json.loads(f.read())
# self.config = json.loads(open(self.configJSONPath).read())
except:
logging.exception('json 配置读取失败')
self.config = {}
# 读取config失败 尝试读取备份
if not self.config:
for backupNumber in [1, 2, 3]: # 备份预设123
self.configJSONPath = os.path.join(
application_path, r'utils/config_备份%d.json' % backupNumber)
if os.path.exists(self.configJSONPath): # 如果备份文件存在
if os.path.getsize(self.configJSONPath): # 如过备份文件有效
try:
self.config = json.loads(
open(self.configJSONPath).read())
break
except:
logging.exception('json 备份配置读取失败')
self.config = {}
# 如果能成功读取到config文件
if self.config:
while len(self.config['player']) < 16:
self.config['player'].append('0')
while len(self.config['volume']) < 16:
self.config['volume'].append(0)
while len(self.config['danmu']) < 16:
self.config['danmu'].append([True, 50, 1, 7, 0, "【 [ {", 10])
while len(self.config['muted']) < 16:
self.config['muted'].append(1)
while len(self.config['quality']) < 16:
self.config['quality'].append(80)
while len(self.config['audioChannel']) < 16:
self.config['audioChannel'].append(0)
self.config['player'] = list(map(str, self.config['player']))
if type(self.config['roomid']) == list:
roomIDList = self.config['roomid']
self.config['roomid'] = {}
for roomID in roomIDList:
self.config['roomid'][roomID] = False
if '0' in self.config['roomid']: # 过滤0房间号
del self.config['roomid']['0']
if 'quality' not in self.config:
self.config['quality'] = [80] * 16
if 'audioChannel' not in self.config:
self.config['audioChannel'] = [0] * 16
if 'translator' not in self.config:
self.config['translator'] = [True] * 16
for index, textSetting in enumerate(self.config['danmu']):
if type(textSetting) == bool:
self.config['danmu'][index] = [
textSetting, 20, 1, 7, 0, '【 [ {']
if 'hardwareDecode' not in self.config:
self.config['hardwareDecode'] = True
if 'maxCacheSize' not in self.config:
self.config['maxCacheSize'] = 2048000
logging.warning('最大缓存没有被设置,使用默认1G')
if 'saveCachePath' not in self.config:
self.config['saveCachePath'] = ''
logging.warning('默认缓存备份路径为空 即自动清空')
if 'startWithDanmu' not in self.config:
self.config['startWithDanmu'] = True
logging.warning('启动时加载弹幕没有被设置,默认加载')
if 'showStartLive' not in self.config:
self.config['showStartLive'] = True
for danmuConfig in self.config['danmu']:
if len(danmuConfig) == 6:
danmuConfig.append(10)
else: # 默认和备份 json 配置均读取失败
self.config = {
# 置顶显示
'roomid': {'21396545': False, '21402309': False, '22384516': False, '8792912': False},
'layout': [(0, 0, 1, 1), (0, 1, 1, 1), (1, 0, 1, 1), (1, 1, 1, 1)],
'player': ['0'] * 16,
'quality': [80] * 16,
'audioChannel': [0] * 16,
'muted': [1] * 16,
'volume': [50] * 16,
# 显示,透明,横向,纵向,类型,同传字符,字体大小
'danmu': [[True, 50, 1, 7, 0, '【 [ {', 10]] * 16,
'globalVolume': 30,
'control': True,
'hardwareDecode': True,
'maxCacheSize': 2048000,
'saveCachePath': '',
'startWithDanmu': True,
'showStartLive': True,
}
self.dumpConfig = DumpConfig(self.config)
# ---- 主窗体控件 ----
mainWidget = QWidget()
self.setCentralWidget(mainWidget)
# Grid 布局
self.mainLayout = QGridLayout(mainWidget)
self.mainLayout.setSpacing(0)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.layoutSettingPanel = LayoutSettingPanel()
self.layoutSettingPanel.layoutConfig.connect(self.changeLayout)
self.version = Version()
self.cacheSetting = CacheSetting()
self.cacheSetting.maxCacheEdit.setText(
str(self.config['maxCacheSize'] // 1024000))
self.cacheSetting.savePathEdit.setText(self.config['saveCachePath'])
self.cacheSetting.setting.connect(self.setCache)
self.hotKey = HotKey()
self.pay = pay()
self.startLiveWindow = StartLiveWindow()
# ---- 内嵌/弹出播放器初始化 ----
self.videoWidgetList = []
self.popVideoWidgetList = []
vlcProgressCounter = 1
for i in range(16):
if len(self.config['danmu'][i]) < 8:
self.config['danmu'][i].append(3)
volume = self.config['volume'][i]
progressText.setText('设置第%s个主层播放器...' % str(i + 1))
self.videoWidgetList.append(VideoWidget(i, volume, cacheFolder, textSetting=self.config['danmu'][i],
maxCacheSize=self.config['maxCacheSize'],
saveCachePath=self.config['saveCachePath'],
startWithDanmu=self.config['startWithDanmu'],
hardwareDecode=self.config['hardwareDecode']))
vlcProgressCounter += 1
progressBar.setValue(vlcProgressCounter)
self.videoWidgetList[i].mutedChanged.connect(self.mutedChanged)
self.videoWidgetList[i].volumeChanged.connect(self.volumeChanged)
self.videoWidgetList[i].addMedia.connect(self.addMedia)
self.videoWidgetList[i].deleteMedia.connect(self.deleteMedia)
self.videoWidgetList[i].exchangeMedia.connect(self.exchangeMedia)
# self.videoWidgetList[i].setDanmu.connect(self.setDanmu) # 硬盘io过高 屏蔽掉 退出的时候统一保存
# self.videoWidgetList[i].setTranslator.connect(self.setTranslator) # 已废弃
self.videoWidgetList[i].changeQuality.connect(self.setQuality)
# self.videoWidgetList[i].changeAudioChannel.connect(self.setAudioChannel) # 硬盘io过高 屏蔽掉 退出的时候统一保存
self.videoWidgetList[i].popWindow.connect(self.popWindow)
self.videoWidgetList[i].hideBarKey.connect(self.openControlPanel)
self.videoWidgetList[i].fullScreenKey.connect(self.fullScreen)
self.videoWidgetList[i].muteExceptKey.connect(self.muteExcept)
self.videoWidgetList[i].mediaMute(
self.config['muted'][i], emit=False)
self.videoWidgetList[i].slider.setValue(self.config['volume'][i])
self.videoWidgetList[i].quality = self.config['quality'][i]
self.videoWidgetList[i].audioChannel = self.config['audioChannel'][i]
self.popVideoWidgetList.append(VideoWidget(i + 16, volume, cacheFolder, True, '悬浮窗', [1280, 720],
maxCacheSize=self.config['maxCacheSize'],
saveCachePath=self.config['saveCachePath'],
startWithDanmu=self.config['startWithDanmu'],
hardwareDecode=self.config['hardwareDecode']))
self.popVideoWidgetList[i].closePopWindow.connect(
self.closePopWindow)
vlcProgressCounter += 1
progressBar.setValue(vlcProgressCounter)
progressText.setText('设置第%s个悬浮窗播放器...' % str(i + 1))
app.processEvents()
logging.info("VLC设置完毕 %s / 16" % str(i + 1))
# 设置所有播放器布局
self.setPlayer()
self.controlDock = DockWidget('控制条')
self.controlDock.setFixedWidth(178)
self.addDockWidget(Qt.TopDockWidgetArea, self.controlDock)
self.controlWidget = ControlWidget()
self.controlWidget.heightValue.connect(self.showAddButton)
self.controlDock.setWidget(self.controlWidget)
self.controlBarLayout = QGridLayout(self.controlWidget)
self.globalPlayToken = True
self.play = PushButton(self.style().standardIcon(QStyle.SP_MediaPause))
self.play.clicked.connect(self.globalMediaPlay)
self.controlBarLayout.addWidget(self.play, 0, 0, 1, 1)
self.reload = PushButton(
self.style().standardIcon(QStyle.SP_BrowserReload))
self.reload.clicked.connect(self.globalMediaReload)
self.controlBarLayout.addWidget(self.reload, 0, 1, 1, 1)
self.stop = PushButton(self.style().standardIcon(
QStyle.SP_DialogCancelButton))
self.stop.clicked.connect(self.globalMediaStop)
self.controlBarLayout.addWidget(self.stop, 0, 2, 1, 1)
# 全局弹幕设置
self.danmuOption = TextOpation()
self.danmuOption.setWindowTitle('全局弹幕窗设置')
self.danmuOption.opacitySlider.value.connect(
self.setGlobalDanmuOpacity)
self.danmuOption.horizontalCombobox.currentIndexChanged.connect(
self.setGlobalHorizontalPercent)
self.danmuOption.verticalCombobox.currentIndexChanged.connect(
self.setGlobalVerticalPercent)
self.danmuOption.translateCombobox.currentIndexChanged.connect(
self.setGlobalTranslateBrowser)
self.danmuOption.showEnterRoom.currentIndexChanged.connect(
self.setGlobalShowEnterRoom)
self.danmuOption.translateFitler.textChanged.connect(
self.setGlobalTranslateFilter)
self.danmuOption.fontSizeCombox.currentIndexChanged.connect(
self.setGlobalFontSize)
# self.danmuButton = ToolButton(self.style().standardIcon(QStyle.SP_FileDialogDetailedView))
icon = QIcon()
icon.addFile(os.path.join(application_path, 'utils/danmu.png'))
self.danmuButton = PushButton(icon)
self.danmuButton.clicked.connect(self.danmuOption.show)
# self.danmuButton = PushButton(text='弹')
# self.globalDanmuToken = True
# self.danmuButton.clicked.connect(self.globalDanmuShow)
self.controlBarLayout.addWidget(self.danmuButton, 0, 3, 1, 1)
# 全局静音
self.globalMuteToken = False
self.volumeButton = PushButton(
self.style().standardIcon(QStyle.SP_MediaVolume))
self.volumeButton.clicked.connect(self.globalMediaMute)
self.controlBarLayout.addWidget(self.volumeButton, 1, 0, 1, 1)
# 全局音量滑条
self.slider = Slider()
self.slider.setValue(self.config['globalVolume'])
self.slider.value.connect(self.globalSetVolume)
self.controlBarLayout.addWidget(self.slider, 1, 1, 1, 3)
progressText.setText('设置播放器控制...')
# 添加主播按钮
self.addButton = QPushButton('+')
self.addButton.setFixedSize(160, 90)
self.addButton.setStyleSheet('border:3px dotted #EEEEEE')
self.addButton.setFont(QFont('Arial', 24, QFont.Bold))
progressText.setText('设置添加控制...')
self.controlBarLayout.addWidget(self.addButton, 2, 0, 1, 4)
progressText.setText('设置全局控制...')
self.scrollArea = ScrollArea()
self.scrollArea.setStyleSheet('border-width:0px')
# self.scrollArea.setMinimumHeight(111)
self.cardDock = DockWidget('卡片槽')
self.cardDock.setWidget(self.scrollArea)
self.addDockWidget(Qt.TopDockWidgetArea, self.cardDock)
# self.controlBarLayout.addWidget(self.scrollArea, 3, 0, 1, 5)
# 主播添加窗口
self.liverPanel = LiverPanel(self.config['roomid'], application_path)
self.liverPanel.addLiverRoomWidget.getHotLiver.start()
self.liverPanel.addToWindow.connect(self.addCoverToPlayer)
self.liverPanel.dumpConfig.connect(self.dumpConfig.start) # 保存config
self.liverPanel.refreshIDList.connect(
self.refreshPlayerStatus) # 刷新播放器
self.liverPanel.startLiveList.connect(self.startLiveTip) # 开播提醒
self.scrollArea.setWidget(self.liverPanel)
self.scrollArea.multipleTimes.connect(self.changeLiverPanelLayout)
self.scrollArea.addLiver.connect(self.liverPanel.openLiverRoomPanel)
self.scrollArea.clearAll.connect(self.clearLiverPanel)
self.addButton.clicked.connect(self.liverPanel.openLiverRoomPanel)
self.liverPanel.updatePlayingStatus(self.config['player'])
progressText.setText('设置主播选择控制...')
# ---- 菜单设置 ----
self.optionMenu = self.menuBar().addMenu('设置')
self.controlBarLayoutToken = self.config['control']
layoutConfigAction = QAction(
'布局方式', self, triggered=self.openLayoutSetting)
self.optionMenu.addAction(layoutConfigAction)
globalQualityMenu = self.optionMenu.addMenu('全局画质 ►')
originQualityAction = QAction(
'原画', self, triggered=lambda: self.globalQuality(10000))
globalQualityMenu.addAction(originQualityAction)
bluerayQualityAction = QAction(
'蓝光', self, triggered=lambda: self.globalQuality(400))
globalQualityMenu.addAction(bluerayQualityAction)
highQualityAction = QAction(
'超清', self, triggered=lambda: self.globalQuality(250))
globalQualityMenu.addAction(highQualityAction)
lowQualityAction = QAction(
'流畅', self, triggered=lambda: self.globalQuality(80))
globalQualityMenu.addAction(lowQualityAction)
onlyAudio = QAction(
'仅播声音', self, triggered=lambda: self.globalQuality(-1))
globalQualityMenu.addAction(onlyAudio)
globalAudioMenu = self.optionMenu.addMenu('全局音效 ►')
audioOriginAction = QAction(
'原始音效', self, triggered=lambda: self.globalAudioChannel(0))
globalAudioMenu.addAction(audioOriginAction)
audioDolbysAction = QAction(
'杜比音效', self, triggered=lambda: self.globalAudioChannel(5))
globalAudioMenu.addAction(audioDolbysAction)
hardDecodeMenu = self.optionMenu.addMenu('解码方案 ►')
hardDecodeAction = QAction(
'硬解', self, triggered=lambda: self.setDecode(True))
hardDecodeMenu.addAction(hardDecodeAction)
softDecodeAction = QAction(
'软解', self, triggered=lambda: self.setDecode(False))
hardDecodeMenu.addAction(softDecodeAction)
startLiveSetting = self.optionMenu.addMenu('开播提醒 ►')
enableStartLive = QAction(
'打开', self, triggered=lambda: self.setStartLive(True))
startLiveSetting.addAction(enableStartLive)
disableStartLive = QAction(
'关闭', self, triggered=lambda: self.setStartLive(False))
startLiveSetting.addAction(disableStartLive)
cacheSizeSetting = QAction(
'缓存设置', self, triggered=self.openCacheSetting)
self.optionMenu.addAction(cacheSizeSetting)
startWithDanmuSetting = QAction(
'自动加载弹幕设置', self, triggered=self.openStartWithDanmuSetting)
self.optionMenu.addAction(startWithDanmuSetting)
controlPanelAction = QAction(
'显示 / 隐藏控制条(H)', self, triggered=self.openControlPanel)
self.optionMenu.addAction(controlPanelAction)
self.fullScreenAction = QAction(
'全屏(F) / 退出(Esc)', self, triggered=self.fullScreen)
self.optionMenu.addAction(self.fullScreenAction)
exportConfig = QAction('导出预设', self, triggered=self.exportConfig)
self.optionMenu.addAction(exportConfig)
importConfig = QAction('导入预设', self, triggered=self.importConfig)
self.optionMenu.addAction(importConfig)
progressText.setText('设置选项菜单...')
self.versionMenu = self.menuBar().addMenu('帮助')
bilibiliAction = QAction('B站视频', self, triggered=self.openBilibili)
self.versionMenu.addAction(bilibiliAction)
hotKeyAction = QAction('快捷键', self, triggered=self.openHotKey)
self.versionMenu.addAction(hotKeyAction)
versionAction = QAction('检查版本', self, triggered=self.openVersion)
self.versionMenu.addAction(versionAction)
otherDDMenu = self.versionMenu.addMenu('其他DD系列工具 ►')
DDSubtitleAction = QAction(
'DD烤肉机', self, triggered=self.openDDSubtitle)
otherDDMenu.addAction(DDSubtitleAction)
DDThanksAction = QAction('DD答谢机', self, triggered=self.openDDThanks)
otherDDMenu.addAction(DDThanksAction)
progressText.setText('设置帮助菜单...')
self.payMenu = self.menuBar().addMenu('开源和投喂')
githubAction = QAction('GitHub', self, triggered=self.openGithub)
self.payMenu.addAction(githubAction)
feedAction = QAction('投喂作者', self, triggered=self.openFeed)
self.payMenu.addAction(feedAction)
# killAction = QAction('自尽(测试)', self, triggered=lambda a: 0 / 0)
# self.payMenu.addAction(killAction)
progressText.setText('设置关于菜单...')
# 鼠标和计时器
self.oldMousePos = QPoint(0, 0) # 初始化鼠标坐标
self.hideMouseCnt = 90
self.mouseTrackTimer = QTimer()
self.mouseTrackTimer.timeout.connect(self.checkMousePos)
self.mouseTrackTimer.start(100) # 0.1s检测一次
progressText.setText('设置UI...')
self.checkDanmmuProvider = CheckDanmmuProvider()
self.checkDanmmuProvider.start()
self.loadDockLayout()
logging.info('UI构造完毕')
def setPlayer(self):
for index, layoutConfig in enumerate(self.config['layout']):
roomID = self.config['player'][index]
videoWidget = self.videoWidgetList[index]
videoWidget.roomID = str(roomID) # 转一下防止格式出错
y, x, h, w = layoutConfig
self.mainLayout.addWidget(videoWidget, y, x, h, w)
self.videoWidgetList[index].show()
self.videoIndex = 0
self.setMediaTimer = QTimer()
self.setMediaTimer.timeout.connect(self.setMedia)
# self.setMediaTimer.start(500) # QMediaPlayer加载慢一点 否则容易崩
self.setMediaTimer.start(10) # vlc
def setMedia(self):
if self.videoIndex == 16:
self.setMediaTimer.stop()
elif self.videoIndex < len(self.config['layout']):
# pass
self.videoWidgetList[self.videoIndex].mediaReload()
else:
self.videoWidgetList[self.videoIndex].playerRestart()
self.videoIndex += 1
def addMedia(self, info): # 窗口 房号
id, roomID = info
self.config['player'][id] = roomID
self.liverPanel.updatePlayingStatus(self.config['player'])
self.dumpConfig.start()
def deleteMedia(self, id):
self.config['player'][id] = 0
self.liverPanel.updatePlayingStatus(self.config['player'])
self.dumpConfig.start()
def exchangeMedia(self, info): # 交换播放窗口的函数
fromID, fromRoomID, toID, toRoomID = info # 交换数据
# 待交换的两个控件
fromVideo, toVideo = self.videoWidgetList[fromID], self.videoWidgetList[toID]
fromVideo.id, toVideo.id = toID, fromID # 交换id
fromVideo.topLabel.setText(fromVideo.topLabel.text().replace(
'窗口%s' % (fromID + 1), '窗口%s' % (toID + 1)))
toVideo.topLabel.setText(toVideo.topLabel.text().replace(
'窗口%s' % (toID + 1), '窗口%s' % (fromID + 1)))
fromWidth, fromHeight = fromVideo.width(), fromVideo.height()
toWidth, toHeight = toVideo.width(), toVideo.height()
if 3 < abs(fromWidth - toWidth) or 3 < abs(fromHeight - toHeight): # 有主次关系的播放窗交换同时交换音量和弹幕设置
fromMuted = 2 if fromVideo.player.audio_get_mute() else 1
toMuted = 2 if toVideo.player.audio_get_mute() else 1
fromVolume, toVolume = fromVideo.player.audio_get_volume(
), toVideo.player.audio_get_volume() # 音量值
fromVideo.mediaMute(toMuted) # 交换静音设置
fromVideo.setVolume(toVolume) # 交换音量
toVideo.mediaMute(fromMuted)
toVideo.setVolume(fromVolume)
fromVideo.textSetting, toVideo.textSetting = toVideo.textSetting, fromVideo.textSetting # 交换弹幕设置
for videoWidget in [fromVideo, toVideo]:
color = str(
hex(int(videoWidget.textSetting[1] / 101 * 256)))[2:] + '000000'
videoWidget.textBrowser.textBrowser.setStyleSheet(
'background-color:#%s' % color) # 设置透明度
videoWidget.textBrowser.transBrowser.setStyleSheet(
'background-color:#%s' % color)
videoWidget.textBrowser.msgsBrowser.setStyleSheet(
'background-color:#%s' % color)
videoWidget.horiPercent = [
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0][videoWidget.textSetting[2]]
videoWidget.vertPercent = [
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0][videoWidget.textSetting[3]]
if videoWidget.textSetting[4] == 0: # 显示弹幕和同传
videoWidget.textBrowser.textBrowser.show()
videoWidget.textBrowser.transBrowser.show()
elif videoWidget.textSetting[4] == 1: # 只显示弹幕
videoWidget.textBrowser.transBrowser.hide()
videoWidget.textBrowser.textBrowser.show()
elif videoWidget.textSetting[4] == 2: # 只显示同传
videoWidget.textBrowser.textBrowser.hide()
videoWidget.textBrowser.transBrowser.show()
videoWidget.filters = videoWidget.textSetting[5].split(' ')
if videoWidget.textSetting[7] < 3:
videoWidget.textBrowser.msgsBrowser.show()
elif videoWidget.textSetting[7] == 3:
videoWidget.textBrowser.msgsBrowser.hide()
size = videoWidget.textSetting[6]
videoWidget.textBrowser.textBrowser.setFont(
QFont('Microsoft JhengHei', size + 5, QFont.Bold))
videoWidget.textBrowser.transBrowser.setFont(
QFont('Microsoft JhengHei', size + 5, QFont.Bold))
videoWidget.textBrowser.msgsBrowser.setFont(
QFont('Microsoft JhengHei', size + 5, QFont.Bold))
# 交换控件列表
self.videoWidgetList[fromID], self.videoWidgetList[toID] = toVideo, fromVideo
self.config['player'][toID] = fromRoomID # 记录config
self.config['player'][fromID] = toRoomID
self.dumpConfig.start()
# self.changeLayout(self.config['layout']) # 刷新layout
# 用新的方法直接交换两个窗口
fromLayout, toLayout = self.config['layout'][fromID], self.config['layout'][toID]
y, x, h, w = fromLayout
self.mainLayout.addWidget(toVideo, y, x, h, w)
y, x, h, w = toLayout
self.mainLayout.addWidget(fromVideo, y, x, h, w)
# TODO: 改崩溃了 不想改了 怎么改都没法按比例调整弹幕窗坐标
# fromVideoPos = fromVideo.mapToGlobal(fromVideo.pos()) # 保持弹幕框相对位置
# toVideoPos = toVideo.mapToGlobal(toVideo.pos())
# fromVideo.textBrowser.move(toVideoPos + QPoint(toWidth * fromVideo.deltaX, toHeight * fromVideo.deltaY))
# toVideo.textBrowser.move(fromVideoPos + QPoint(fromWidth * toVideo.deltaX, fromHeight * toVideo.deltaY))
def clearLiverPanel(self): # 清空卡片槽
reply = QMessageBox.information(
self, '清空卡片槽', '注意:是否要清空卡片槽?', QMessageBox.Yes | QMessageBox.No)
if reply == QMessageBox.Yes: # 确认用户操作
self.liverPanel.deleteAll()
def setDanmu(self):
self.dumpConfig.start()
def showAddButton(self, height):
if height < 181:
self.addButton.hide()
else:
self.addButton.show()
def setTranslator(self, info):
id, token = info # 窗口 同传显示布尔值
self.config['translator'][id] = token
self.dumpConfig.start()
def setQuality(self, info):
id, quality = info # 窗口 画质
self.config['quality'][id] = quality
self.dumpConfig.start()
def setAudioChannel(self, info):
id, audioChannel = info # 窗口 音效
self.config['audioChannel'][id] = audioChannel
self.dumpConfig.start()
def popWindow(self, info): # 悬浮窗播放
id, roomID, quality, showMax, startWithDanmu = info
logging.info("%s 进入悬浮窗模式, 弹幕?: %s" % (roomID, startWithDanmu))
self.popVideoWidgetList[id].roomID = roomID
self.popVideoWidgetList[id].quality = quality
self.popVideoWidgetList[id].resize(1280, 720)
self.popVideoWidgetList[id].show()
if startWithDanmu:
self.popVideoWidgetList[id].showDanmu()
self.popVideoWidgetList[id].textBrowser.show()
if showMax:
self.popVideoWidgetList[id].showMaximized()
self.popVideoWidgetList[id].mediaReload()
def mutedChanged(self, mutedInfo):
id, muted = mutedInfo
token = 2 if muted else 1
self.config['muted'][id] = token
# self.dumpConfig.start()
def volumeChanged(self, volumeInfo):
id, value = volumeInfo
self.config['volume'][id] = value
# self.dumpConfig.start()
def globalMediaPlay(self):
if self.globalPlayToken:
force = 1
self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
else:
force = 2
self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPause))
self.globalPlayToken = not self.globalPlayToken
for videoWidget in self.videoWidgetList:
videoWidget.mediaPlay(force, setUserPause=True)
def globalMediaReload(self):
for videoWidget in self.videoWidgetList:
if not videoWidget.isHidden():
videoWidget.mediaReload()
def globalMediaMute(self):
if self.globalMuteToken:
force = 1
self.volumeButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaVolume))
else:
force = 2
self.volumeButton.setIcon(
self.style().standardIcon(QStyle.SP_MediaVolumeMuted))
self.globalMuteToken = not self.globalMuteToken
for videoWidget in self.videoWidgetList:
videoWidget.mediaMute(force)
self.config['muted'] = [force] * 16
# self.dumpConfig.start()
def globalSetVolume(self, value):
for videoWidget in self.videoWidgetList:
videoWidget.player.audio_set_volume(
int(value * videoWidget.volumeAmplify))
videoWidget.volume = value
videoWidget.slider.setValue(value)
self.config['volume'] = [value] * 16
self.config['globalVolume'] = value
# self.dumpConfig.start()
def globalMediaStop(self):
for videoWidget in self.videoWidgetList:
videoWidget.mediaStop()
# def globalDanmuShow(self): # 已弃用
# self.globalDanmuToken = not self.globalDanmuToken
# for videoWidget in self.videoWidgetList:
# if not videoWidget.isHidden():
# videoWidget.textBrowser.show() if self.globalDanmuToken else videoWidget.textBrowser.hide()
# for danmuConfig in self.config['danmu']:
# danmuConfig[0] = self.globalDanmuToken
def setGlobalDanmuOpacity(self, value):
if value < 7:
value = 7 # 最小透明度
opacity = int(value / 101 * 256)
color = str(hex(opacity))[2:] + '000000'
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.textSetting[1] = value # 记录设置
videoWidget.textBrowser.textBrowser.setStyleSheet(
'background-color:#%s' % color)
videoWidget.textBrowser.transBrowser.setStyleSheet(
'background-color:#%s' % color)
videoWidget.textBrowser.msgsBrowser.setStyleSheet(
'background-color:#%s' % color)
def setGlobalHorizontalPercent(self, index): # 设置弹幕框水平宽度
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.textSetting[2] = index
videoWidget.horiPercent = [
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0][index] # 记录横向占比
width = videoWidget.width() * videoWidget.horiPercent
videoWidget.textBrowser.resize(
width, videoWidget.textBrowser.height())
videoWidget.textBrowser.textBrowser.verticalScrollBar().setValue(100000000)
videoWidget.textBrowser.transBrowser.verticalScrollBar().setValue(100000000)
videoWidget.textBrowser.msgsBrowser.verticalScrollBar().setValue(100000000)
def setGlobalVerticalPercent(self, index): # 设置弹幕框垂直高度
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.textSetting[3] = index
videoWidget.vertPercent = [
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0][index] # 记录纵向占比
height = videoWidget.height() * videoWidget.vertPercent
videoWidget.textBrowser.resize(
videoWidget.textBrowser.width(), height)
videoWidget.textBrowser.textBrowser.verticalScrollBar().setValue(100000000)
videoWidget.textBrowser.transBrowser.verticalScrollBar().setValue(100000000)
videoWidget.textBrowser.msgsBrowser.verticalScrollBar().setValue(100000000)
def setGlobalTranslateBrowser(self, index):
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.textSetting[4] = index
if index == 0: # 显示弹幕和同传
videoWidget.textBrowser.textBrowser.show()
videoWidget.textBrowser.transBrowser.show()
elif index == 1: # 只显示弹幕
videoWidget.textBrowser.transBrowser.hide()
videoWidget.textBrowser.textBrowser.show()
elif index == 2: # 只显示同传
videoWidget.textBrowser.textBrowser.hide()
videoWidget.textBrowser.transBrowser.show()
width = videoWidget.width() * videoWidget.horiPercent
height = videoWidget.height() * videoWidget.vertPercent
videoWidget.textBrowser.resize(width, height)
def setGlobalShowEnterRoom(self, index):
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.textSetting[7] = index
if index < 3: # 显示礼物和进入信息]
videoWidget.textBrowser.msgsBrowser.show()
elif index == 3: # 隐藏窗口
videoWidget.textBrowser.msgsBrowser.hide()
width = videoWidget.width() * videoWidget.horiPercent
height = videoWidget.height() * videoWidget.vertPercent
videoWidget.textBrowser.resize(width, height)
def setGlobalTranslateFilter(self, filterWords):
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.textSetting[5] = filterWords
videoWidget.filters = filterWords.split(' ')
def setGlobalFontSize(self, index):
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.textSetting[6] = index
videoWidget.textBrowser.textBrowser.setFont(
QFont('Microsoft JhengHei', index + 5, QFont.Bold))
videoWidget.textBrowser.transBrowser.setFont(
QFont('Microsoft JhengHei', index + 5, QFont.Bold))
videoWidget.textBrowser.msgsBrowser.setFont(
QFont('Microsoft JhengHei', index + 5, QFont.Bold))
def globalQuality(self, quality):
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
if not videoWidget.isHidden(): # 窗口没有被隐藏
videoWidget.quality = quality
videoWidget.mediaReload()
self.config['quality'] = [quality] * 16
self.dumpConfig.start()
def globalAudioChannel(self, audioChannel):
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.audioChannel = audioChannel
videoWidget.player.audio_set_channel(audioChannel)
self.config['audioChannel'] = [audioChannel] * 16
# self.dumpConfig.start()
def setDecode(self, hardwareDecodeToken):
for videoWidget in self.videoWidgetList + self.popVideoWidgetList:
videoWidget.hardwareDecode = hardwareDecodeToken
self.globalMediaReload()
self.config['hardwareDecode'] = hardwareDecodeToken
def setStartLive(self, token):
self.config['showStartLive'] = token
def openControlPanel(self):
if self.controlDock.isHidden() and self.cardDock.isHidden():
self.controlDock.show()
self.cardDock.show()
self.optionMenu.menuAction().setVisible(True)
self.versionMenu.menuAction().setVisible(True)
self.payMenu.menuAction().setVisible(True)
else:
self.controlDock.hide()
self.cardDock.hide()
self.optionMenu.menuAction().setVisible(False)
self.versionMenu.menuAction().setVisible(False)
self.payMenu.menuAction().setVisible(False)
self.controlBarLayoutToken = self.controlDock.isHidden()
def openVersion(self):
self.version.hide()
self.version.show()
def openGithub(self):
QDesktopServices.openUrl(
QUrl(r'https://github.com/zhimingshenjun/DD_Monitor'))
def openBilibili(self):
QDesktopServices.openUrl(
QUrl(r'https://www.bilibili.com/video/BV14v411s7WE'))
def openDDSubtitle(self):
QDesktopServices.openUrl(
QUrl(r'https://www.bilibili.com/video/BV1p5411b7o7'))
def openDDThanks(self):
QDesktopServices.openUrl(
QUrl(r'https://www.bilibili.com/video/BV1Di4y1L7T2'))
def openCacheSetting(self):
self.cacheSetting.hide()
self.cacheSetting.show()
def setCache(self, setting):
maxCache, savePath = setting
intergerMaxCache = int(maxCache)
if intergerMaxCache <= 0:
QMessageBox.warning(self, '大小错误', '缓存大小不能小于为0GB!', QMessageBox.Ok)
return
self.config['maxCacheSize'] = intergerMaxCache * 1024000
self.config['saveCachePath'] = savePath
self.dumpConfig.start()
QMessageBox.information(
self, '缓存设置更改', '设置成功 重启监控室后生效', QMessageBox.Ok)
def openStartWithDanmuSetting(self):
items = ('加载(推荐,默认。但可能增加网络压力,可能会被限流。)', '不加载')
defulatSelection = 0
if not self.config['startWithDanmu']:
defulatSelection = 1
selection, okPressed = QInputDialog.getItem(
self, "设置启动时是否加载弹幕", "加载选项", items, defulatSelection, False)
if okPressed:
trueDanmu = (selection == items[0])
self.config['startWithDanmu'] = trueDanmu
self.dumpConfig.start()
def openHotKey(self):
self.hotKey.hide()