mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Add new readonly json format - thx Filip :)
This commit is contained in:
parent
07e144458c
commit
6bf7e7e3c8
64
src/libse/SubtitleFormats/JsonTypeOnlyLoad3.cs
Normal file
64
src/libse/SubtitleFormats/JsonTypeOnlyLoad3.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Nikse.SubtitleEdit.Core.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
/// <summary>
|
||||
/// https://www.seriencamp-watchroom.tv
|
||||
/// </summary>
|
||||
public class JsonTypeOnlyLoad3 : SubtitleFormat
|
||||
{
|
||||
public override string Extension => ".json";
|
||||
|
||||
public override string Name => "JSON Type Only load 3";
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
return "Not implemented";
|
||||
}
|
||||
|
||||
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.IndexOf("captiondata", StringComparison.Ordinal) < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
subtitle.Paragraphs.Clear();
|
||||
var parser = new SeJsonParser();
|
||||
var captionDataAr = parser.GetArrayElementsByName(text, "captiondata");
|
||||
foreach (var captionData in captionDataAr)
|
||||
{
|
||||
var texts = parser.GetArrayElementsByName(captionData, "data");
|
||||
foreach (var textElement in texts)
|
||||
{
|
||||
var start = parser.GetFirstObject(textElement, "fromms");
|
||||
var end = parser.GetFirstObject(textElement, "toms");
|
||||
var caption = parser.GetFirstObject(textElement, "caption");
|
||||
if (!string.IsNullOrEmpty(caption) &&
|
||||
double.TryParse(start, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var startMs) &&
|
||||
double.TryParse(end, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var endMs))
|
||||
{
|
||||
caption = Json.DecodeJsonText(caption);
|
||||
caption = caption.Replace("<br />", Environment.NewLine);
|
||||
var p = new Paragraph(caption, startMs, endMs);
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subtitle.Renumber();
|
||||
}
|
||||
}
|
||||
}
|
@ -645,6 +645,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
new Wsb(),
|
||||
new JsonTypeOnlyLoad1(),
|
||||
new JsonTypeOnlyLoad2(),
|
||||
new JsonTypeOnlyLoad3(),
|
||||
new TranscriptiveJson(),
|
||||
new KaraokeCdgCreatorText(),
|
||||
new VidIcelandic(),
|
||||
|
Loading…
Reference in New Issue
Block a user