You've already forked my-video-workflow
							
							补充西瓜弹幕自动化
This commit is contained in:
		@@ -5,7 +5,7 @@ from glob import glob
 | 
			
		||||
from flask import Blueprint, jsonify, request, current_app
 | 
			
		||||
from typing import Optional
 | 
			
		||||
 | 
			
		||||
from config import BILILIVE_RECORDER_DIRECTORY, VIDEO_TITLE
 | 
			
		||||
from config import BILILIVE_RECORDER_DIRECTORY, VIDEO_TITLE, XIGUALIVE_RECORDER_DIRECTORY
 | 
			
		||||
from model import db
 | 
			
		||||
from model.DanmakuClip import DanmakuClip
 | 
			
		||||
from model.VideoClip import VideoClip
 | 
			
		||||
@@ -81,22 +81,33 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
 | 
			
		||||
        pre_file_name = os.path.splitext(full_path)[0]
 | 
			
		||||
        # 理论上也只有一个结果
 | 
			
		||||
        for danmaku_file in glob("{}*xml".format(pre_file_name)):
 | 
			
		||||
            if os.path.exists(danmaku_file):
 | 
			
		||||
                relpath = os.path.relpath(danmaku_file, BILILIVE_RECORDER_DIRECTORY)
 | 
			
		||||
                # 确认是否已经添加
 | 
			
		||||
                already_add = False
 | 
			
		||||
                for danmaku_clip in workflow.danmaku_clips:
 | 
			
		||||
                    if danmaku_clip.file == relpath and danmaku_clip.base_path == BILILIVE_RECORDER_DIRECTORY:
 | 
			
		||||
                        already_add = True
 | 
			
		||||
                        break
 | 
			
		||||
                if not already_add:
 | 
			
		||||
                    danmaku = DanmakuClip()
 | 
			
		||||
                    danmaku.file = relpath
 | 
			
		||||
                    danmaku.base_path = BILILIVE_RECORDER_DIRECTORY
 | 
			
		||||
                    danmaku.offset = 0
 | 
			
		||||
                    danmaku.workflow = workflow
 | 
			
		||||
                    db.session.add(danmaku)
 | 
			
		||||
                    workflow.danmaku_clips.append(danmaku)
 | 
			
		||||
            relpath = os.path.relpath(danmaku_file, BILILIVE_RECORDER_DIRECTORY)
 | 
			
		||||
            danmaku = DanmakuClip.query.filter(
 | 
			
		||||
                DanmakuClip.file == relpath,
 | 
			
		||||
                DanmakuClip.base_path == BILILIVE_RECORDER_DIRECTORY
 | 
			
		||||
            ).first()
 | 
			
		||||
            if danmaku is None:
 | 
			
		||||
                danmaku = DanmakuClip()
 | 
			
		||||
                danmaku.file = relpath
 | 
			
		||||
                danmaku.base_path = BILILIVE_RECORDER_DIRECTORY
 | 
			
		||||
                danmaku.offset = 0
 | 
			
		||||
                danmaku.workflow = workflow
 | 
			
		||||
                db.session.add(danmaku)
 | 
			
		||||
                workflow.danmaku_clips.append(danmaku)
 | 
			
		||||
        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(
 | 
			
		||||
                DanmakuClip.file == relpath,
 | 
			
		||||
                DanmakuClip.base_path == XIGUALIVE_RECORDER_DIRECTORY
 | 
			
		||||
            ).first()
 | 
			
		||||
            if danmaku is None:
 | 
			
		||||
                danmaku = DanmakuClip()
 | 
			
		||||
                danmaku.file = relpath
 | 
			
		||||
                danmaku.base_path = XIGUALIVE_RECORDER_DIRECTORY
 | 
			
		||||
                danmaku.offset = 0
 | 
			
		||||
                danmaku.workflow = workflow
 | 
			
		||||
                db.session.add(danmaku)
 | 
			
		||||
                workflow.danmaku_clips.append(danmaku)
 | 
			
		||||
    commit_item()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user