-
Notifications
You must be signed in to change notification settings - Fork 0
/
DECtalkPlayer.py
183 lines (172 loc) · 6.11 KB
/
DECtalkPlayer.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
import sys
import os
import subprocess
import time
import atexit
#configuration#
CFG_ver = 1.0
show_metadata = True
details = True
details_error = True
if details:
details_error = True
debug = False
if details:
print("DECtalk Player v1.1.0 || 06 Aug 2023\n")
def exit_handler():
try:
for i in range(len(process_list)):
process_list[i].kill()
except:
if debug:
raise
if details_error:
print("error closing DECtalk windows")
def read_metadata():
print("")
if version == 0.0:
for i in range(len(config)):
if config[i].strip() == "!FILES!":
break
else:
print(config[i].strip())
else:
metadata_temp = 0
for i in range(len(config)):
if config[i+1].strip() == "!FILES!":
break
elif metadata_temp == 1:
print(config[i+1].strip())
elif config[i+1].strip() == "!META!":
metadata_temp = 1
def create_command_list():
if version == 0.0:
for i in range(len(config) - startingLine):
command_list.append(["SPE", config[i+startingLine][0:8].strip(), "FILE", (relpath + config[i+startingLine][9:].strip()).replace("\\","/")])
if details:
print("file names and dependencies:")
i = 0
for i_fake in range(len(command_list)):
if debug and details:
print(i_fake, i, len(command_list))
if i < len(command_list):
if details:
print(command_list[i][3] + " - " + command_list[i][1])
try:
path_check = open(command_list[i][3], "r")
path_check.close()
i += 1
except:
if details_error:
print("file \"" + command_list[i][3] + "\" not found")
command_list.pop(i)
else:
for i in range(len(config) - startingLine):
CCL_temp_list = []
CCL_temp_list.append(config[i+startingLine][0:3].strip())
CCL_temp_divider = config[i+startingLine].find("|")
CCL_temp_list.append(config[i+startingLine][4:CCL_temp_divider].strip())
CCL_temp_list.append(config[i+startingLine][CCL_temp_divider + 1:CCL_temp_divider + 5].strip())
CCL_temp_list.append(config[i+startingLine][CCL_temp_divider + 6:].strip())
command_list.append(CCL_temp_list)
if debug:
print(CCL_temp_list)
if details:
print("file names and dependencies:")
i = 0
for i_fake in range(len(command_list)):
if debug and details:
print(i_fake, i, len(command_list))
if i < len(command_list):
if command_list[i][2] == "FILE":
if details:
print(command_list[i][3] + " - " + command_list[i][0])
try:
path_check = open(command_list[i][3], "r")
command_list[i][3] = path_check.read()
path_check.close()
i += 1
except:
if details_error:
print("file \"" + command_list[i][3] + "\" not found")
command_list.pop(i)
else:
if details:
print("Text In CFG" + " - " + command_list[i][1])
i += 1
#choose config file name
conf_name = ""
if len(sys.argv) >= 2:
conf_name = sys.argv[1]
else:
conf_name = input("Path to config file : ")
if details:
print("loading from file \"" + conf_name + "\"...")
try:
conf = open(conf_name, "r")
relpath = os.path.dirname(conf.name)
if relpath != "":
relpath += "/"
if debug and (details):
print("file \"" + conf.name + "\" is in the relative directory \"" + relpath + "\"")
config = conf.readlines()
conf.close()
length = (float(config[0]))
try:
version = (float(config[1]))
#if cfg version is newer than the CFG_ver, alert user.
if version > CFG_ver:
if details_error:
print("CFG version newer than supported. It may not work with your version of DtP")
except:
version = 0.0
if details_error:
print("ERROR : No version for CFG file. It may not work with your version of DtP.")
if debug:
print("cfg version", version, "\nmax cfg version", CFG_ver)
#find where the files start
startingLine = 0
for i in range(len(config)):
if config[i].strip() == "!FILES!":
break
else:
startingLine += 1
startingLine += 1
if startingLine >= len(config):
startingLine = 1
if debug and (details):
print(startingLine)
command_list = []
try:
create_command_list()
try:
#run/stop speak_us.exe with all the files
process_list = []
atexit.register(exit_handler)
for i in range(len(command_list)):
try:
if command_list[i][0] == "SPE":
process_list.append(subprocess.Popen([command_list[i][1],command_list[i][3]], start_new_session=True, shell=False))
elif command_list[i][0] == "SAY":
process_list.append(subprocess.Popen([command_list[i][1],command_list[i][3]], start_new_session=True, shell=False))
except:
if debug:
raise
if details_error:
print(command_list[i][3] + " - couldn't open \"" + command_list[i][1] + "\" window")
if (startingLine != 1) and show_metadata:
read_metadata()
time.sleep(length)
except:
if debug:
raise
except:
if debug:
raise
except:
if debug:
raise
if details_error:
print("couldn't load \"" + conf_name + "\"")
if details:
print("\nexiting program...")