36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
import argparse
|
|
import os.path
|
|
from datetime import datetime
|
|
|
|
from exception.danmaku import DanmakuException
|
|
from workflow.danmaku import get_file_start, diff_danmaku_files, danmaku_to_subtitle
|
|
from workflow.video import encode_video_with_subtitles, quick_split_video
|
|
|
|
|
|
def do_workflow(video_file, danmaku_base_file, *danmaku_files):
|
|
if not os.path.exists(danmaku_base_file):
|
|
...
|
|
result = []
|
|
start_ts = get_file_start(danmaku_base_file)
|
|
base_start = datetime.fromtimestamp(start_ts)
|
|
new_file_name = base_start.strftime("%Y%m%d_%H%M.flv")
|
|
result.append(danmaku_to_subtitle(danmaku_base_file, 0))
|
|
for file in danmaku_files:
|
|
try:
|
|
result.append(danmaku_to_subtitle(file, diff_danmaku_files(danmaku_base_file, file)))
|
|
except DanmakuException:
|
|
print("弹幕文件", file, "异常")
|
|
continue
|
|
print(result)
|
|
encode_video_with_subtitles(video_file, result, new_file_name)
|
|
quick_split_video(new_file_name)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("video", help="视频标准")
|
|
parser.add_argument("base", help="弹幕标准")
|
|
parser.add_argument("files", nargs="+", help="弹幕需要对齐")
|
|
args = parser.parse_args()
|
|
do_workflow(args.video, args.base, args.files)
|