130 lines
5.2 KiB
C#
130 lines
5.2 KiB
C#
using AntDesign;
|
|
using AntDesign.TableModels;
|
|
using FFmpeg.NET.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
|
using Microsoft.JSInterop;
|
|
using SqlSugar;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
using VideoAnalysisCore.AICore.GPT.Dto;
|
|
using VideoAnalysisCore.AICore.SherpaOnnx;
|
|
using VideoAnalysisCore.Common;
|
|
using VideoAnalysisCore.Model.Enum;
|
|
using VideoAnalysisCore.Model;
|
|
using VideoAnalysisCore.Model.Dto;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
using System.Text.Json;
|
|
|
|
namespace Learn.VideoAnalysis.Components.Pages
|
|
{
|
|
public partial class VideoTaskShow : ComponentBase
|
|
{
|
|
/// <summary>
|
|
/// 任务id
|
|
/// </summary>
|
|
[Parameter]
|
|
public long? taskId { get; set; }
|
|
[Inject] private ConfirmService ComfirmService { get; set; } = default!;
|
|
[Inject] private IHttpContextAccessor HttpContext { get; set; } = default!;
|
|
[Inject] private Repository<VideoTask> taskDB { get; set; } = default!;
|
|
[Inject] private Repository<VideoQuestion> videoQuestionDB { get; set; } = default!;
|
|
[Inject] private Repository<VideoQuestionKonw> videoQuestionKonwDB { get; set; } = default!;
|
|
[Inject] private Repository<VideoKonwPoint> videoKonwPointDB { get; set; } = default!;
|
|
[Inject] private RedisManager redisManager { get; set; } = default!;
|
|
[Inject] private IJSRuntime JSRuntime { get; set; } = default!;
|
|
|
|
private VideoTask nowTask { get; set; } = default!;
|
|
private string videoPath { get; set; } = default!;
|
|
|
|
/// <summary>
|
|
/// 分段
|
|
/// </summary>
|
|
private VideoKnowRes[] videoKnows { get; set; } = default!;
|
|
/// <summary>
|
|
/// 在渲染页面之后
|
|
/// </summary>
|
|
/// <param name="firstRender"></param>
|
|
/// <returns></returns>
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
}
|
|
|
|
|
|
}
|
|
public string getF(VideoKnowRes segment)
|
|
{
|
|
var sf = ((int)((segment.StartTime ?? 0) / 60)).ToString().PadLeft(2, '0');
|
|
var sm = ((int)((segment.StartTime ?? 0) % 60)).ToString().PadLeft(2, '0');
|
|
return $"{sf}:{sm}";
|
|
//var ef = ((int)((segment.EndTime ?? 0) / 60)).ToString().PadLeft(2, '0');
|
|
//var em = ((int)((segment.EndTime ?? 0) % 60)).ToString().PadLeft(2, '0');
|
|
//return $"{sf}:{sm} - {ef}: {em}";
|
|
}
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
protected override async void OnInitialized()
|
|
{
|
|
if (this.taskId is null)
|
|
return;
|
|
long taskId = this.taskId.Value;
|
|
nowTask = await taskDB.GetFirstAsync(s => s.Id == taskId);
|
|
if (nowTask is null)
|
|
return;
|
|
var captionsArr = JsonSerializer.Deserialize<SenseVoiceRes[]>(nowTask.Captions);
|
|
var captionsArr1 = JsonSerializer.Deserialize<SenseVoiceRes[]>(nowTask.CaptionsAI??"[]") ;
|
|
redisManager.Redis.HMGet<SenseVoiceRes[]>(RedisExpandKey.Task(taskId), "Captions").FirstOrDefault();
|
|
|
|
var konwArr = await videoKonwPointDB.AsQueryable()
|
|
.Where(s => s.VideoTaskId == nowTask.Id)
|
|
.ToArrayAsync();
|
|
|
|
videoKnows = konwArr
|
|
.GroupBy(s => s.StartTime)
|
|
.Select(s => new VideoKnowRes()
|
|
{
|
|
Content = s.First().Content,
|
|
StartTime = s.First().StartTime,
|
|
EndTime = s.First().EndTime,
|
|
Theme = s.First().Theme,
|
|
StageId = s.First().StageId,
|
|
KnowPoint = string.Join(',', s.Select(x => x.KnowPoint))
|
|
}).ToArray();
|
|
videoPath = nowTask.MediaUrl; //AppCommon.GetVideoPath(nowTask.Id.ToString());
|
|
|
|
if (nowTask.VideoType == AttachmentsInfoType.复习)
|
|
{
|
|
var questionArr = await videoQuestionDB
|
|
.AsQueryable().Where(s => s.VideoTaskId == nowTask.Id)
|
|
.Select<VideoQuestionShowDto>()
|
|
.ToArrayAsync();
|
|
|
|
var konwDic = (await videoQuestionKonwDB
|
|
.AsQueryable().Where(s => s.VideoTaskId == nowTask.Id)
|
|
.ToArrayAsync()).GroupBy(s=>s.VideoQuestionId)
|
|
.ToDictionary(s=>s.Key);
|
|
foreach (var item in questionArr.Where(s=> konwDic.ContainsKey(s.Id)))
|
|
item.KonwArr = konwDic[item.Id].ToArray();
|
|
foreach (var item in videoKnows)
|
|
item.QuestionArr = questionArr
|
|
.Where(s => s.StageId == item.StageId).ToArray();
|
|
}
|
|
|
|
await JSRuntime
|
|
.InvokeVoidAsync("setDB", captionsArr, captionsArr1, videoKnows, videoPath);
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task<bool> Comfirm(string message)
|
|
{
|
|
return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes;
|
|
}
|
|
|
|
}
|
|
|
|
}
|