diff --git a/ClassTranscribeServer/Controllers/MediaController.cs b/ClassTranscribeServer/Controllers/MediaController.cs index 8e7002b..9a98125 100644 --- a/ClassTranscribeServer/Controllers/MediaController.cs +++ b/ClassTranscribeServer/Controllers/MediaController.cs @@ -76,7 +76,9 @@ public async Task> GetMedia(string id) { Id = t.Id, Path = t.File != null ? t.File.Path : null, - Language = t.Language + Language = t.Language, + TranscriptionType = (int) t.TranscriptionType, + Label = String.IsNullOrWhiteSpace( t.Label ) ? "" : t.Label }).ToList(), Video = new VideoDTO { diff --git a/ClassTranscribeServer/Controllers/PlaylistsController.cs b/ClassTranscribeServer/Controllers/PlaylistsController.cs index 27c3d1e..4c19629 100644 --- a/ClassTranscribeServer/Controllers/PlaylistsController.cs +++ b/ClassTranscribeServer/Controllers/PlaylistsController.cs @@ -169,7 +169,11 @@ public async Task>> GetPlaylists2(string o Id = t.Id, Path = t.File != null ? t.File.Path : null, SrtPath = t.SrtFile != null ? t.SrtFile.Path : null, - Language = t.Language + Language = t.Language, + Label = t.Label, + SourceLabel = t.SourceLabel, + TranscriptionType = (int) t.TranscriptionType + }).ToList() }).ToList() }).ToList(); @@ -453,6 +457,11 @@ public class TranscriptionDTO public string Path { get; set; } public string SrtPath { get; set; } + public int TranscriptionType { get; set; } // 0=Caption 1=Description + + public String Label { get; set; } + + public String SourceLabel { get; set; } // where did this transcription originate? public string Language { get; set; } } diff --git a/ClassTranscribeServer/Controllers/TaskController.cs b/ClassTranscribeServer/Controllers/TaskController.cs index a10d547..f519446 100644 --- a/ClassTranscribeServer/Controllers/TaskController.cs +++ b/ClassTranscribeServer/Controllers/TaskController.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using static ClassTranscribeDatabase.CommonUtils; namespace ClassTranscribeServer.Controllers { @@ -47,23 +48,70 @@ public async Task UpdateSceneData(string videoId, JObject scene) { string sceneAsString = scene.ToString(0); Video video = await _context.Videos.FindAsync(videoId); - if(video.HasSceneObjectData()) + var existingScenes = video.HasSceneObjectData(); + + TextData data; + if (existingScenes) { - TextData data = await _context.TextData.FindAsync(video.SceneObjectDataId); + data = await _context.TextData.FindAsync(video.SceneObjectDataId); data.Text = sceneAsString; } else { - TextData data = new TextData(); - data.Text = sceneAsString; + data = new TextData() { Text = sceneAsString }; _context.TextData.Add(data); video.SceneObjectDataId = data.Id; Trace.Assert(!string.IsNullOrEmpty(data.Id)); } - + + createDescriptionsIfNone(video, data); await _context.SaveChangesAsync(); return Ok(); } - [HttpGet("GetPhraseHints")] + private void createDescriptionsIfNone(Video v, TextData scenedata) + { + JArray scenes = scenedata.getAsJSON()["Scenes"] as JArray; + if (scenes == null || v == null || v.Id == null) + { + return; + } + + var exists = v.Transcriptions.Exists(t=>t.TranscriptionType == TranscriptionType.TextDescription); + if(exists) + { + _logger.LogInformation($"{v.Id}: already has descriptions (skipping)"); + return; + } + _logger.LogInformation($"{v.Id}: Creating basic descriptions"); + var captions = new List(); + + int index = 0; + foreach (JObject scene in scenes) + { + var c = new Caption + { + Index = index++, + Begin = TimeSpan.Parse(scene["start"].ToString()), + End = TimeSpan.Parse(scene["end"].ToString()), + CaptionType = CaptionType.AudioDescription, + Text = scene["phrases"]?.ToString() + }; + } + _logger.LogInformation($"{v.Id}: {index} entries added"); + var transcription = new Transcription() + { + Captions = captions, + TranscriptionType = TranscriptionType.TextDescription, + VideoId = v.Id, + Language = Languages.ENGLISH_AMERICAN, + Label = "Description", + SourceLabel = "ClassTranscribe", + SourceInternalRef = "ClassTranscribe/Scene-OCR" + }; + + _context.Add(transcription); + } + + [HttpGet("GetPhraseHints")] public async Task GetPhraseHints(string videoId) { Video video = await _context.Videos.FindAsync(videoId); if(video.HasPhraseHints()) { @@ -74,6 +122,8 @@ public async Task GetPhraseHints(string videoId) { return video.PhraseHints ?? ""; } + + [HttpGet("GetSceneData")] public async Task> GetSceneData(string videoId) { Video video = await _context.Videos.FindAsync(videoId);