Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic descriptions support #413

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -45,25 +46,72 @@
//Future: [Authorize(Roles = Globals.ROLE_MEDIA_WORKER + "," + Globals.ROLE_ADMIN)]
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 @@
return video.PhraseHints ?? "";
}



[HttpGet("GetSceneData")]
public async Task<ActionResult<Object>> GetSceneData(string videoId) {
Video video = await _context.Videos.FindAsync(videoId);
Expand All @@ -96,7 +146,7 @@
public async Task<ActionResult> UpdatePhraseHints(string videoId, PhraseHintsDTO phraseHintsDTO)
{
Video video = await _context.Videos.FindAsync(videoId);
string hints = phraseHintsDTO.PhraseHints ?? "";

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

View workflow job for this annotation

GitHub Actions / Build

In externally visible method 'Task<ActionResult> TaskController.UpdatePhraseHints(string videoId, PhraseHintsDTO phraseHintsDTO)', validate parameter 'phraseHintsDTO' 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.

if(video.HasPhraseHints()) {
TextData data = await _context.TextData.FindAsync(video.PhraseHintsDataId);
Expand All @@ -119,7 +169,7 @@
//Future: [Authorize(Roles = Globals.ROLE_MEDIA_WORKER + "," + Globals.ROLE_ADMIN)]
public async Task<ActionResult> UpdateGlossary(string videoId, JObject glossary)
{
string glossaryAsString = glossary.ToString(0);

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

View workflow job for this annotation

GitHub Actions / Build

In externally visible method 'Task<ActionResult> TaskController.UpdateGlossary(string videoId, JObject glossary)', validate parameter 'glossary' 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.HasGlossaryData())
{
Expand Down
Loading