Skip to content

Commit

Permalink
Merge pull request #603 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
优化翻译前原文字幕的保存实现
  • Loading branch information
Ikaros-521 committed Jan 29, 2024
2 parents a08910b + fe4e9a5 commit 5691f73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions utils/my_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def config_load(self):
f.write('')
logging.info(f'{self.log_file_path} 日志文件已创建')

# 生成弹幕文件
self.comment_file_path = "./log/comment-" + My_handle.common.get_bj_time(1) + ".txt"
if os.path.isfile(self.comment_file_path):
logging.info(f'{self.comment_file_path} 弹幕文件已存在,跳过')
Expand Down
11 changes: 5 additions & 6 deletions utils/my_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def trans(self, text, type=None) -> str:
if type is None:
type = self.config_data["type"]

# 是否启用字幕输出
if self.config.get("captions", "enable"):
# 输出当前播放的音频文件的文本内容到字幕文件中,就是保存翻译前的原文
self.common.write_content_to_file(self.config.get("captions", "raw_file_path"), text, write_log=False)

if type == "baidu":
return self.baidu_trans(text)
elif type == "google":
Expand All @@ -64,8 +69,6 @@ def baidu_trans(self, text):
appid = self.baidu_config["appid"]
appkey = self.baidu_config["appkey"]

captions_config = self.config.get("captions")

# For list of language codes, please refer to `https://api.fanyi.baidu.com/doc/21`
from_lang = self.baidu_config["from_lang"]
to_lang = self.baidu_config["to_lang"]
Expand All @@ -84,10 +87,6 @@ def make_md5(s, encoding='utf-8'):
# Build request
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
payload = {'appid': appid, 'q': text, 'from': from_lang, 'to': to_lang, 'salt': salt, 'sign': sign}
# 是否启用字幕输出
if captions_config["enable"]:
# 输出当前播放的音频文件的文本内容到字幕文件中
self.common.write_content_to_file(captions_config["raw_file_path"], text, write_log=False)

try:
# Send request
Expand Down

0 comments on commit 5691f73

Please sign in to comment.