fix FastAPI模型FFMPEGSubtitleOverlayRequest解析后没有返回Self以及可选参数没有给default值

This commit is contained in:
shuohigh@gmail.com
2025-06-24 13:53:40 +08:00
parent d37da25a82
commit 39044f22dc
5 changed files with 26 additions and 19 deletions

View File

@@ -111,22 +111,17 @@ class FFMPEGTestCase(unittest.IsolatedAsyncioTestCase):
async def test_ffmpeg_slice_stream(self):
from pydantic import TypeAdapter
# #EXT-X-PROGRAM-DATE-TIME:2025-06-23T06:20:30.720+0000
# #EXT-X-PROGRAM-DATE-TIME:2025-06-23T10:09:38.476+0000
stream_url = "https://cdn.roasmax.cn/test/records/hls/fc-01JXY1AS1HDGS300EQ54ATAKHF/playlist.m3u8"
# stream_url = "https://cdn.roasmax.cn/test/records/hls/fc-01JXY1AS1HDGS300EQ54ATAKHF/playlist.m3u8"
stream_url = "https://cdn.roasmax.cn/test/records/hls/fc-01JYDQ3RVMPAEKMYHA0HQ14WAJ/playlist.m3u8"
adapter = TypeAdapter(List[FFMpegSliceSegment])
segments = adapter.validate_json("""[
{
"start": 920.425,
"end": 921.688
},
{
"start": 922.425,
"end": 923.688
},
{
"start": 940.425,
"end": 941.688
}
"start": 12600,
"end": 13500
}
]""")
for segment in segments:
logger.info(f"{segment.start.toFormatStr()} --> {segment.end.toFormatStr()}")

View File

@@ -3,6 +3,7 @@ import unittest
import httpx
from loguru import logger
from BowongModalFunctions.models.web_model import FFMPEGSubtitleOverlayRequest
class PydanticModelTestCase(unittest.TestCase):
@@ -25,6 +26,14 @@ class PydanticModelTestCase(unittest.TestCase):
logger.info(f"Login response: {session_json}")
self.assertEqual(True, True)
def test_subtitle_apply(self):
subtitle_apply_input = """
{\"media\": \"s3://ap-northeast-2/modal-media-cache/test/bgm_nosie_reduce/outputs/fc-01JYG6NVQ1AEJMARECGN8FXDYH/output.mp4\",\n \"subtitle\": \"s3://ap-northeast-2/modal-media-cache/upload/2d5e2674-2c03-4a83-a589-3dce96003470/1183fed3-770d-4ded-a314-ef47c37d84d7.ass\",\n \"fonts\": [\n \"s3://ap-northeast-2/modal-media-cache/upload/test/fonts/荆南俊俊体.ttf\"\n ]}
"""
request = FFMPEGSubtitleOverlayRequest.model_validate_json(subtitle_apply_input)
logger.info(f"request = {request.model_dump_json(indent=2, exclude_none=True)}")
if __name__ == '__main__':
unittest.main()