forked from ACA4DFA4/CGSS_ACB_Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename.py
324 lines (292 loc) · 19.3 KB
/
rename.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
#!py -3
#!/usr/bin/env python
import csv
import numpy as np
import pandas as pd
import os,sys, os.path
import sqlite3
from datetime import date
from pathlib import Path
cgss_path=os.getcwd()
cgss_logs=cgss_path+"\\logs"
csv_header= ['manifest_music_name', 'music_data_name', 'manifest_version', 'date']
csv_music_data=cgss_logs+"\\music_data\\music_data.csv"
music_data_another=cgss_path+"\\local_data\\music_data_another.db"
music_data=cgss_path+"\\local_data\\music_data.db"
chara_data=cgss_path+"\\local_data\\chara_data.db"
old_files = ["\\sound\\s_ren1.bat","\\sound\\s_ren2.bat","\\txt\\song_1001_vocal_list.txt","\\txt\\song_another_name_list.txt",
"\\txt\\song_call_name_list.txt","\\txt\\song_collab_name_list.txt","\\txt\\song_movie_name_list.txt","\\txt\\song_se_name_list.txt"]
if not os.path.exists(cgss_path+"\\Static_version"):
print("\tStatic version are not found !")
print("\tPlease run cgss.py to get manifests version")
sys.exit(1)
elif os.path.exists(cgss_path+"\\Static_version"):
f=Path(cgss_path+"\\Static_version")
f=open(f)
version = f.read()
f.close()
if version == None:
print("\tCurrent manifest version = "+version)
print("\tPlease run cgss.py if you want to get latest manifest version!")
manifests=cgss_path+"\\manifests\\manifest_"+version+".db"
manifests_con=sqlite3.Connection(manifests)
music_data_con=sqlite3.Connection(music_data)
music_data_another_con=sqlite3.Connection(music_data_another)
today=date.today()
vocal_data_con=sqlite3.Connection(chara_data)
xlsx_music_data=cgss_logs+"\\music_data\\music_data.xlsx"
print("\tCGSS ACB Auto Renamer | Starting!")
print("\tUpdate & Maintain by @Nicklas373")
print("\tCleanup old log from rename file is exists! ...")
for old_log in old_files:
if old_log == "\\sound\\s_ren1.bat" or old_log == "\\sound\\s_ren2.bat":
if os.path.exists(cgss_path+"\\"+version+"\\"+old_log):
os.remove(cgss_path+"\\"+version+"\\"+old_log)
else:
if os.path.exists(cgss_logs+old_log):
os.remove(cgss_logs+old_log)
solo_list = np.loadtxt(cgss_logs+"\\txt\\solo_list.txt", dtype=str, delimiter=",")
for solo_in_query in solo_list:
if os.path.exists(cgss_logs+"\\txt\\"+str(solo_in_query)+"_vocal.txt"):
os.remove(cgss_logs+"\\txt\\"+str(solo_in_query)+"_vocal.txt")
if os.path.exists(version+"\\solo\\"+solo_in_query+"\\sva_ren1.bat"):
os.remove(version+"\\solo\\"+solo_in_query+"\\sva_ren1.bat")
if os.path.exists(version+"\\solo\\"+solo_in_query+"\\sva_ren2.bat"):
os.remove(version+"\\solo\\"+solo_in_query+"\\sva_ren2.bat")
print("\tBegin generate music name list from database...")
print("\tCreate name list for "+version+"/sound in database from manifests ...\n")
query=manifests_con.execute("select name,hash,size from manifests where name like 'l/song%.acb' and size > '7000' and name not like 'l/song_%_another.acb' and name not like 'l/song_%_call.acb' and name not like 'l/song_%_collab.acb' and name not like 'l/song_%_se.acb' and name not like 'l/song_%_movie.acb'")
for name,hash,size in query:
f=open(cgss_logs+"\\txt\\song_main_name_list.txt", 'a')
if (int(name[7:][:-4]) > 1000):
f.write(name[7:][:-4]+"\n")
else:
print("")
f.close()
if os.path.exists(csv_music_data):
print("\tCleanup old music data (CSV)..")
os.remove(csv_music_data)
if os.path.exists(xlsx_music_data):
print("\tCleanup old music data (XLSX)..")
os.remove(xlsx_music_data)
song_main_name_list = np.loadtxt(cgss_logs+"\\txt\\"+"song_main_name_list.txt", dtype=str, delimiter=",")
for song_main_name in song_main_name_list:
query=music_data_con.execute("select id, name from music_data where id like '"+song_main_name+"'")
if not os.path.exists(csv_music_data):
if not os.path.exists(cgss_logs+"\\music_data"):
os.makedirs(cgss_logs+"\\music_data")
f = open(csv_music_data, 'w', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_header)
f.close()
for id,name in query:
fp1=open(cgss_path+"\\"+version+"\\sound\\s_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\sound\\s_ren2.bat", 'a', encoding='utf8')
replace_phase_1 = str(name).replace(' ','_')
replace_phase_2 = str(replace_phase_1).replace('\n','')
fp1.write("ren song_"+str(id)+".hca"+ ' '+str(replace_phase_2).replace("\n"," ")+".hca"+"\n")
fp2.write("ren "+str(replace_phase_2).replace('/n','')+".hca"+' '+"song_"+str(id)+".hca"+"\n")
fp1.close()
fp2.close()
csv_solo_rows=["song_"+str(id)+".hca", str(replace_phase_2).replace("\n"," ")+".hca", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
print("\tCreate auto rename for "+version+"/sound_another in database from manifests ...\n")
query=manifests_con.execute("select name,hash,size from manifests where name like 'l/song_%_another.acb' and size > '7000' and name not like 'l/song_%_call.acb' and name not like 'l/song_%_collab.acb' and name not like 'l/song_%_se.acb' and name not like 'l/song_%_movie.acb'")
for name,hash,size in query:
f=open(cgss_logs+"\\txt\\song_another_name_list.txt", 'a')
f.write(name[7:][:-4]+"\n")
f.close()
song_another_name_list = np.loadtxt(cgss_logs+"\\txt\\"+"song_another_name_list.txt", dtype=str, delimiter=",")
for song_another_name in song_another_name_list:
query=music_data_another_con.execute("select music_id, name from music_another_data where music_id like '"+song_another_name+"'")
for music_id,name in query:
fp1=open(cgss_path+"\\"+version+"\\sound\\s_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\sound\\s_ren2.bat", 'a', encoding='utf8')
fp1.write("ren song_"+music_id+".hca"+ ' '+str(name).replace(' ','_')+"_another.hca"+"\n")
fp2.write("ren "+str(name).replace(' ','_')+"_another.hca"+' '+"song_"+music_id+".hca"+"\n")
fp1.close()
fp2.close()
csv_solo_rows=["song_"+str(music_id)+".hca", str(name).replace(' ','_')+"_another.hca", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
print("\tCreate auto rename for "+version+"/sound_call in database from manifests ...\n")
query=manifests_con.execute("select name,hash,size from manifests where name like 'l/song_%_call.acb' and size > '7000' and name not like 'l/song_%_another.acb' and name not like 'l/song_%_collab.acb' and name not like 'l/song_%_se.acb' and name not like 'l/song_%_movie.acb'")
for name,hash,size in query:
f=open(cgss_logs+"\\txt\\song_call_name_list.txt", 'a')
f.write(name[7:][:-4]+"\n")
f.close()
song_call_name_list = np.loadtxt(cgss_logs+"\\txt\\"+"song_call_name_list.txt", dtype=str, delimiter=",")
for song_call_name in song_call_name_list:
query=music_data_another_con.execute("select music_id, name from music_another_data where music_id like '"+song_call_name+"'")
for music_id,name in query:
fp1=open(cgss_path+"\\"+version+"\\sound\\s_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\sound\\s_ren2.bat", 'a', encoding='utf8')
fp1.write("ren song_"+music_id+".hca"+ ' '+str(name).replace(' ','_')+"_call.hca"+"\n")
fp2.write("ren "+str(name).replace(' ','_')+"_call.hca"+' '+"song_"+music_id+".hca"+"\n")
fp1.close()
fp2.close()
csv_solo_rows=["song_"+str(music_id)+".hca", str(name).replace(' ','_')+"_call.hca", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
query=manifests_con.execute("select name,hash,size from manifests where name like 'l/song_%_collab.acb' and size > '7000' and name not like 'l/song_%_another.acb' and name not like 'l/song_%_call.acb' and name not like 'l/song_%_se.acb' and name not like 'l/song_%_movie.acb'")
print("\tCreate auto rename for "+version+"/sound_collab in database from manifests ...\n")
for name,hash,size in query:
f=open(cgss_logs+"\\txt\\song_collab_name_list.txt", 'a')
f.write(name[7:][:-4]+"\n")
f.close()
song_collab_name_read = open(cgss_logs+"\\txt\\"+"song_collab_name_list.txt", "r")
song_collab_name = song_collab_name_read.read()
query=music_data_con.execute("select id, name from music_data where id like '"+song_collab_name[:-8]+"'")
for id,name in query:
fp1=open(cgss_path+"\\"+version+"\\sound\\s_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\sound\\s_ren2.bat", 'a', encoding='utf8')
fp1.write("ren song_"+str(id)+".hca"+ ' '+str(name).replace(' ','_')+"_collab.hca"+"\n")
fp2.write("ren "+str(name).replace(' ','_')+"_collab.hca"+' '+"song_"+str(id)+".hca"+"\n")
fp1.close()
fp2.close()
csv_solo_rows=["song_"+str(id)+".hca", str(name).replace(' ','_')+"_collab.hca", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
query=manifests_con.execute("select name,hash,size from manifests where name like 'l/song_%_se.acb' and size > '7000' and name not like 'l/song_%_another.acb' and name not like 'l/song_%_collab.acb' and name not like 'l/song_%_call.acb' and name not like 'l/song_%_movie.acb'")
print("\tCreate auto rename for "+version+"/sound_se in database from manifests ...\n")
for name,hash,size in query:
f=open(cgss_logs+"\\txt\\song_se_name_list.txt", 'a')
f.write(name[7:][:-4]+"\n")
f.close()
song_se_name_list = np.loadtxt(cgss_logs+"\\txt\\"+"song_se_name_list.txt", dtype=str, delimiter=",")
for song_se_name in song_se_name_list:
query=music_data_con.execute("select id, name from music_data where id like '"+song_se_name[:-3]+"'")
for id,name in query:
fp1=open(cgss_path+"\\"+version+"\\sound\\s_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\sound\\s_ren2.bat", 'a', encoding='utf8')
fp1.write("ren song_"+str(id)+".hca"+ ' '+str(name).replace(' ','_')+"_se.hca"+"\n")
fp2.write("ren "+str(name).replace(' ','_')+"_se.hca"+' '+"song_"+str(id)+".hca"+"\n")
fp1.close()
fp2.close()
csv_solo_rows=["song_"+str(id)+".hca", str(name).replace(' ','_')+"_se.hca", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
query=manifests_con.execute("select name,hash,size from manifests where name like 'l/song_%_movie.acb' and size > '7000' and name not like 'l/song_%_another.acb' and name not like 'l/song_%_collab.acb' and name not like 'l/song_%_call.acb' and name not like 'l/song_%_se.acb'")
print("\tCreate auto rename for "+version+"/sound_movie in database from manifests ...\n")
for name,hash,size in query:
f=open(cgss_logs+"\\txt\\song_movie_name_list.txt", 'a')
f.write(name[7:][:-4]+"\n")
f.close()
song_movie_name_read = open(cgss_logs+"\\txt\\"+"song_movie_name_list.txt", "r")
song_movie_name_list = song_movie_name_read.read()
query=music_data_con.execute("select id, name from music_data where id like '"+song_movie_name_list[:-7]+"'")
for id,name in query:
fp1=open(cgss_path+"\\"+version+"\\sound\\s_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\sound\\s_ren2.bat", 'a', encoding='utf8')
fp1.write("ren song_"+str(id)+".hca"+ ' '+str(name).replace(' ','_')+"_movie.hca"+"\n")
fp2.write("ren "+str(name).replace(' ','_')+"_movie.hca"+' '+"song_"+str(id)+".hca"+"\n")
fp1.close()
fp2.close()
csv_solo_rows=["song_"+str(id)+".hca", str(name).replace(' ','_')+"movie.hca", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
print("\tCreate auto rename for "+version+"/sound_1001 in database from manifests ...\n")
query=manifests_con.execute("select name,hash,size from manifests where name like 'l/song_1001_%.acb' and size > '7000' and name not like 'l/song_%_call.acb' and name not like 'l/song_%_collab.acb' and name not like 'l/song_%_se.acb' and name not like 'l/song_%_movie.acb'")
for name,hash,size in query:
f=open(cgss_logs+"\\txt\\song_1001_vocal_list.txt", 'a')
f.write(name[12:][:-4]+"\n")
f.close()
song_1001_vocal_list = np.loadtxt(cgss_logs+"\\txt\\"+"song_1001_vocal_list.txt", dtype=str, delimiter=",")
for song_1001_vocal in song_1001_vocal_list:
query=vocal_data_con.execute("select chara_id, name from chara_data where chara_id like '"+song_1001_vocal+"'")
for chara_id,name in query:
fp1=open(cgss_path+"\\"+version+"\\sound\\s_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\sound\\s_ren2.bat", 'a', encoding='utf8')
fp1.write("ren song_1001_"+str(chara_id)+".hca"+ ' お願い_!_シンデレラ~'+str(name).replace(' ','_')+".hca"+"\n")
fp2.write("ren お願い_!_シンデレラ~"+str(name).replace(' ','_')+".hca"+' '+"song_1001_"+str(chara_id)+".hca"+"\n")
fp1.close()
fp2.close()
csv_solo_rows=["song_1001_"+str(chara_id)+".hca", ' お願い_!_シンデレラ~'+str(name).replace(' ','_')+".hca", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
print("\tCreate auto rename for "+version+"/sound_solo_part in database from manifests ...\n")
solo_list = np.loadtxt(cgss_logs+"\\txt\\solo_list.txt", dtype=str, delimiter=",")
for solo_in_query in solo_list:
query = manifests_con.execute("select name, hash, size from manifests where name like 'l/"+solo_in_query+"/vo_solo_%_0%.awb'")
f=open(cgss_logs+"\\txt\\"+solo_in_query+"_vocal.txt", 'a')
for name, hash, size in query:
f.write(str(name[31:][:-4])+"\n")
f.close()
solo_list = np.loadtxt(cgss_logs+"\\txt\\solo_list.txt", dtype=str, delimiter=",")
for solo_in_query in solo_list:
sub_solo_list = np.loadtxt(cgss_logs+"\\txt\\"+solo_in_query+"_vocal.txt", dtype=str, delimiter=",")
fp1=open(cgss_path+"\\"+version+"\\solo\\"+solo_in_query+"\\sva_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\solo\\"+solo_in_query+"\\sva_ren2.bat", 'a', encoding='utf8')
for sub_solo_list_in_query in sub_solo_list:
solo_id_trim = solo_in_query[5:][:-5]
query1 = music_data_con.execute("select id, name as music_name from music_data where id like '"+solo_id_trim+"'")
for id, music_name in query1:
if (sub_solo_list_in_query[3:] == "_1"):
trim_sub_solo = sub_solo_list_in_query[:-2]
elif (sub_solo_list_in_query[3:] == "_2"):
trim_sub_solo = sub_solo_list_in_query[:-2]
else:
trim_sub_solo = sub_solo_list_in_query
query2 = vocal_data_con.execute("select chara_id, name as chara_name from chara_data where chara_id like '"+trim_sub_solo+"'")
for chara_id, chara_name in query2:
solo_id_trim_2 = solo_in_query[5:][:-5]
if (sub_solo_list_in_query[3:] == "_1"):
trim_sub_solo_2 = str(chara_id)+"_1"
trim_sub_chara_2 = str(chara_name)+"_1"
elif (sub_solo_list_in_query[3:] == "_2"):
trim_sub_solo_2 = str(chara_id)+"_2"
trim_sub_chara_2 = str(chara_name)+"_2"
else:
trim_sub_solo_2 = str(chara_id)
trim_sub_chara_2 = str(chara_name)
fp1.write("ren vo_solo_"+solo_id_trim_2+"_0"+str(trim_sub_solo_2)+".awb"+' '+str(music_name.replace('\n',"_"))+"~"+str(trim_sub_chara_2)+".awb"+"\n")
fp2.write("ren "+str(music_name.replace('\n',"_"))+"~"+str(trim_sub_chara_2)+".awb"+' '+"vo_solo_"+solo_id_trim_2+"_0"+str(trim_sub_solo_2)+".awb"+"\n")
fp1.close
fp2.close
csv_solo_rows=["vo_solo_"+solo_id_trim_2+"_0"+str(trim_sub_solo_2)+".awb", str(music_name.replace('\n',"_"))+"~"+str(trim_sub_chara_2)+".awb", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
solo_list = np.loadtxt(cgss_logs+"\\txt\\solo_list.txt", dtype=str, delimiter=",")
for solo_in_query in solo_list:
fp1=open(cgss_path+"\\"+version+"\\solo\\"+solo_in_query+"\\sva_ren1.bat", 'a', encoding='utf8')
fp2=open(cgss_path+"\\"+version+"\\solo\\"+solo_in_query+"\\sva_ren2.bat", 'a', encoding='utf8')
solo_id_trim = solo_in_query[5:][:-5]
query1 = music_data_con.execute("select id, name as music_name from music_data where id like '"+solo_id_trim+"'")
for id, music_name in query1:
solo_id_trim_2 = solo_in_query[5:][:-5]
fp1.write("ren inst_song_"+solo_id_trim_2+".awb"+' '+"inst_"+str(music_name).replace(" ","_")+".awb"+"\n")
fp2.write("ren inst_"+str(music_name).replace(" ","_")+".awb"+' '+"inst_song_"+solo_id_trim_2+".awb"+"\n")
fp1.close
fp2.close
csv_solo_rows=["inst_song_"+solo_id_trim_2+".awb", "inst_"+str(music_name).replace(" ","_")+".awb", version, today.strftime("%d/%m/%Y")]
f = open(csv_music_data, 'a', encoding='UTF8', newline='')
writer = csv.writer(f)
writer.writerow(csv_solo_rows)
f.close()
print("\tDump music data into XLSX!")
read_file = pd.read_csv(csv_music_data, on_bad_lines='skip')
read_file.to_excel(xlsx_music_data, index=None, header=True)
if os.path.isfile(xlsx_music_data):
print("\tDump success...")
print("\tCheck music data on logs/music_data/music_data.xlsx...")
else:
print("\tDump failed...")
print("\tCheck music data on logs/music_data/music_data.csv...")
print("\tCGSS ACB Renamer List | Finished!")