TA的每日心情 | 开心 8 小时前 |
---|
签到天数: 580 天 [LV.9]以坛为家II
荣誉会员
- 积分
- 129255
|
如果只是反了, 你需要把时间交换下, 用脚本做这个重复的事挺好的
- import os
- import sys
- import time
- def run(p):
- bn = os.path.basename(p)
- name, ext=os.path.splitext(bn)
- if not (ext.lower() in ['.ass',]):
- return
- for coding in ["utf-8", "gbk", "big5", "gb2312", "gb18030", "cp1252", "utf-16", "utf-32"]:
- try:
- with open(p, 'r', encoding=coding) as file:
- lines = file.readlines()
- break
- except (UnicodeDecodeError, UnicodeError):
- print(2)
- continue
- except FileNotFoundError:
- print(3)
- return
- new_lines = []
- for idx, line in enumerate(lines):
- if line.startswith("Dialogue:"):
- fields = line.split(",", 3)
- start_time = fields[1]
- end_time = fields[2]
- if start_time > end_time:
- fields[1] = end_time
- fields[2] = start_time
- new_line = ','.join(fields)
- new_lines.append(new_line)
- print(f"L{str(idx+1)} 时间相反 {line}", end="")
- else:
- new_lines.append(line)
- else:
- new_lines.append(line)
- new_name = os.path.join(os.path.dirname(p), name + '.' + str(int(time.time())) + ext)
- with open(new_name, 'w', encoding="utf-8") as fw:
- fw.writelines(new_lines)
- return new_name
- if __name__ == '__main__':
- if sys.argv[1]:
- run(sys.argv[1])
- os.system('pause')
复制代码
代码保存成1.py
命令行执行python c:\文件全路径\1.py c:\文件全路径\1.ass即可
如果没装python就装一个python3
|
|