forked from kslz/SoundLabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (45 loc) · 1.5 KB
/
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
import sys
from PySide6.QtWidgets import QApplication
import global_obj
from ui import guiclass
from utils import dictdir, LiteDB, check_mkdir
from threading import Thread
def main():
global_obj._init()
db_path = "db/data.db"
file_dict_path = "filepath/"
sound_type = ["wav", "mp3", "aac"]
# 读取文件路径
check_mkdir(file_dict_path)
srt_file_dict = {}
file_dict = {}
dictdir(file_dict_path, srt_file_dict, "srt")
dictdir(file_dict_path, file_dict, "")
global sound_dict
sound_dict = get_sound_dict(srt_file_dict, file_dict, sound_type)
# print(sound_dict)
db = LiteDB()
global_obj.set_value("sound_dict", sound_dict)
global_obj.set_value("db", db)
global_obj.set_value("sound_type",sound_type)
# sqlite的对象不能在别的线程里用,先不用了
# gui_thread = Thread(target=guiclass.main)
# gui_thread.start()
# gui_thread.join()
guiclass.main()
print("GUI已关闭")
db.close()
def get_sound_dict(srt_file_dict, file_dict, sound_type):
sound_dict = {}
for srt_file in srt_file_dict.keys():
sound_path = ""
for type in sound_type:
sound_file = srt_file.replace(".srt", "." + type)
# print(sound_file)
if sound_file in file_dict:
sound_path = file_dict[sound_file]
break
sound_dict[srt_file.replace(".srt", "")] = (srt_file_dict[srt_file], sound_path)
return sound_dict
if __name__ == '__main__':
main()