You've already forked my-video-workflow
自动投稿alpha
This commit is contained in:
@ -1,25 +1,28 @@
|
||||
import os.path
|
||||
import threading
|
||||
from concurrent.futures import ProcessPoolExecutor, Future
|
||||
from datetime import datetime
|
||||
from glob import glob
|
||||
from typing import Optional
|
||||
|
||||
from flask import Blueprint, jsonify, request, current_app
|
||||
|
||||
from config import BILILIVE_RECORDER_DIRECTORY, VIDEO_TITLE, XIGUALIVE_RECORDER_DIRECTORY
|
||||
from config import BILILIVE_RECORDER_DIRECTORY, VIDEO_TITLE, XIGUALIVE_RECORDER_DIRECTORY, VIDEO_OUTPUT_DIR, VIDEO_DESC, \
|
||||
VIDEO_TAGS, VIDEO_TID
|
||||
from exception.danmaku import DanmakuException
|
||||
from model import db
|
||||
from model.DanmakuClip import DanmakuClip
|
||||
from model.VideoClip import VideoClip
|
||||
from model.VideoPart import VideoPart
|
||||
from model.Workflow import Workflow
|
||||
from workflow.danmaku import get_file_start
|
||||
from workflow.video import get_video_real_duration, duration_str_to_float
|
||||
from workflow.worker import do_workflow
|
||||
from workflow.bilibili import IS_LIVING, INSTANCE as bilibili_instance
|
||||
|
||||
blueprint = Blueprint("api_bilirecorder", __name__, url_prefix="/api/bilirecorder")
|
||||
|
||||
bili_record_workflow_item: Optional[Workflow] = None
|
||||
|
||||
pool = ProcessPoolExecutor(max_workers=4)
|
||||
|
||||
def auto_submit_task():
|
||||
global bili_record_workflow_item
|
||||
@ -32,20 +35,29 @@ def auto_submit_task():
|
||||
if len(bili_record_workflow_item.video_clips) == 0:
|
||||
print("[!]Auto Submit Fail: No Video Clips")
|
||||
return
|
||||
_started = False
|
||||
for video_clip in bili_record_workflow_item.video_clips:
|
||||
if len(video_clip.danmaku_clips) > 0:
|
||||
print("[+]Workflow:", bili_record_workflow_item.id, "; Video:", video_clip.full_path)
|
||||
_started = True
|
||||
threading.Thread(target=do_workflow, args=(
|
||||
_future = pool.submit(
|
||||
do_workflow,
|
||||
video_clip.full_path,
|
||||
video_clip.danmaku_clips[0].full_path,
|
||||
*[clip.full_path for clip in video_clip.danmaku_clips[1:]]
|
||||
)).start()
|
||||
)
|
||||
clear_item()
|
||||
def _encode_finish_callback(_f: "Future"):
|
||||
_result = _f.result()
|
||||
if _result:
|
||||
# start uploading
|
||||
bilibili_instance.upload(parts=_result,
|
||||
title=bili_record_workflow_item.name,
|
||||
desc=VIDEO_DESC,
|
||||
tid=VIDEO_TID,
|
||||
tag=VIDEO_TAGS)
|
||||
_future.add_done_callback(_encode_finish_callback)
|
||||
else:
|
||||
print("[-]Workflow:", bili_record_workflow_item.id, "; Video:", video_clip.full_path, "; No Danmaku")
|
||||
if _started:
|
||||
clear_item()
|
||||
|
||||
|
||||
def clear_item():
|
||||
@ -156,9 +168,11 @@ def bilirecorder_event():
|
||||
return response
|
||||
|
||||
if payload['EventType'] == "SessionStarted":
|
||||
IS_LIVING.set()
|
||||
# 录制开始
|
||||
safe_create_item()
|
||||
elif payload['EventType'] == "SessionEnded":
|
||||
IS_LIVING.clear()
|
||||
# 录制结束
|
||||
item = safe_get_item()
|
||||
item.editing = False
|
||||
|
Reference in New Issue
Block a user