You've already forked my-video-workflow
避免添加了反向偏移过大的弹幕文件
This commit is contained in:
@ -11,6 +11,9 @@ from model.DanmakuClip import DanmakuClip
|
||||
from model.VideoClip import VideoClip
|
||||
from model.Workflow import Workflow
|
||||
from worker.danmaku import do_workflow
|
||||
from workflow.danmaku import get_file_start
|
||||
from workflow.video import get_video_real_duration
|
||||
from exception.danmaku import DanmakuException
|
||||
|
||||
blueprint = Blueprint("api_bilirecorder", __name__, url_prefix="/api/bilirecorder")
|
||||
|
||||
@ -86,6 +89,7 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
full_path = clip.full_path
|
||||
pre_file_name = os.path.splitext(full_path)[0]
|
||||
# 理论上也只有一个结果
|
||||
start_time_ts = None
|
||||
for danmaku_file in glob("{}*xml".format(pre_file_name)):
|
||||
relpath = os.path.relpath(danmaku_file, BILILIVE_RECORDER_DIRECTORY)
|
||||
danmaku = DanmakuClip.query.filter(
|
||||
@ -93,6 +97,10 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
DanmakuClip.base_path == BILILIVE_RECORDER_DIRECTORY
|
||||
).first()
|
||||
if danmaku is None:
|
||||
try:
|
||||
start_time_ts = get_file_start(danmaku_file)
|
||||
except DanmakuException:
|
||||
start_time_ts = None
|
||||
danmaku = DanmakuClip()
|
||||
danmaku.file = relpath
|
||||
danmaku.base_path = BILILIVE_RECORDER_DIRECTORY
|
||||
@ -100,6 +108,10 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
danmaku.workflow = workflow
|
||||
db.session.add(danmaku)
|
||||
workflow.danmaku_clips.append(danmaku)
|
||||
if start_time_ts is None:
|
||||
if clip.duration is None or clip.duration == 0:
|
||||
clip.duration = get_video_real_duration(clip.full_path)
|
||||
start_time_ts = datetime.now().timestamp() - clip.duration
|
||||
for danmaku_file in glob(os.path.join(XIGUALIVE_RECORDER_DIRECTORY, "*.xml")):
|
||||
relpath = os.path.relpath(danmaku_file, XIGUALIVE_RECORDER_DIRECTORY)
|
||||
danmaku = DanmakuClip.query.filter(
|
||||
@ -107,10 +119,17 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
DanmakuClip.base_path == XIGUALIVE_RECORDER_DIRECTORY
|
||||
).first()
|
||||
if danmaku is None:
|
||||
try:
|
||||
start_time_xg = get_file_start(danmaku_file)
|
||||
except DanmakuException:
|
||||
continue
|
||||
bias = start_time_xg - start_time_ts
|
||||
if bias < -600:
|
||||
print("弹幕文件", danmaku_file, "反向偏移超过10分钟")
|
||||
danmaku = DanmakuClip()
|
||||
danmaku.file = relpath
|
||||
danmaku.base_path = XIGUALIVE_RECORDER_DIRECTORY
|
||||
danmaku.offset = 0
|
||||
danmaku.offset = bias
|
||||
danmaku.workflow = workflow
|
||||
db.session.add(danmaku)
|
||||
workflow.danmaku_clips.append(danmaku)
|
||||
|
Reference in New Issue
Block a user