Improve unknown json format parser- thx CB :)

This commit is contained in:
Nikolaj Olsson 2024-07-28 18:05:39 +02:00
parent f402c3c2dd
commit 9ee39eb029
3 changed files with 36 additions and 16 deletions

View File

@ -163,11 +163,19 @@ namespace Nikse.SubtitleEdit.Core.Common
{
start = DecodeFormatToSeconds(start);
}
else if (start != null && start.Contains(":") && start.Length == 8 && start.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries).Length == 3)
{
start = DecodeFormatHourMinuteSecondsToSeconds(start);
}
if (end != null && end.Contains(":") && end.Length >= 11 && end.Length <= 12 && end.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries).Length == 4)
{
end = DecodeFormatToSeconds(end);
}
else if (end != null && end.Contains(":") && end.Length == 8 && end.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries).Length == 3)
{
end = DecodeFormatHourMinuteSecondsToSeconds(end);
}
if (start != null && end != null && text != null)
{
@ -199,11 +207,16 @@ namespace Nikse.SubtitleEdit.Core.Common
return (ms / TimeCode.BaseUnit).ToString(CultureInfo.InvariantCulture);
}
private static string DecodeFormatHourMinuteSecondsToSeconds(string s)
{
return DecodeFormatToSeconds(s + ":00");
}
private static string ReadStartTag(string s)
{
return ReadFirstMultiTag(s, new[]
{
"start", "in",
"start", "in", "begin",
"startTime", "start_time", "starttime",
"startMillis", "start_Millis", "startmillis",
"startMs", "start_ms", "startms",

View File

@ -140,19 +140,19 @@
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.deleteToolStripMenuItem.Text = "Delete";
this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator2.Size = new System.Drawing.Size(168, 6);
//
// addFilesToolStripMenuItem
//
this.addFilesToolStripMenuItem.Name = "addFilesToolStripMenuItem";
this.addFilesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.addFilesToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.addFilesToolStripMenuItem.Text = "Add subtitle files...";
this.addFilesToolStripMenuItem.Click += new System.EventHandler(this.addFilesToolStripMenuItem_Click);
//
@ -168,31 +168,31 @@
this.deleteToolStripMenuItem,
this.clearToolStripMenuItem});
this.contextMenuStripBatch.Name = "contextMenuStripBatch";
this.contextMenuStripBatch.Size = new System.Drawing.Size(181, 148);
this.contextMenuStripBatch.Size = new System.Drawing.Size(172, 126);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator1.Size = new System.Drawing.Size(168, 6);
//
// pickVideoFileToolStripMenuItem
//
this.pickVideoFileToolStripMenuItem.Name = "pickVideoFileToolStripMenuItem";
this.pickVideoFileToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.pickVideoFileToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.pickVideoFileToolStripMenuItem.Text = "Pick video file...";
this.pickVideoFileToolStripMenuItem.Click += new System.EventHandler(this.pickVideoFileToolStripMenuItem_Click);
//
// removeVideoFileToolStripMenuItem
//
this.removeVideoFileToolStripMenuItem.Name = "removeVideoFileToolStripMenuItem";
this.removeVideoFileToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.removeVideoFileToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.removeVideoFileToolStripMenuItem.Text = "Remove video file";
this.removeVideoFileToolStripMenuItem.Click += new System.EventHandler(this.removeVideoFileToolStripMenuItem_Click);
//
// clearToolStripMenuItem
//
this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
this.clearToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.clearToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.clearToolStripMenuItem.Text = "Clear";
this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
//
@ -1441,6 +1441,7 @@
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "GenerateTransparentVideoWithSubtitles";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GenerateTransparentVideoWithSubtitles_FormClosing);
this.Shown += new System.EventHandler(this.GenerateTransparentVideoWithSubtitles_Shown);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GenerateTransparentVideoWithSubtitles_KeyDown);
this.contextMenuStripBatch.ResumeLayout(false);
this.contextMenuStripRes.ResumeLayout(false);

View File

@ -3,7 +3,6 @@ using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
@ -116,12 +115,6 @@ namespace Nikse.SubtitleEdit.Forms
checkBoxAlignRight.Checked = Configuration.Settings.Tools.GenVideoNonAssaAlignRight;
checkBoxRightToLeft.Checked = Configuration.Settings.Tools.GenVideoNonAssaAlignRight;
if (_videoInfo != null)
{
numericUpDownWidth.Value = _videoInfo.Width;
numericUpDownHeight.Value = _videoInfo.Height;
}
var left = Math.Max(Math.Max(labelResolution.Left + labelResolution.Width, labelFontSize.Left + labelFontSize.Width), labelSubtitleFont.Left + labelSubtitleFont.Width) + 5;
numericUpDownFontSize.Left = left;
comboBoxSubtitleFont.Left = left;
@ -1720,6 +1713,19 @@ namespace Nikse.SubtitleEdit.Forms
_batchItems[i].Height = 0;
}
}
private void GenerateTransparentVideoWithSubtitles_Shown(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(_inputVideoFileName))
{
var mediaInfo = FfmpegMediaInfo.Parse(_inputVideoFileName);
if (mediaInfo.Dimension.IsValid())
{
numericUpDownWidth.Value = mediaInfo.Dimension.Width;
numericUpDownHeight.Value = mediaInfo.Dimension.Height;
}
}
}
}
}