From 5ff60df3d3486f7b4394c865b79005e657107065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Wed, 20 Nov 2024 18:19:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E4=BF=A1=E6=81=AF=20=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VideoAnalysis/Controllers/ApiController.cs | 56 +++++++++++++++------- VideoAnalysis/Controllers/Dto/ApiDto.cs | 1 + 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/VideoAnalysis/Controllers/ApiController.cs b/VideoAnalysis/Controllers/ApiController.cs index bfc9f8b..8aee9ad 100644 --- a/VideoAnalysis/Controllers/ApiController.cs +++ b/VideoAnalysis/Controllers/ApiController.cs @@ -79,16 +79,44 @@ namespace Learn.VideoAnalysis.Controllers return Ok(res); } + [NonAction] + private static List MergeTimeBases(IEnumerable timeBases) + { + if (timeBases == null || timeBases.Count() == 0) + { + return new List(); + } + var mergedList = new List(); + // 初始化合并段 + var current = timeBases.First(); + foreach (var next in timeBases) + { + // 如果类型相同,则扩展时间段 + if (current.TimeBaseType == next.TimeBaseType) + { + current.End = Math.Max(current.End, next.End); + } + else + { + // 类型不同,将当前时间段加入结果列表,并开始新时间段 + current.Content = string.Empty; + mergedList.Add(current); + current = next; + } + } + // 添加最后的时间段 + mergedList.Add(current); + return mergedList; + } - - /// - /// 获取视频信息taskId/tagId二选一 - /// - /// - /// 自定义id - /// 是否附加字幕 - /// - [HttpGet(Name = "TaskInfo")] + /// + /// 获取视频信息taskId/tagId二选一 + /// + /// + /// 自定义id + /// 是否附加字幕 + /// + [HttpGet(Name = "TaskInfo")] public async Task TaskInfo(long taskId,string? tagId,bool needSubtitle=false) { var task = await videoTaskDB.AsQueryable() @@ -104,15 +132,7 @@ namespace Learn.VideoAnalysis.Controllers if (task.LastEnum != RedisChannelEnum.EndTask) return BadRequest(taskData); if (!needSubtitle && taskData != null && taskData.TimeBase != null) - { - taskData.TimeBase = taskData.TimeBase - .Select(s => - { - s.Content = null; - return s; - }) - .ToArray(); - } + taskData.TimeBase = MergeTimeBases(taskData.TimeBase); return Ok(taskData); } diff --git a/VideoAnalysis/Controllers/Dto/ApiDto.cs b/VideoAnalysis/Controllers/Dto/ApiDto.cs index 35c9a35..b1634d8 100644 --- a/VideoAnalysis/Controllers/Dto/ApiDto.cs +++ b/VideoAnalysis/Controllers/Dto/ApiDto.cs @@ -74,6 +74,7 @@ namespace Learn.VideoAnalysis.Controllers.Dto Enum.GetValues(typeof(TimeBaseTypeEnum)) .Cast() .ToDictionary(x => (int)x, x => x.ToString()); + /// /// 鏃堕棿杞村悎璁 ///