diff --git a/ClassTranscribeDatabase/CaptionQueries.cs b/ClassTranscribeDatabase/CaptionQueries.cs index df9d417..cf3e8a1 100644 --- a/ClassTranscribeDatabase/CaptionQueries.cs +++ b/ClassTranscribeDatabase/CaptionQueries.cs @@ -21,11 +21,11 @@ public CaptionQueries(CTDbContext context) /// Get the captions for a given videoId /// /// Language of the captions to fetch. - public async Task> GetCaptionsAsync(string videoId, string language = "en-US") + public async Task> GetCaptionsAsync(string videoId, string sourceInternalRef, string language) // = "en-US" { try { - var transcriptionId = _context.Transcriptions.Where(t => t.Language == language && t.VideoId == videoId + var transcriptionId = _context.Transcriptions.Where(t => t.Language == language && t.VideoId == videoId && t.SourceInternalRef== sourceInternalRef && t.TranscriptionType == TranscriptionType.Caption).First().Id; return await GetCaptionsAsync(transcriptionId); } diff --git a/ClassTranscribeServer/Controllers/EPubsController.cs b/ClassTranscribeServer/Controllers/EPubsController.cs index bdc48e6..87b6129 100644 --- a/ClassTranscribeServer/Controllers/EPubsController.cs +++ b/ClassTranscribeServer/Controllers/EPubsController.cs @@ -104,8 +104,9 @@ public async Task>> GetEpubData(string mediaId, SourceType = ResourceType.Media, SourceId = mediaId }; - - var captions = await _captionQueries.GetCaptionsAsync(media.VideoId, epub.Language); + const string SOURCEINTERNALREF= "ClassTranscribe/Azure"; // Do not change me; this is a key inside the database + // to indicate the source of the captions was this code + var captions = await _captionQueries.GetCaptionsAsync(media.VideoId, SOURCEINTERNALREF, epub.Language); _logger.LogInformation($"GetEpubData({mediaId}) - returning combined SceneData"); return GetSceneData(sceneArray, captions); diff --git a/TaskEngine/Tasks/TranscriptionTask.cs b/TaskEngine/Tasks/TranscriptionTask.cs index 8d28538..397e3df 100644 --- a/TaskEngine/Tasks/TranscriptionTask.cs +++ b/TaskEngine/Tasks/TranscriptionTask.cs @@ -100,7 +100,9 @@ protected async override Task OnConsume(string videoId, TaskParameters taskParam { buildMockCaptions(videoId); } - + const string SOURCEINTERNALREF= "ClassTranscribe/Azure"; // Do not change me; this is a key inside the database + // to indicate the source of the captions was this code + using (var _context = CTDbContext.CreateDbContext()) { @@ -165,10 +167,10 @@ protected async override Task OnConsume(string videoId, TaskParameters taskParam foreach (string language in allLanguages) { - var existing = await _captionQueries.GetCaptionsAsync(video.Id, language); + var existing = await _captionQueries.GetCaptionsAsync(video.Id, SOURCEINTERNALREF, language); captionsMap[language] = existing; - startAfterMap[language] = TimeSpan.Zero; + startAfterMap[language] = TimeSpan.Zero; if (existing.Any()) { TimeSpan lastCaptionTime = existing.Select(c => c.End).Max(); @@ -196,10 +198,9 @@ protected async override Task OnConsume(string videoId, TaskParameters taskParam { var theLanguage = captionsInLanguage.Key; var theCaptions = captionsInLanguage.Value; - - if (theCaptions.Any()) + if (theCaptions.Count>0) { - var t = _context.Transcriptions.SingleOrDefault(t => t.VideoId == video.Id && t.Language == theLanguage); + var t = _context.Transcriptions.SingleOrDefault(t => t.VideoId == video.Id && t.SourceInternalRef == SOURCEINTERNALREF && t.Language == theLanguage && t.TranscriptionType == TranscriptionType.Caption); GetLogger().LogInformation($"Find Existing Transcriptions null={t == null}"); // Did we get the default or an existing Transcription entity? if (t == null) @@ -211,7 +212,7 @@ protected async override Task OnConsume(string videoId, TaskParameters taskParam Language = theLanguage, VideoId = video.Id, Label = $"{theLanguage} (ClassTranscribe)", - SourceInternalRef = "ClassTranscribe/Azure", + SourceInternalRef = SOURCEINTERNALREF, // SourceLabel = "ClassTranscribe (Azure" + (phraseHints.Length>0 ?" with phrase hints)" : ")") }; _context.Add(t);