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()); + /// /// 鏃堕棿杞村悎璁 ///