Support for Ooona shot change file import - thx Eva :)

This commit is contained in:
niksedk 2023-09-06 22:56:10 +02:00
parent bbeb7e56c4
commit 9627fd713c

View File

@ -17,7 +17,7 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
{
public List<double> ShotChangesInSeconds = new List<double>();
private readonly double _frameRate = 25;
private readonly double _duration = 0;
private readonly double _duration;
private readonly string _videoFileName;
private bool _abort;
private bool _pause;
@ -88,7 +88,7 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
private void buttonOpenText_Click(object sender, EventArgs e)
{
openFileDialog1.Title = buttonOpenText.Text;
openFileDialog1.Filter = LanguageSettings.Current.ImportText.TextFiles + "|*.txt;*.shotchanges;*.xml;*.json" +
openFileDialog1.Filter = LanguageSettings.Current.ImportText.TextFiles + "|*.txt;*.shotchanges;*.xml;*.json;*.dat" +
"|Matroska xml chapter file|*.xml" +
"|EZTitles shotchanges XML file|*.xml" +
"|JSON shot changes file|*.json" +
@ -120,16 +120,24 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
return;
}
res = LoadFromJsonShotchangesFile(fileName);
res = LoadFromJsonShotChangesFile(fileName);
if (!string.IsNullOrEmpty(res))
{
textBoxIImport.Text = res;
radioButtonHHMMSSMS.Checked = true;
radioButtonSeconds.Checked = true;
return;
}
res = LoadFromJsonShotChangesFile2(fileName);
if (!string.IsNullOrEmpty(res))
{
textBoxIImport.Text = res;
radioButtonSeconds.Checked = true;
return;
}
var encoding = LanguageAutoDetect.GetEncodingFromFile(fileName);
string s = File.ReadAllText(fileName, encoding).Trim();
var s = File.ReadAllText(fileName, encoding).Trim();
if (s.Contains('.'))
{
radioButtonSeconds.Checked = true;
@ -143,7 +151,7 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
if (!s.Contains(Environment.NewLine) && s.Contains(';'))
{
var sb = new StringBuilder();
foreach (string line in s.Split(';'))
foreach (var line in s.Split(';'))
{
if (!string.IsNullOrWhiteSpace(line))
{
@ -163,7 +171,7 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
}
}
private string LoadFromMatroskaChapterFile(string fileName)
private static string LoadFromMatroskaChapterFile(string fileName)
{
try
{
@ -209,9 +217,13 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
{
foreach (XmlNode shotChange in xmlNodeList)
{
sb.AppendLine(shotChange.Attributes["frame"]?.InnerText);
if (shotChange.Attributes != null)
{
sb.AppendLine(shotChange.Attributes["frame"]?.InnerText);
}
}
}
return sb.ToString();
}
catch
@ -220,16 +232,16 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
}
}
private string LoadFromJsonShotchangesFile(string fileName)
private static string LoadFromJsonShotChangesFile(string fileName)
{
try
{
var text = FileUtil.ReadAllTextShared(fileName, Encoding.UTF8);
var list = new List<double>();
foreach (string line in text.Split(','))
foreach (var line in text.Split(','))
{
string s = line.Trim() + "}";
string start = Json.ReadTag(s, "frame_time");
var s = line.Trim() + "}";
var start = Json.ReadTag(s, "frame_time");
if (start != null)
{
if (double.TryParse(start, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var startSeconds))
@ -240,10 +252,11 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
}
var sb = new StringBuilder();
foreach (double ms in list.OrderBy(p => p))
foreach (var ms in list.OrderBy(p => p))
{
sb.AppendLine(new TimeCode(ms).ToShortStringHHMMSSFF());
}
return sb.ToString();
}
catch
@ -252,6 +265,36 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
}
}
private static string LoadFromJsonShotChangesFile2(string fileName)
{
try
{
var text = FileUtil.ReadAllTextShared(fileName, Encoding.UTF8);
var list = new List<double>();
var parser = new SeJsonParser();
var arr = parser.GetArrayElementsByName(text, "shotchanges");
foreach (var line in arr)
{
if (double.TryParse(line, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var startSeconds))
{
list.Add(startSeconds);
}
}
var sb = new StringBuilder();
foreach (var seconds in list.OrderBy(p => p))
{
sb.AppendLine(seconds.ToString(CultureInfo.InvariantCulture));
}
return sb.ToString();
}
catch
{
return null;
}
}
private static readonly char[] SplitChars = { ':', '.', ',' };
@ -265,9 +308,10 @@ namespace Nikse.SubtitleEdit.Forms.ShotChanges
else
{
ShotChangesInSeconds = new List<double>();
var useInvariantCulture = textBoxIImport.Text.Contains('.');
foreach (var line in lines)
{
if (double.TryParse(line, out var d))
if (double.TryParse(line, NumberStyles.AllowDecimalPoint, useInvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.CurrentUICulture, out var d))
{
if (radioButtonFrames.Checked)
{