Skip to content

Commit

Permalink
Automatic descriptions support
Browse files Browse the repository at this point in the history
  • Loading branch information
angrave committed Nov 8, 2023
1 parent 2a7b4c4 commit 13a76fb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
4 changes: 3 additions & 1 deletion ClassTranscribeServer/Controllers/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public async Task<ActionResult<MediaDTO>> 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
{
Expand Down
11 changes: 10 additions & 1 deletion ClassTranscribeServer/Controllers/PlaylistsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ public async Task<ActionResult<IEnumerable<PlaylistDTO>>> 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();
Expand Down Expand Up @@ -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; }
}

Expand Down
62 changes: 56 additions & 6 deletions ClassTranscribeServer/Controllers/TaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ClassTranscribeDatabase.CommonUtils;

namespace ClassTranscribeServer.Controllers
{
Expand Down Expand Up @@ -47,23 +48,70 @@ public async Task<ActionResult> UpdateSceneData(string videoId, JObject scene)
{
string sceneAsString = scene.ToString(0);

Check warning on line 49 in ClassTranscribeServer/Controllers/TaskController.cs

View workflow job for this annotation

GitHub Actions / Build

In externally visible method 'Task<ActionResult> TaskController.UpdateSceneData(string videoId, JObject scene)', validate parameter 'scene' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.
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<Caption>();

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<string> GetPhraseHints(string videoId) {
Video video = await _context.Videos.FindAsync(videoId);
if(video.HasPhraseHints()) {
Expand All @@ -74,6 +122,8 @@ public async Task<string> GetPhraseHints(string videoId) {
return video.PhraseHints ?? "";
}



[HttpGet("GetSceneData")]
public async Task<ActionResult<Object>> GetSceneData(string videoId) {
Video video = await _context.Videos.FindAsync(videoId);
Expand Down

0 comments on commit 13a76fb

Please sign in to comment.