|
@@ -8,6 +8,7 @@ import zipfile
|
|
|
from io import BytesIO
|
|
|
from translate import Translator
|
|
|
from chardet.universaldetector import UniversalDetector
|
|
|
+import numpy as np
|
|
|
|
|
|
DEFAULT_ENCODING = "utf-8"
|
|
|
|
|
@@ -69,14 +70,17 @@ def check_zip(zip_filepath:str):
|
|
|
if n != 1:
|
|
|
raise ValueError(f"voice file is can't find is zip at scene {i+1}.")
|
|
|
|
|
|
-def update_zip(zip_path, lang):
|
|
|
+def update_zip(zip_path, lang, new_filename, voice):
|
|
|
temp_zip_path = zip_path + ".tmp"
|
|
|
|
|
|
- with zipfile.ZipFile(zip_path, 'r') as zip_in, zipfile.ZipFile(temp_zip_path, 'w') as zip_out:
|
|
|
+ with zipfile.ZipFile(zip_path, 'r') as zip_in, zipfile.ZipFile(new_filename, 'w') as zip_out:
|
|
|
for item in zip_in.infolist():
|
|
|
with zip_in.open(item.filename) as src_file:
|
|
|
if item.filename.split('.')[-1] == "xlsx":
|
|
|
table = pd.read_excel(src_file, dtype=object)
|
|
|
+ table['聲音'] = np.NaN
|
|
|
+ table.loc[0, ['聲音']] = voice
|
|
|
+ table['發音'] = np.NaN
|
|
|
table = translate_table(table, lang)
|
|
|
table.to_excel(Path(item.filename).name ,sheet_name='Sheet_name_1')
|
|
|
zip_out.write(Path(item.filename).name, item.filename)
|
|
@@ -84,6 +88,9 @@ def update_zip(zip_path, lang):
|
|
|
elif item.filename.split('.')[-1] == "csv":
|
|
|
table = pd.read_csv(src_file, dtype=object)
|
|
|
table = translate_table(table, lang)
|
|
|
+ table['聲音'] = np.NaN
|
|
|
+ table.loc[0, ['聲音']] = voice
|
|
|
+ table['發音'] = np.NaN
|
|
|
table.to_excel(Path(item.filename).name ,sheet_name='Sheet_name_1')
|
|
|
zip_out.write(Path(item.filename).name, item.filename)
|
|
|
os.remove(Path(item.filename).name)
|