接口做兼容处理,避免直接报错。

This commit is contained in:
Hommy
2026-06-11 11:03:32 +08:00
parent 2e84844440
commit 24266334c8
+23
View File
@@ -1,3 +1,16 @@
# Copyright 2024 Hommy <taohongmin@sina.cn>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from typing import List, Dict, Any, Tuple, Optional, Literal
import asyncio
@@ -818,6 +831,16 @@ def parse_captions_data(json_str: str) -> List[Dict[str, Any]]:
if not isinstance(processed_item["end"], (int, float)) or processed_item["end"] <= processed_item["start"]:
logger.error(f"the {i}th item has invalid end time: {processed_item['end']}")
raise CustomException(CustomError.INVALID_CAPTION_INFO, f"the {i}th item has invalid end time")
# 将时间转换为整数(微秒),兼容 start/end 为小数的情况
processed_item["start"] = int(processed_item["start"])
processed_item["end"] = int(processed_item["end"])
if processed_item["end"] <= processed_item["start"]:
logger.error(
f"the {i}th item has invalid end time after int conversion: "
f"start={processed_item['start']}, end={processed_item['end']}"
)
raise CustomException(CustomError.INVALID_CAPTION_INFO, f"the {i}th item has invalid end time")
if not isinstance(processed_item["text"], str) or len(processed_item["text"].strip()) == 0:
logger.error(f"the {i}th item has invalid text: {processed_item['text']}")