Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

简体弹幕 #274

Open
fangyuan99 opened this issue Apr 24, 2024 · 0 comments
Open

简体弹幕 #274

fangyuan99 opened this issue Apr 24, 2024 · 0 comments

Comments

@fangyuan99
Copy link

这个Python脚本将会遍历当前目录及其所有子目录下的.ass字幕文件,将其中的繁体中文转换为简体中文,并覆盖源文件。请确保在执行这个脚本之前备份重要数据,以防不测。

import os
from opencc import OpenCC

def convert_to_simplified(file_path):
    cc = OpenCC('t2s')  # 繁体转简体
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
    simplified_content = cc.convert(content)
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(simplified_content)
    print(f"Converted: {file_path}")

def traverse_and_convert(root_dir):
    for root, dirs, files in os.walk(root_dir):
        for file in files:
            if file.endswith('.ass'):
                file_path = os.path.join(root, file)
                convert_to_simplified(file_path)

if __name__ == "__main__":
    traverse_and_convert('.')  # 从当前目录开始

使用说明:

  1. 安装所需库:脚本使用 OpenCC 来进行繁简转换,你需要先安装这个库。可以通过 pip 安装:

    pip install opencc-python-reimplemented
  2. 备份文件:由于该脚本会覆盖原文件,请确保你已经备份了所有重要的 .ass 文件。

  3. 运行脚本:将上述代码保存为 Python 文件(例如 convert_ass.py),在包含 .ass 文件的目录中运行该脚本。确保你的工作目录是正确的,或者修改脚本中的 traverse_and_convert('.') 调用,使其指向正确的目录路径。

脚本运行时将打印出被转换的文件路径,以便跟踪进度。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant