From 07e695c94578abb3565d85f7e0d36ebe9f816fbd Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Mon, 18 Apr 2022 09:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0prod=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 4 ++++ controller/api/config_blueprint.py | 9 ++++++++- workflow/video.py | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 7a01e6f..dd77983 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,9 @@ import configparser import os.path +from flask.helpers import get_env + + +PROD_ENV = get_env() == "production" # [danmaku] # exec diff --git a/controller/api/config_blueprint.py b/controller/api/config_blueprint.py index 5fa4303..bb5d9ff 100644 --- a/controller/api/config_blueprint.py +++ b/controller/api/config_blueprint.py @@ -1,6 +1,6 @@ from flask import Blueprint, jsonify, request -from config import get_config, write_config, load_config +from config import get_config, write_config, load_config, PROD_ENV blueprint = Blueprint("api_config", __name__, url_prefix="/api/config") @@ -10,6 +10,13 @@ def get_global_config(): return jsonify(get_config()) +@blueprint.get("/env") +def get_current_env(): + return jsonify({ + "prod": PROD_ENV + }) + + @blueprint.put("/") def modify_global_config(): return jsonify(request.json) diff --git a/workflow/video.py b/workflow/video.py index e3efe4f..8715958 100644 --- a/workflow/video.py +++ b/workflow/video.py @@ -4,7 +4,7 @@ import subprocess from datetime import datetime, timedelta from typing import IO -from config import FFMPEG_EXEC, VIDEO_BITRATE, FFMPEG_USE_GPU, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC +from config import FFMPEG_EXEC, VIDEO_BITRATE, FFMPEG_USE_GPU, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC, PROD_ENV def get_video_real_duration(filename): @@ -33,6 +33,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi new_filename ], stdout=subprocess.PIPE) handle_ffmpeg_output(encode_process.stdout) + return encode_process.wait() def handle_ffmpeg_output(stderr: IO[bytes]) -> None: @@ -40,6 +41,9 @@ def handle_ffmpeg_output(stderr: IO[bytes]) -> None: line = stderr.readline() if line == b"": break + if PROD_ENV: + # 正式环境不要输出一大堆的东西了 + continue if line.startswith(b"out_time="): cur_time = line.replace(b"out_time=", b"").decode() print("CurTime", cur_time.strip())