Skip to content

Commit 13a76fb

Browse files
committed
Automatic descriptions support
1 parent 2a7b4c4 commit 13a76fb

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

ClassTranscribeServer/Controllers/MediaController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public async Task<ActionResult<MediaDTO>> GetMedia(string id)
7676
{
7777
Id = t.Id,
7878
Path = t.File != null ? t.File.Path : null,
79-
Language = t.Language
79+
Language = t.Language,
80+
TranscriptionType = (int) t.TranscriptionType,
81+
Label = String.IsNullOrWhiteSpace( t.Label ) ? "" : t.Label
8082
}).ToList(),
8183
Video = new VideoDTO
8284
{

ClassTranscribeServer/Controllers/PlaylistsController.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ public async Task<ActionResult<IEnumerable<PlaylistDTO>>> GetPlaylists2(string o
169169
Id = t.Id,
170170
Path = t.File != null ? t.File.Path : null,
171171
SrtPath = t.SrtFile != null ? t.SrtFile.Path : null,
172-
Language = t.Language
172+
Language = t.Language,
173+
Label = t.Label,
174+
SourceLabel = t.SourceLabel,
175+
TranscriptionType = (int) t.TranscriptionType
176+
173177
}).ToList()
174178
}).ToList()
175179
}).ToList();
@@ -453,6 +457,11 @@ public class TranscriptionDTO
453457
public string Path { get; set; }
454458
public string SrtPath { get; set; }
455459

460+
public int TranscriptionType { get; set; } // 0=Caption 1=Description
461+
462+
public String Label { get; set; }
463+
464+
public String SourceLabel { get; set; } // where did this transcription originate?
456465
public string Language { get; set; }
457466
}
458467

ClassTranscribeServer/Controllers/TaskController.cs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Linq;
1212
using System.Text;
1313
using System.Threading.Tasks;
14+
using static ClassTranscribeDatabase.CommonUtils;
1415

1516
namespace ClassTranscribeServer.Controllers
1617
{
@@ -47,23 +48,70 @@ public async Task<ActionResult> UpdateSceneData(string videoId, JObject scene)
4748
{
4849
string sceneAsString = scene.ToString(0);
4950
Video video = await _context.Videos.FindAsync(videoId);
50-
if(video.HasSceneObjectData())
51+
var existingScenes = video.HasSceneObjectData();
52+
53+
TextData data;
54+
if (existingScenes)
5155
{
52-
TextData data = await _context.TextData.FindAsync(video.SceneObjectDataId);
56+
data = await _context.TextData.FindAsync(video.SceneObjectDataId);
5357
data.Text = sceneAsString;
5458
} else
5559
{
56-
TextData data = new TextData();
57-
data.Text = sceneAsString;
60+
data = new TextData() { Text = sceneAsString };
5861
_context.TextData.Add(data);
5962
video.SceneObjectDataId = data.Id;
6063
Trace.Assert(!string.IsNullOrEmpty(data.Id));
6164
}
62-
65+
66+
createDescriptionsIfNone(video, data);
6367
await _context.SaveChangesAsync();
6468
return Ok();
6569
}
66-
[HttpGet("GetPhraseHints")]
70+
private void createDescriptionsIfNone(Video v, TextData scenedata)
71+
{
72+
JArray scenes = scenedata.getAsJSON()["Scenes"] as JArray;
73+
if (scenes == null || v == null || v.Id == null)
74+
{
75+
return;
76+
}
77+
78+
var exists = v.Transcriptions.Exists(t=>t.TranscriptionType == TranscriptionType.TextDescription);
79+
if(exists)
80+
{
81+
_logger.LogInformation($"{v.Id}: already has descriptions (skipping)");
82+
return;
83+
}
84+
_logger.LogInformation($"{v.Id}: Creating basic descriptions");
85+
var captions = new List<Caption>();
86+
87+
int index = 0;
88+
foreach (JObject scene in scenes)
89+
{
90+
var c = new Caption
91+
{
92+
Index = index++,
93+
Begin = TimeSpan.Parse(scene["start"].ToString()),
94+
End = TimeSpan.Parse(scene["end"].ToString()),
95+
CaptionType = CaptionType.AudioDescription,
96+
Text = scene["phrases"]?.ToString()
97+
};
98+
}
99+
_logger.LogInformation($"{v.Id}: {index} entries added");
100+
var transcription = new Transcription()
101+
{
102+
Captions = captions,
103+
TranscriptionType = TranscriptionType.TextDescription,
104+
VideoId = v.Id,
105+
Language = Languages.ENGLISH_AMERICAN,
106+
Label = "Description",
107+
SourceLabel = "ClassTranscribe",
108+
SourceInternalRef = "ClassTranscribe/Scene-OCR"
109+
};
110+
111+
_context.Add(transcription);
112+
}
113+
114+
[HttpGet("GetPhraseHints")]
67115
public async Task<string> GetPhraseHints(string videoId) {
68116
Video video = await _context.Videos.FindAsync(videoId);
69117
if(video.HasPhraseHints()) {
@@ -74,6 +122,8 @@ public async Task<string> GetPhraseHints(string videoId) {
74122
return video.PhraseHints ?? "";
75123
}
76124

125+
126+
77127
[HttpGet("GetSceneData")]
78128
public async Task<ActionResult<Object>> GetSceneData(string videoId) {
79129
Video video = await _context.Videos.FindAsync(videoId);

0 commit comments

Comments
 (0)