forked from mvdctop/Movie_Data_Capture
-
Notifications
You must be signed in to change notification settings - Fork 225
/
AVDC_Main.py
1677 lines (1600 loc) · 85.6 KB
/
AVDC_Main.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import threading
import json
from PyQt5 import QtWidgets
from PyQt5.QtGui import QPixmap
from PyQt5.QtGui import QTextCursor, QCursor
from PyQt5.QtWidgets import QMainWindow, QTreeWidgetItem, QApplication
from PyQt5.QtCore import pyqtSignal, Qt
import sys
import time
import os.path
import requests
import shutil
import base64
import re
from aip import AipBodyAnalysis
from PIL import Image, ImageFilter
import os
from configparser import ConfigParser
from Ui.AVDC import Ui_AVDV
from Function.Function import save_config, movie_lists, get_info, getDataFromJSON, escapePath, getNumber, check_pic
from Function.getHtml import get_html, get_proxies, get_config
class MyMAinWindow(QMainWindow, Ui_AVDV):
progressBarValue = pyqtSignal(int) # 进度条信号量
def __init__(self, parent=None):
super(MyMAinWindow, self).__init__(parent)
self.Ui = Ui_AVDV() # 实例化 Ui
self.Ui.setupUi(self) # 初始化Ui
self.Init_Ui()
self.set_style()
# 初始化需要的变量
self.version = '3.964'
self.m_drag = False
self.m_DragPosition = 0
self.count_claw = 0 # 批量刮削次数
self.item_succ = self.Ui.treeWidget_number.topLevelItem(0)
self.item_fail = self.Ui.treeWidget_number.topLevelItem(1)
self.select_file_path = ''
self.json_array = {}
self.Init()
self.Load_Config()
self.show_version()
# ========================================================================打开日志文件
if self.Ui.radioButton_log_on.isChecked():
if not os.path.exists('Log'):
os.makedirs('Log')
log_name = 'Log/' + time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'
self.log_txt = open(log_name, "wb", buffering=0)
self.add_text_main('[-]Created log file: ' + log_name)
self.add_text_main("[*]======================================================")
def Init_Ui(self):
ico_path = ''
if os.path.exists('AVDC-ico.png'):
ico_path = 'AVDC-ico.png'
elif os.path.exists('Img/AVDC-ico.png'):
ico_path = 'Img/AVDC-ico.png'
pix = QPixmap(ico_path)
self.Ui.label_ico.setScaledContents(True)
self.Ui.label_ico.setPixmap(pix) # 添加图标
self.Ui.progressBar_avdc.setValue(0) # 进度条清0
self.progressBarValue.connect(self.set_processbar)
self.Ui.progressBar_avdc.setTextVisible(False) # 不显示进度条文字
self.setWindowFlag(Qt.FramelessWindowHint) # 隐藏边框
# self.setWindowOpacity(0.9) # 设置窗口透明度
self.setAttribute(Qt.WA_TranslucentBackground) # 设置窗口背景透明
self.Ui.treeWidget_number.expandAll()
def set_style(self):
# 控件美化
self.Ui.widget_setting.setStyleSheet(
'''
QWidget#widget_setting{
background:#F0F8FF;
border-radius:20px;
padding:2px 4px;
}
QPushButton{
font-size:15px;
background:gray;
border:9px solid gray;
border-radius:15px;
padding:2px 4px;
}
''')
self.Ui.centralwidget.setStyleSheet(
'''
* {
font-size:15px;
}
QWidget#centralwidget{
background:gray;
border:1px solid gray;
width:300px;
border-radius:20px;
padding:2px 4px;
}
QTextBrowser{
border:1px solid gray;
background:white;
width:300px;
border-radius:10px;
padding:2px 4px;
}
QLineEdit{
background:white;
border:1px solid gray;
width:300px;
border-radius:10px;
padding:2px 4px;
}
QTextBrowser#textBrowser_about{
background:white;
border:1px solid white;
width:300px;
border-radius:10px;
padding:2px 4px;
}
QTextBrowser#textBrowser_warning{
background:gray;
border:1px solid gray;
width:300px;
border-radius:10px;
padding:2px 4px;
}
QPushButton#pushButton_start_cap,#pushButton_move_mp4,#pushButton_select_file,#pushButton_select_thumb{
font-size:20px;
background:#F0F8FF;
border:2px solid white;
width:300px;
border-radius:20px;
padding:2px 4px;
}
QPushButton#pushButton_add_actor_pic,#pushButton_start_single_file{
font-size:20px;
background:#F0F8FF;
border:2px solid white;
width:300px;
border-radius:20px;
padding:2px 4px;
}
QPushButton#pushButton_save_config,#pushButton_show_pic_actor,#pushButton_init_config{
background:#F0F8FF;
border:2px solid white;
width:300px;
border-radius:13px;
padding:2px 4px;
}
QProgressBar::chunk{
background-color: #2196F3;
width: 5px; /*区块宽度*/
margin: 0.5px;
}
''')
# ========================================================================按钮点击事件
def Init(self):
self.Ui.stackedWidget.setCurrentIndex(0)
self.Ui.treeWidget_number.clicked.connect(self.treeWidget_number_clicked)
self.Ui.pushButton_close.clicked.connect(self.close_win)
self.Ui.pushButton_min.clicked.connect(self.min_win)
self.Ui.pushButton_main.clicked.connect(self.pushButton_main_clicked)
self.Ui.pushButton_tool.clicked.connect(self.pushButton_tool_clicked)
self.Ui.pushButton_setting.clicked.connect(self.pushButton_setting_clicked)
self.Ui.pushButton_select_file.clicked.connect(self.pushButton_select_file_clicked)
self.Ui.pushButton_about.clicked.connect(self.pushButton_about_clicked)
self.Ui.pushButton_start_cap.clicked.connect(self.pushButton_start_cap_clicked)
self.Ui.pushButton_save_config.clicked.connect(self.pushButton_save_config_clicked)
self.Ui.pushButton_init_config.clicked.connect(self.pushButton_init_config_clicked)
self.Ui.pushButton_move_mp4.clicked.connect(self.move_file)
self.Ui.pushButton_add_actor_pic.clicked.connect(self.pushButton_add_actor_pic_clicked)
self.Ui.pushButton_show_pic_actor.clicked.connect(self.pushButton_show_pic_actor_clicked)
self.Ui.pushButton_select_thumb.clicked.connect(self.pushButton_select_thumb_clicked)
self.Ui.pushButton_log.clicked.connect(self.pushButton_show_log_clicked)
self.Ui.pushButton_start_single_file.clicked.connect(self.pushButton_start_single_file_clicked)
self.Ui.checkBox_cover.stateChanged.connect(self.cover_change)
self.Ui.horizontalSlider_timeout.valueChanged.connect(self.lcdNumber_timeout_change)
self.Ui.horizontalSlider_retry.valueChanged.connect(self.lcdNumber_retry_change)
self.Ui.horizontalSlider_mark_size.valueChanged.connect(self.lcdNumber_mark_size_change)
# ========================================================================显示版本号
def show_version(self):
self.Ui.textBrowser_log_main.append('[*]======================== AVDC ========================')
self.Ui.textBrowser_log_main.append('[*] Version ' + self.version)
self.Ui.textBrowser_log_main.append('[*]======================================================')
# ========================================================================鼠标拖动窗口
def mousePressEvent(self, e):
if e.button() == Qt.LeftButton:
self.m_drag = True
self.m_DragPosition = e.globalPos() - self.pos()
self.setCursor(QCursor(Qt.OpenHandCursor)) # 按下左键改变鼠标指针样式为手掌
def mouseReleaseEvent(self, e):
if e.button() == Qt.LeftButton:
self.m_drag = False
self.setCursor(QCursor(Qt.ArrowCursor)) # 释放左键改变鼠标指针样式为箭头
def mouseMoveEvent(self, e):
if Qt.LeftButton and self.m_drag:
self.move(e.globalPos() - self.m_DragPosition)
e.accept()
# ========================================================================左侧按钮点击事件响应函数
def close_win(self):
os._exit(0)
def min_win(self):
self.setWindowState(Qt.WindowMinimized)
def pushButton_main_clicked(self):
self.Ui.stackedWidget.setCurrentIndex(0)
def pushButton_tool_clicked(self):
self.Ui.stackedWidget.setCurrentIndex(1)
def pushButton_setting_clicked(self):
self.Ui.stackedWidget.setCurrentIndex(2)
def pushButton_about_clicked(self):
self.Ui.stackedWidget.setCurrentIndex(3)
def pushButton_show_log_clicked(self):
self.Ui.stackedWidget.setCurrentIndex(4)
def lcdNumber_timeout_change(self):
timeout = self.Ui.horizontalSlider_timeout.value()
self.Ui.lcdNumber_timeout.display(timeout)
def lcdNumber_retry_change(self):
retry = self.Ui.horizontalSlider_retry.value()
self.Ui.lcdNumber_retry.display(retry)
def lcdNumber_mark_size_change(self):
mark_size = self.Ui.horizontalSlider_mark_size.value()
self.Ui.lcdNumber_mark_size.display(mark_size)
def cover_change(self):
if not self.Ui.checkBox_cover.isChecked():
self.Ui.label_poster.setText("封面图")
self.Ui.label_thumb.setText("缩略图")
def treeWidget_number_clicked(self, qmodeLindex):
item = self.Ui.treeWidget_number.currentItem()
if item.text(0) != '成功' and item.text(0) != '失败':
try:
index_json = str(item.text(0)).split('.')[0]
self.add_label_info(self.json_array[str(index_json)])
except:
print(item.text(0) + ': No info!')
def pushButton_start_cap_clicked(self):
self.Ui.pushButton_start_cap.setEnabled(False)
self.progressBarValue.emit(int(0))
try:
self.count_claw += 1
t = threading.Thread(target=self.AVDC_Main)
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_start_cap_clicked: ' + str(error_info))
# ========================================================================恢复默认config.ini
def pushButton_init_config_clicked(self):
try:
t = threading.Thread(target=self.init_config_clicked)
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_save_config_clicked: ' + str(error_info))
def init_config_clicked(self):
json_config = {
'show_poster': 1,
'main_mode': 1,
'soft_link': 0,
'switch_debug': 1,
'failed_file_move': 1,
'update_check': 1,
'save_log': 1,
'website': 'all',
'failed_output_folder': 'failed',
'success_output_folder': 'JAV_output',
'proxy': '',
'timeout': 7,
'retry': 3,
'folder_name': 'actor/number-title-release',
'naming_media': 'number-title',
'naming_file': 'number',
'literals': '\()',
'folders': 'failed,JAV_output',
'string': '1080p,720p,22-sht.me,-HD',
'emby_url': 'localhost:8096',
'api_key': '',
'media_path': 'E:/TEMP',
'media_type': '.mp4|.avi|.rmvb|.wmv|.mov|.mkv|.flv|.ts|.webm|.MP4|.AVI|.RMVB|.WMV|.MOV|.MKV|.FLV|.TS|.WEBM',
'sub_type': '.smi|.srt|.idx|.sub|.sup|.psb|.ssa|.ass|.txt|.usf|.xss|.ssf|.rt|.lrc|.sbv|.vtt|.ttml',
'poster_mark': 1,
'thumb_mark': 1,
'mark_size': 3,
'mark_type': 'SUB,LEAK,UNCENSORED',
'mark_pos': 'top_left',
'uncensored_poster': 0,
'uncensored_prefix': 'S2M|BT|LAF|SMD',
'nfo_download': 1,
'poster_download': 1,
'fanart_download': 1,
'thumb_download': 1,
'extrafanart_download': 0,
'extrafanart_folder': 'extrafanart',
}
save_config(json_config)
self.Load_Config()
# ========================================================================加载config
def Load_Config(self):
config_file = 'config.ini'
config = ConfigParser()
config.read(config_file, encoding='UTF-8')
# ========================================================================common
if int(config['common']['main_mode']) == 1:
self.Ui.radioButton_common.setChecked(True)
elif int(config['common']['main_mode']) == 2:
self.Ui.radioButton_sort.setChecked(True)
if int(config['common']['soft_link']) == 1:
self.Ui.radioButton_soft_on.setChecked(True)
elif int(config['common']['soft_link']) == 0:
self.Ui.radioButton_soft_off.setChecked(True)
if int(config['common']['failed_file_move']) == 1:
self.Ui.radioButton_fail_move_on.setChecked(True)
elif int(config['common']['failed_file_move']) == 0:
self.Ui.radioButton_fail_move_off.setChecked(True)
if int(config['common']['show_poster']) == 1:
self.Ui.checkBox_cover.setChecked(True)
elif int(config['common']['show_poster']) == 0:
self.Ui.checkBox_cover.setChecked(False)
if config['common']['website'] == 'all':
self.Ui.comboBox_website_all.setCurrentIndex(0)
elif config['common']['website'] == 'mgstage':
self.Ui.comboBox_website_all.setCurrentIndex(1)
elif config['common']['website'] == 'javbus':
self.Ui.comboBox_website_all.setCurrentIndex(2)
elif config['common']['website'] == 'jav321':
self.Ui.comboBox_website_all.setCurrentIndex(3)
elif config['common']['website'] == 'javdb':
self.Ui.comboBox_website_all.setCurrentIndex(4)
elif config['common']['website'] == 'avsox':
self.Ui.comboBox_website_all.setCurrentIndex(5)
elif config['common']['website'] == 'xcity':
self.Ui.comboBox_website_all.setCurrentIndex(6)
elif config['common']['website'] == 'dmm':
self.Ui.comboBox_website_all.setCurrentIndex(7)
self.Ui.lineEdit_success.setText(config['common']['success_output_folder'])
self.Ui.lineEdit_fail.setText(config['common']['failed_output_folder'])
# ========================================================================proxy
if config['proxy']['type'] == 'no' or config['proxy']['type'] == '':
self.Ui.radioButton_proxy_nouse.setChecked(True)
elif config['proxy']['type'] == 'http':
self.Ui.radioButton_proxy_http.setChecked(True)
elif config['proxy']['type'] == 'socks5':
self.Ui.radioButton_proxy_socks5.setChecked(True)
self.Ui.lineEdit_proxy.setText(config['proxy']['proxy'])
self.Ui.horizontalSlider_timeout.setValue(int(config['proxy']['timeout']))
self.Ui.horizontalSlider_retry.setValue(int(config['proxy']['retry']))
# ========================================================================Name_Rule
self.Ui.lineEdit_dir_name.setText(config['Name_Rule']['folder_name'])
self.Ui.lineEdit_media_name.setText(config['Name_Rule']['naming_media'])
self.Ui.lineEdit_local_name.setText(config['Name_Rule']['naming_file'])
# ========================================================================update
if int(config['update']['update_check']) == 1:
self.Ui.radioButton_update_on.setChecked(True)
elif int(config['update']['update_check']) == 0:
self.Ui.radioButton_update_off.setChecked(True)
# ========================================================================log
if int(config['log']['save_log']) == 1:
self.Ui.radioButton_log_on.setChecked(True)
elif int(config['log']['save_log']) == 0:
self.Ui.radioButton_log_off.setChecked(True)
# ========================================================================media
self.Ui.lineEdit_movie_type.setText(config['media']['media_type'])
self.Ui.lineEdit_sub_type.setText(config['media']['sub_type'])
self.Ui.lineEdit_movie_path.setText(str(config['media']['media_path']).replace('\\', '/'))
# ========================================================================escape
self.Ui.lineEdit_escape_dir.setText(config['escape']['folders'])
self.Ui.lineEdit_escape_char.setText(config['escape']['literals'])
self.Ui.lineEdit_escape_dir_move.setText(config['escape']['folders'])
self.Ui.lineEdit_escape_string.setText(config['escape']['string'])
# ========================================================================debug_mode
if int(config['debug_mode']['switch']) == 1:
self.Ui.radioButton_debug_on.setChecked(True)
elif int(config['debug_mode']['switch']) == 0:
self.Ui.radioButton_debug_off.setChecked(True)
# ========================================================================emby
self.Ui.lineEdit_emby_url.setText(config['emby']['emby_url'])
self.Ui.lineEdit_api_key.setText(config['emby']['api_key'])
# ========================================================================mark
if int(config['mark']['poster_mark']) == 1:
self.Ui.radioButton_poster_mark_on.setChecked(True)
elif int(config['mark']['poster_mark']) == 0:
self.Ui.radioButton_poster_mark_off.setChecked(True)
if int(config['mark']['thumb_mark']) == 1:
self.Ui.radioButton_thumb_mark_on.setChecked(True)
elif int(config['mark']['thumb_mark']) == 0:
self.Ui.radioButton_thumb_mark_off.setChecked(True)
self.Ui.horizontalSlider_mark_size.setValue(int(config['mark']['mark_size']))
if 'SUB' in str(config['mark']['mark_type']).upper():
self.Ui.checkBox_sub.setChecked(True)
if 'LEAK' in str(config['mark']['mark_type']).upper():
self.Ui.checkBox_leak.setChecked(True)
if 'UNCENSORED' in str(config['mark']['mark_type']).upper():
self.Ui.checkBox_uncensored.setChecked(True)
if 'top_left' == config['mark']['mark_pos']:
self.Ui.radioButton_top_left.setChecked(True)
elif 'bottom_left' == config['mark']['mark_pos']:
self.Ui.radioButton_bottom_left.setChecked(True)
elif 'top_right' == config['mark']['mark_pos']:
self.Ui.radioButton_top_right.setChecked(True)
elif 'bottom_right' == config['mark']['mark_pos']:
self.Ui.radioButton_bottom_right.setChecked(True)
# ========================================================================uncensored
if int(config['uncensored']['uncensored_poster']) == 1:
self.Ui.radioButton_poster_cut.setChecked(True)
elif int(config['uncensored']['uncensored_poster']) == 0:
self.Ui.radioButton_poster_official.setChecked(True)
self.Ui.lineEdit_uncensored_prefix.setText(config['uncensored']['uncensored_prefix'])
# ========================================================================file_download
if int(config['file_download']['nfo']) == 1:
self.Ui.checkBox_download_nfo.setChecked(True)
elif int(config['file_download']['nfo']) == 0:
self.Ui.checkBox_download_nfo.setChecked(False)
if int(config['file_download']['poster']) == 1:
self.Ui.checkBox_download_poster.setChecked(True)
elif int(config['file_download']['poster']) == 0:
self.Ui.checkBox_download_poster.setChecked(False)
if int(config['file_download']['fanart']) == 1:
self.Ui.checkBox_download_fanart.setChecked(True)
elif int(config['file_download']['fanart']) == 0:
self.Ui.checkBox_download_fanart.setChecked(False)
if int(config['file_download']['thumb']) == 1:
self.Ui.checkBox_download_thumb.setChecked(True)
elif int(config['file_download']['thumb']) == 0:
self.Ui.checkBox_download_thumb.setChecked(False)
# ========================================================================extrafanart
if int(config['extrafanart']['extrafanart_download']) == 1:
self.Ui.radioButton_extrafanart_download_on.setChecked(True)
elif int(config['extrafanart']['extrafanart_download']) == 0:
self.Ui.radioButton_extrafanart_download_off.setChecked(True)
self.Ui.lineEdit_extrafanart_dir.setText(config['extrafanart']['extrafanart_folder'])
# ========================================================================读取设置页设置,保存在config.ini
def pushButton_save_config_clicked(self):
try:
t = threading.Thread(target=self.save_config_clicked)
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_save_config_clicked: ' + str(error_info))
def save_config_clicked(self):
main_mode = 1
failed_file_move = 1
soft_link = 0
show_poster = 0
switch_debug = 0
update_check = 0
save_log = 0
website = ''
add_mark = 1
mark_size = 3
mark_type = ''
mark_pos = ''
uncensored_poster = 0
nfo_download = 0
poster_download = 0
fanart_download = 0
thumb_download = 0
extrafanart_download = 0
extrafanart_folder = ''
proxy_type = ''
# ========================================================================common
if self.Ui.radioButton_common.isChecked(): # 普通模式
main_mode = 1
elif self.Ui.radioButton_sort.isChecked(): # 整理模式
main_mode = 2
if self.Ui.radioButton_soft_on.isChecked(): # 软链接开
soft_link = 1
elif self.Ui.radioButton_soft_off.isChecked(): # 软链接关
soft_link = 0
if self.Ui.radioButton_debug_on.isChecked(): # 调试模式开
switch_debug = 1
elif self.Ui.radioButton_debug_off.isChecked(): # 调试模式关
switch_debug = 0
if self.Ui.radioButton_update_on.isChecked(): # 检查更新
update_check = 1
elif self.Ui.radioButton_update_off.isChecked(): # 不检查更新
update_check = 0
if self.Ui.radioButton_log_on.isChecked(): # 开启日志
save_log = 1
elif self.Ui.radioButton_log_off.isChecked(): # 关闭日志
save_log = 0
if self.Ui.checkBox_cover.isChecked(): # 显示封面
show_poster = 1
else: # 关闭封面
show_poster = 0
if self.Ui.radioButton_fail_move_on.isChecked(): # 失败移动开
failed_file_move = 1
elif self.Ui.radioButton_fail_move_off.isChecked(): # 失败移动关
failed_file_move = 0
if self.Ui.comboBox_website_all.currentText() == 'All websites': # all
website = 'all'
elif self.Ui.comboBox_website_all.currentText() == 'mgstage': # mgstage
website = 'mgstage'
elif self.Ui.comboBox_website_all.currentText() == 'javbus': # javbus
website = 'javbus'
elif self.Ui.comboBox_website_all.currentText() == 'jav321': # jav321
website = 'jav321'
elif self.Ui.comboBox_website_all.currentText() == 'javdb': # javdb
website = 'javdb'
elif self.Ui.comboBox_website_all.currentText() == 'avsox': # avsox
website = 'avsox'
elif self.Ui.comboBox_website_all.currentText() == 'xcity': # xcity
website = 'xcity'
elif self.Ui.comboBox_website_all.currentText() == 'dmm': # dmm
website = 'dmm'
# ========================================================================proxy
if self.Ui.radioButton_proxy_http.isChecked(): # http proxy
proxy_type = 'http'
elif self.Ui.radioButton_proxy_socks5.isChecked(): # socks5 proxy
proxy_type = 'socks5'
elif self.Ui.radioButton_proxy_nouse.isChecked(): # nouse proxy
proxy_type = 'no'
# ========================================================================水印
if self.Ui.radioButton_poster_mark_on.isChecked(): # 封面添加水印
poster_mark = 1
else: # 关闭封面添加水印
poster_mark = 0
if self.Ui.radioButton_thumb_mark_on.isChecked(): # 缩略图添加水印
thumb_mark = 1
else: # 关闭缩略图添加水印
thumb_mark = 0
if self.Ui.checkBox_sub.isChecked(): # 字幕
mark_type += ',SUB'
if self.Ui.checkBox_leak.isChecked(): # 流出
mark_type += ',LEAK'
if self.Ui.checkBox_uncensored.isChecked(): # 无码
mark_type += ',UNCENSORED'
if self.Ui.radioButton_top_left.isChecked(): # 左上
mark_pos = 'top_left'
elif self.Ui.radioButton_bottom_left.isChecked(): # 左下
mark_pos = 'bottom_left'
elif self.Ui.radioButton_top_right.isChecked(): # 右上
mark_pos = 'top_right'
elif self.Ui.radioButton_bottom_right.isChecked(): # 右下
mark_pos = 'bottom_right'
if self.Ui.radioButton_poster_official.isChecked(): # 官方
uncensored_poster = 0
elif self.Ui.radioButton_poster_cut.isChecked(): # 裁剪
uncensored_poster = 1
# ========================================================================下载文件,剧照
if self.Ui.checkBox_download_nfo.isChecked():
nfo_download = 1
else:
nfo_download = 0
if self.Ui.checkBox_download_poster.isChecked():
poster_download = 1
else:
poster_download = 0
if self.Ui.checkBox_download_fanart.isChecked():
fanart_download = 1
else:
fanart_download = 0
if self.Ui.checkBox_download_thumb.isChecked():
thumb_download = 1
else:
thumb_download = 0
if self.Ui.radioButton_extrafanart_download_on.isChecked(): # 下载剧照
extrafanart_download = 1
else: # 关闭封面
extrafanart_download = 0
json_config = {
'main_mode': main_mode,
'soft_link': soft_link,
'switch_debug': switch_debug,
'show_poster': show_poster,
'failed_file_move': failed_file_move,
'update_check': update_check,
'save_log': save_log,
'website': website,
'failed_output_folder': self.Ui.lineEdit_fail.text(),
'success_output_folder': self.Ui.lineEdit_success.text(),
'type': proxy_type,
'proxy': self.Ui.lineEdit_proxy.text(),
'timeout': self.Ui.horizontalSlider_timeout.value(),
'retry': self.Ui.horizontalSlider_retry.value(),
'folder_name': self.Ui.lineEdit_dir_name.text(),
'naming_media': self.Ui.lineEdit_media_name.text(),
'naming_file': self.Ui.lineEdit_local_name.text(),
'literals': self.Ui.lineEdit_escape_char.text(),
'folders': self.Ui.lineEdit_escape_dir.text(),
'string': self.Ui.lineEdit_escape_string.text(),
'emby_url': self.Ui.lineEdit_emby_url.text(),
'api_key': self.Ui.lineEdit_api_key.text(),
'media_path': self.Ui.lineEdit_movie_path.text(),
'media_type': self.Ui.lineEdit_movie_type.text(),
'sub_type': self.Ui.lineEdit_sub_type.text(),
'poster_mark': poster_mark,
'thumb_mark': thumb_mark,
'mark_size': self.Ui.horizontalSlider_mark_size.value(),
'mark_type': mark_type.strip(','),
'mark_pos': mark_pos,
'uncensored_poster': uncensored_poster,
'uncensored_prefix': self.Ui.lineEdit_uncensored_prefix.text(),
'nfo_download': nfo_download,
'poster_download': poster_download,
'fanart_download': fanart_download,
'thumb_download': thumb_download,
'extrafanart_download': extrafanart_download,
'extrafanart_folder': self.Ui.lineEdit_extrafanart_dir.text(),
}
save_config(json_config)
# ========================================================================小工具-单视频刮削
def pushButton_select_file_clicked(self):
path = self.Ui.lineEdit_movie_path.text()
filepath, filetype = QtWidgets.QFileDialog.getOpenFileName(self, "选取视频文件", path, "Movie Files(*.mp4 "
"*.avi *.rmvb *.wmv "
"*.mov *.mkv *.flv *.ts "
"*.webm *.MP4 *.AVI "
"*.RMVB *.WMV *.MOV "
"*.MKV *.FLV *.TS "
"*.WEBM);;All Files(*)")
self.select_file_path = filepath
def pushButton_start_single_file_clicked(self):
if self.select_file_path != '':
self.Ui.stackedWidget.setCurrentIndex(0)
try:
t = threading.Thread(target=self.select_file_thread)
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_start_single_file_clicked: ' + str(error_info))
def select_file_thread(self):
file_name = self.select_file_path
file_root = os.getcwd().replace("\\\\", "/").replace("\\", "/")
file_path = file_name.replace(file_root, '.').replace("\\\\", "/").replace("\\", "/")
# 获取去掉拓展名的文件名做为番号
file_name = os.path.splitext(file_name.split('/')[-1])[0]
mode = self.Ui.comboBox_website.currentIndex() + 1
# 指定的网址
appoint_url = self.Ui.lineEdit_appoint_url.text()
appoint_number = self.Ui.lineEdit_movie_number.text()
try:
if appoint_number:
file_name = appoint_number
else:
if '-CD' in file_name or '-cd' in file_name:
part = ''
if re.search('-CD\d+', file_name):
part = re.findall('-CD\d+', file_name)[0]
elif re.search('-cd\d+', file_name):
part = re.findall('-cd\d+', file_name)[0]
file_name = file_name.replace(part, '')
if '-c.' in file_path or '-C.' in file_path:
file_name = file_name[0:-2]
self.add_text_main("[!]Making Data for [" + file_path + "], the number is [" + file_name + "]")
self.Core_Main(file_path, file_name, mode, 0, appoint_url)
except Exception as error_info:
self.add_text_main('[-]Error in select_file_thread: ' + str(error_info))
self.add_text_main("[*]======================================================")
# ========================================================================小工具-裁剪封面图
def pushButton_select_thumb_clicked(self):
path = self.Ui.lineEdit_movie_path.text()
filePath, fileType = QtWidgets.QFileDialog.getOpenFileName(self, "选取缩略图", path,
"Picture Files(*.jpg);;All Files(*)")
if filePath != '':
self.Ui.stackedWidget.setCurrentIndex(0)
try:
t = threading.Thread(target=self.select_thumb_thread, args=(filePath,))
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_select_thumb_clicked: ' + str(error_info))
def select_thumb_thread(self, file_path):
file_name = file_path.split('/')[-1]
file_path = file_path.replace('/' + file_name, '')
self.image_cut(file_path, file_name, 2)
self.add_text_main("[*]======================================================")
def image_cut(self, path, file_name, mode=1):
png_name = file_name.replace('-thumb.jpg', '-poster.jpg')
file_path = os.path.join(path, file_name)
png_path = os.path.join(path, png_name)
try:
if os.path.exists(png_path):
os.remove(png_path)
except Exception as error_info:
self.add_text_main('[-]Error in image_cut: ' + str(error_info))
return
""" 你的 APPID AK SK """
APP_ID = '17013175'
API_KEY = 'IQs1mkG4FerdtmNh6qKDI4fW'
SECRET_KEY = 'dLr9GTqqutqP9nWKKRaEinVDhxYlPbnD'
client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY)
""" 获取图片分辨率 """
im = Image.open(file_path) # 返回一个Image对象
width, height = im.size
""" 读取图片 """
with open(file_path, 'rb') as fp:
image = fp.read()
ex, ey, ew, eh = 0, 0, 0, 0
""" 获取裁剪区域 """
if height / width <= 1.5: # 长宽比大于1.5,太宽
""" 调用人体检测与属性识别 """
result = client.bodyAnalysis(image)
ewidth = int(height / 1.5)
ex = int(result["person_info"][0]['body_parts']['nose']['x'])
if width - ex < ewidth / 2:
ex = width - ewidth
else:
ex -= int(ewidth / 2)
if ex < 0:
ex = 0
ey = 0
eh = height
if ewidth > width:
ew = width
else:
ew = ewidth
elif height / width > 1.5: # 长宽比小于1.5,太窄
ex = 0
ey = 0
ew = int(width)
eh = ew * 1.5
fp = open(file_path, 'rb')
img = Image.open(fp)
img_new_png = img.crop((ex, ey, ew + ex, eh + ey))
fp.close()
img_new_png.save(png_path)
self.add_text_main('[+]Poster Cut ' + png_name + ' from ' + file_name + '!')
if mode == 2:
pix = QPixmap(file_path)
self.Ui.label_thumb.setScaledContents(True)
self.Ui.label_thumb.setPixmap(pix) # 添加图标
pix = QPixmap(png_path)
self.Ui.label_poster.setScaledContents(True)
self.Ui.label_poster.setPixmap(pix) # 添加图标
# ========================================================================小工具-视频移动
def move_file(self):
self.Ui.stackedWidget.setCurrentIndex(4)
try:
t = threading.Thread(target=self.move_file_thread)
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in move_file: ' + str(error_info))
def move_file_thread(self):
escape_dir = self.Ui.lineEdit_escape_dir_move.text()
sub_type = self.Ui.lineEdit_sub_type.text().split('|')
movie_path = self.Ui.lineEdit_movie_path.text()
movie_type = self.Ui.lineEdit_movie_type.text()
movie_list = movie_lists(escape_dir, movie_type, movie_path)
des_path = movie_path + '/Movie_moved'
if not os.path.exists(des_path):
self.add_text_main('[+]Created folder Movie_moved!')
os.makedirs(des_path)
self.add_text_main('[+]Move Movies Start!')
for movie in movie_list:
if des_path in movie:
continue
sour = movie
des = des_path + '/' + sour.split('/')[-1]
try:
shutil.move(sour, des)
self.add_text_main(' [+]Move ' + sour.split('/')[-1] + ' to Movie_moved Success!')
path_old = sour.replace(sour.split('/')[-1], '')
filename = sour.split('/')[-1].split('.')[0]
for sub in sub_type:
if os.path.exists(path_old + '/' + filename + sub): # 字幕移动
shutil.move(path_old + '/' + filename + sub, des_path + '/' + filename + sub)
self.add_text_main(' [+]Sub moved! ' + filename + sub)
except Exception as error_info:
self.add_text_main('[-]Error in move_file_thread: ' + str(error_info))
self.add_text_main("[+]Move Movies All Finished!!!")
self.add_text_main("[*]======================================================")
# ========================================================================小工具-emby女优头像
def pushButton_add_actor_pic_clicked(self): # 添加头像按钮响应
self.Ui.stackedWidget.setCurrentIndex(4)
emby_url = self.Ui.lineEdit_emby_url.text()
api_key = self.Ui.lineEdit_api_key.text()
if emby_url == '':
self.add_text_main('[-]The emby_url is empty!')
self.add_text_main("[*]======================================================")
return
elif api_key == '':
self.add_text_main('[-]The api_key is empty!')
self.add_text_main("[*]======================================================")
return
try:
t = threading.Thread(target=self.found_profile_picture, args=(1,))
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_add_actor_pic_clicked: ' + str(error_info))
def pushButton_show_pic_actor_clicked(self): # 查看按钮响应
self.Ui.stackedWidget.setCurrentIndex(4)
emby_url = self.Ui.lineEdit_emby_url.text()
api_key = self.Ui.lineEdit_api_key.text()
if emby_url == '':
self.add_text_main('[-]The emby_url is empty!')
self.add_text_main("[*]======================================================")
return
elif api_key == '':
self.add_text_main('[-]The api_key is empty!')
self.add_text_main("[*]======================================================")
return
if self.Ui.comboBox_pic_actor.currentIndex() == 0: # 可添加头像的女优
try:
t = threading.Thread(target=self.found_profile_picture, args=(2,))
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_show_pic_actor_clicked: ' + str(error_info))
else:
try:
t = threading.Thread(target=self.show_actor, args=(self.Ui.comboBox_pic_actor.currentIndex(),))
t.start() # 启动线程,即让线程开始执行
except Exception as error_info:
self.add_text_main('[-]Error in pushButton_show_pic_actor_clicked: ' + str(error_info))
def show_actor(self, mode): # 按模式显示相应列表
if mode == 1: # 没有头像的女优
self.add_text_main('[+]没有头像的女优!')
elif mode == 2: # 有头像的女优
self.add_text_main('[+]有头像的女优!')
elif mode == 3: # 所有女优
self.add_text_main('[+]所有女优!')
actor_list = self.get_emby_actor_list()
if actor_list['TotalRecordCount'] == 0:
self.add_text_main("[*]======================================================")
return
count = 1
actor_list_temp = ''
for actor in actor_list['Items']:
if mode == 3: # 所有女优
actor_list_temp += str(count) + '.' + actor['Name'] + ','
count += 1
elif mode == 2 and actor['ImageTags'] != {}: # 有头像的女优
actor_list_temp += str(count) + '.' + actor['Name'] + ','
count += 1
elif mode == 1 and actor['ImageTags'] == {}: # 没有头像的女优
actor_list_temp += str(count) + '.' + actor['Name'] + ','
count += 1
if (count - 1) % 5 == 0 and actor_list_temp != '':
self.add_text_main('[+]' + actor_list_temp)
actor_list_temp = ''
self.add_text_main("[*]======================================================")
def get_emby_actor_list(self): # 获取emby的演员列表
emby_url = self.Ui.lineEdit_emby_url.text()
api_key = self.Ui.lineEdit_api_key.text()
emby_url = emby_url.replace(':', ':')
url = 'http://' + emby_url + '/emby/Persons?api_key=' + api_key
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/60.0.3100.0 Safari/537.36'}
actor_list = {}
try:
getweb = requests.get(str(url), headers=headers, timeout=10)
getweb.encoding = 'utf-8'
actor_list = json.loads(getweb.text)
except:
self.add_text_main('[-]Error! Check your emby_url or api_key!')
actor_list['TotalRecordCount'] = 0
return actor_list
def found_profile_picture(self, mode): # mode=1,上传头像,mode=2,显示可添加头像的女优
if mode == 1:
self.add_text_main('[+]Start upload profile pictures!')
elif mode == 2:
self.add_text_main('[+]可添加头像的女优!')
path = 'Actor'
if not os.path.exists(path):
self.add_text_main('[+]Actor folder not exist!')
self.add_text_main("[*]======================================================")
return
path_success = 'Actor/Success'
if not os.path.exists(path_success):
os.makedirs(path_success)
profile_pictures = os.listdir(path)
actor_list = self.get_emby_actor_list()
if actor_list['TotalRecordCount'] == 0:
self.add_text_main("[*]======================================================")
return
count = 1
for actor in actor_list['Items']:
flag = 0
pic_name = ''
if actor['Name'] + '.jpg' in profile_pictures:
flag = 1
pic_name = actor['Name'] + '.jpg'
elif actor['Name'] + '.png' in profile_pictures:
flag = 1
pic_name = actor['Name'] + '.png'
if flag == 0:
byname_list = re.split('[,,()()]', actor['Name'])
for byname in byname_list:
if byname + '.jpg' in profile_pictures:
pic_name = byname + '.jpg'
flag = 1
break
elif byname + '.png' in profile_pictures:
pic_name = byname + '.png'
flag = 1
break
if flag == 1 and (actor['ImageTags'] == {} or not os.path.exists(path_success + '/' + pic_name)):
if mode == 1:
try:
self.upload_profile_picture(count, actor, path + '/' + pic_name)
shutil.copy(path + '/' + pic_name, path_success + '/' + pic_name)
except Exception as error_info:
self.add_text_main('[-]Error in found_profile_picture! ' + str(error_info))
else:
self.add_text_main('[+]' + "%4s" % str(count) + '.Actor name: ' + actor['Name'] + ' Pic name: '
+ pic_name)
count += 1
if count == 1:
self.add_text_main('[-]NO profile picture can be uploaded!')
self.add_text_main("[*]======================================================")
def upload_profile_picture(self, count, actor, pic_path): # 上传头像
emby_url = self.Ui.lineEdit_emby_url.text()
api_key = self.Ui.lineEdit_api_key.text()
emby_url = emby_url.replace(':', ':')
try:
f = open(pic_path, 'rb') # 二进制方式打开图文件
b6_pic = base64.b64encode(f.read()) # 读取文件内容,转换为base64编码
f.close()
url = 'http://' + emby_url + '/emby/Items/' + actor['Id'] + '/Images/Primary?api_key=' + api_key
if pic_path.endswith('jpg'):
header = {"Content-Type": 'image/png', }
else:
header = {"Content-Type": 'image/jpeg', }
requests.post(url=url, data=b6_pic, headers=header)
self.add_text_main(
'[+]' + "%4s" % str(count) + '.Success upload profile picture for ' + actor['Name'] + '!')
except Exception as error_info:
self.add_text_main('[-]Error in upload_profile_picture! ' + str(error_info))
# ========================================================================自定义文件名
def get_naming_rule(self, json_data):
title, studio, publisher, year, outline, runtime, director, actor_photo, actor, release, tag, number, cover, website, series = get_info(
json_data)
if len(actor.split(',')) >= 10: # 演员过多取前五个
actor = actor.split(',')[0] + ',' + actor.split(',')[1] + ',' + actor.split(',')[2] + '等演员'
name_file = json_data['naming_file'].replace('title', title).replace('studio', studio).replace('year',
year).replace(
'runtime',
runtime).replace(
'director', director).replace('actor', actor).replace('release', release).replace('number', number).replace(
'series', series).replace('publisher', publisher)
name_file = name_file.replace('//', '/').replace('--', '-').strip('-')
if len(name_file) > 100: # 文件名过长 取标题前70个字符
self.add_text_main('[-]Error in Length of Path! Cut title!')
name_file = name_file.replace(title, title[0:70])
return name_file
# ========================================================================语句添加到日志框
def add_text_main(self, text):
try:
time.sleep(0.1)
if self.Ui.radioButton_log_on.isChecked():
self.log_txt.write((str(text) + '\n').encode('utf8'))
self.Ui.textBrowser_log_main.append(text)
self.Ui.textBrowser_log_main.moveCursor(QTextCursor.End)
except Exception as error_info:
self.Ui.textBrowser_log_main.append('[-]Error in add_text_main' + str(error_info))
# ========================================================================移动到失败文件夹
def moveFailedFolder(self, filepath, failed_folder):
if self.Ui.radioButton_fail_move_on.isChecked():
if self.Ui.radioButton_soft_off.isChecked():
try:
shutil.move(filepath, failed_folder + '/')
self.add_text_main('[-]Move ' + os.path.split(filepath)[1] + ' to Failed output folder Success!')
except Exception as error_info:
self.add_text_main('[-]Error in moveFailedFolder! ' + str(error_info))
# ========================================================================下载文件
def DownloadFileWithFilename(self, url, filename, path, Config, filepath, failed_folder):
proxy_type = ''
retry_count = 0