Add PodcastIndexer json - thx rjgout :)

Related to  #8522
This commit is contained in:
Nikolaj Olsson 2024-06-13 19:25:46 +02:00
parent ceac0eee80
commit 172900a247
4 changed files with 101 additions and 0 deletions

View File

@ -3175,6 +3175,7 @@ Continue?</RestoreDefaultSettingsMsg>
<MergingAudioTrackXOfY>Merging audio track: {0} / {1}...</MergingAudioTrackXOfY>
<GeneratingSpeechFromTextXOfY>Generating speech from text: {0} / {1}...</GeneratingSpeechFromTextXOfY>
<ReviewAudioClips>Review audio clips</ReviewAudioClips>
<CustomAudioEncoding>Custom audio encoding</CustomAudioEncoding>
<ReviewInfo>Review and edit/remove audio clips</ReviewInfo>
<Play>Play</Play>
<AutoContinue>Auto-continue</AutoContinue>

View File

@ -0,0 +1,96 @@
using Nikse.SubtitleEdit.Core.Common;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class PodcastIndexer : SubtitleFormat
{
public override string Extension => ".json";
public override string Name => "PodcastIndexer";
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder("{" +
Environment.NewLine + " \"version\": \"1.0.0\"" +
Environment.NewLine + " \"segments\": [");
var count = 0;
foreach (var p in subtitle.Paragraphs)
{
if (count > 0)
{
sb.Append(',');
}
count++;
sb.AppendLine();
sb.AppendLine(" {");
if (!string.IsNullOrEmpty(p.Actor))
{
sb.AppendLine($" \"speaker\": \"{p.Actor}\"");
}
sb.AppendLine($" \"startTime\": {p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture)},");
sb.AppendLine($" \"endTime\": {p.EndTime.TotalSeconds.ToString(CultureInfo.InvariantCulture)},");
sb.AppendLine($" \"body\": \"{Json.EncodeJsonText(p.Text, "\\n")}\"");
sb.Append(" }");
}
sb.Append(" ]" + Environment.NewLine + "}");
return sb.ToString().Trim();
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
var sb = new StringBuilder();
foreach (var s in lines)
{
sb.Append(s);
}
var text = sb.ToString().TrimStart();
if (!text.Contains("\"segments\"", StringComparison.Ordinal))
{
return;
}
var parser = new SeJsonParser();
var words = parser.GetArrayElementsByName(text, "segments");
foreach (var word in words)
{
var startTimeObject = parser.GetFirstObject(word, "startTime");
var endTimeObject = parser.GetFirstObject(word, "endTime");
var actorObject = parser.GetFirstObject(word, "speaker");
var s = parser.GetFirstObject(word, "body");
if (!string.IsNullOrEmpty(s) && !string.IsNullOrEmpty(startTimeObject) && !string.IsNullOrEmpty(endTimeObject))
{
if (double.TryParse(startTimeObject, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var startSecs) &&
double.TryParse(endTimeObject, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var endSecs))
{
var pText = Json.DecodeJsonText(s);
var p = new Paragraph(pText, startSecs * 1000.0, endSecs * 1000.0);
if (!string.IsNullOrEmpty(actorObject))
{
p.Actor = actorObject;
}
subtitle.Paragraphs.Add(p);
}
else
{
_errorCount++;
}
}
}
subtitle.Renumber();
}
}
}

View File

@ -177,6 +177,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
new PhoenixSubtitle(),
new PinnacleImpression(),
new PListCaption(),
new PodcastIndexer(),
new ProjectionSubtitleList(),
new QubeMasterImport(),
new QuickTimeText(),

View File

@ -8707,6 +8707,9 @@ namespace Nikse.SubtitleEdit.Logic
case "TextToSpeech/ReviewAudioClips":
language.TextToSpeech.ReviewAudioClips = reader.Value;
break;
case "TextToSpeech/CustomAudioEncoding":
language.TextToSpeech.CustomAudioEncoding = reader.Value;
break;
case "TextToSpeech/ReviewInfo":
language.TextToSpeech.ReviewInfo = reader.Value;
break;