diff --git a/ADC_function.py b/ADC_function.py index ef539fd..44a1d37 100755 --- a/ADC_function.py +++ b/ADC_function.py @@ -451,3 +451,11 @@ def translateTag_to_sc(tag): return tag else: return tag + +def translate(src:str,target_language:str="zh_cn"): + url = f"https://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl={target_language}&q={src}" + result = get_html(url=url,return_type="object") + + translate_list = [i["trans"] for i in result.json()["sentences"]] + + return "".join(translate_list) diff --git a/config.ini b/config.ini index 1cb579e..be3a55c 100644 --- a/config.ini +++ b/config.ini @@ -31,3 +31,7 @@ folders=failed,JAV_output [debug_mode] switch=0 + +[transalte] +switch=0 # 是否开启翻译功能 +values=title,outline #需要翻译的变量 diff --git a/config.py b/config.py index 6240993..305d802 100644 --- a/config.py +++ b/config.py @@ -43,7 +43,10 @@ class Config: return self.conf.getboolean("common", "auto_exit") def transalte_to_sc(self) -> bool: return self.conf.getboolean("common", "transalte_to_sc") - + def is_transalte(self) -> bool: + return self.conf.getboolean("transalte", "switch") + def transalte_values(self) -> bool: + return self.conf.get("transalte", "values") def proxy(self) -> [str, int, int, str]: try: sec = "proxy" @@ -138,6 +141,11 @@ class Config: conf.add_section(sec7) conf.set(sec7, "switch", "0") + sec8 = "transalte" + conf.add_section(sec8) + conf.set(sec8, "switch", "0") + conf.set(sec8, "values", "title,outline") + return conf @@ -157,3 +165,5 @@ if __name__ == "__main__": print(config.escape_literals()) print(config.escape_folder()) print(config.debug()) + print(config.is_transalte()) + print(config.transalte_values()) diff --git a/core.py b/core.py index d20767d..7a4841d 100755 --- a/core.py +++ b/core.py @@ -207,10 +207,20 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON json_data['release'] = release json_data['cover_small'] = cover_small json_data['tag'] = tag - json_data['naming_rule'] = eval(conf.naming_rule()) json_data['location_rule'] = location_rule json_data['year'] = year json_data['actor_list'] = actor_list + if conf.is_transalte(): + translate_values = conf.transalte_values().split(",") + for translate_value in translate_values: + json_data[translate_value] = translate(json_data[translate_value]) + naming_rule="" + for i in conf.naming_rule().split("+"): + if i not in json_data: + naming_rule+=i.strip("'").strip('"') + else: + naming_rule+=json_data[i] + json_data['naming_rule'] = naming_rule return json_data