31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
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)
|
|
# clean files
|
|
for file in result:
|
|
os.remove(file)
|
|
os.remove(new_file_name)
|
|
|