59 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import threading
from queue import SimpleQueue as Queue
from time import sleep
from model.Workflow import Workflow
from workflow.video import quick_split_video
from workflow.worker import do_workflow
from . import LOGGER
IS_LIVING = threading.Event()
IS_ENCODING = threading.Event()
IS_UPLOADING = threading.Event()
ENCODING_QUEUE: "Queue[Workflow]" = Queue()
class Bilibili(threading.Thread):
def __init__(self) -> None:
super().__init__()
self.parts = []
def run(self) -> None:
while True:
if ENCODING_QUEUE.empty():
sleep(5)
if len(self.parts) > 0 and not IS_UPLOADING.is_set():
self.do_upload()
else:
workflow_item = ENCODING_QUEUE.get()
LOGGER.info("收到工作流请求ID:【{}".format(workflow_item.id))
for video_clip in workflow_item.video_clips:
IS_ENCODING.set()
try:
LOGGER.info("工作流视频ID{}】,路径:【{}".format(video_clip.id, video_clip.full_path))
if len(video_clip.danmaku_clips) < 1:
_parts = quick_split_video(video_clip.full_path)
else:
_parts = do_workflow(video_clip.full_path, video_clip.danmaku_clips[0].full_path)
LOGGER.info("工作流视频压制完成:结果:【{}".format(_parts))
for _part in _parts:
self.parts.append(_part)
except:
LOGGER.error("压制异常工作流视频ID{}】,路径:【{}".format(video_clip.id, video_clip.full_path))
finally:
IS_ENCODING.clear()
def do_upload(self):
LOGGER.info("尝试投稿:内容【{}".format(self.parts))
self.clear()
def clear(self):
self.parts = []
INSTANCE = Bilibili()