Merge branch 'SubtitleEdit:main' into master

This commit is contained in:
May Kittens Devour Your Soul 2023-11-22 14:28:37 +01:00 committed by GitHub
commit e359ff37f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 11 deletions

View File

@ -44,9 +44,14 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
var content = new StringContent(input, Encoding.UTF8);
content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var result = _httpClient.PostAsync(string.Empty, content).Result;
result.EnsureSuccessStatusCode();
var bytes = await result.Content.ReadAsByteArrayAsync();
var json = Encoding.UTF8.GetString(bytes).Trim();
if (!result.IsSuccessStatusCode)
{
SeLogger.Error("ChatGptTranslate failed calling API: Status code=" + result.StatusCode + Environment.NewLine + json);
}
result.EnsureSuccessStatusCode();
var parser = new SeJsonParser();
var resultText = parser.GetFirstObject(json, "content");

View File

@ -323,6 +323,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public int BinEditRightMargin { get; set; }
public string BinEditStartPosition { get; set; }
public string BinEditStartSize { get; set; }
public bool BinEditShowColumnGap { get; set; }
public bool FixCommonErrorsFixOverlapAllowEqualEndStart { get; set; }
public bool FixCommonErrorsSkipStepOne { get; set; }
public string ImportTextSplitting { get; set; }
@ -6094,6 +6095,12 @@ $HorzAlign = Center
settings.Tools.ExportPenLineJoin = subNode.InnerText;
}
subNode = node.SelectSingleNode("BinEditShowColumnGap");
if (subNode != null)
{
settings.Tools.BinEditShowColumnGap = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("FixCommonErrorsFixOverlapAllowEqualEndStart");
if (subNode != null)
{
@ -11713,6 +11720,7 @@ $HorzAlign = Center
textWriter.WriteElementString("ExportFullFrame", settings.Tools.ExportFullFrame.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("ExportFcpFullPathUrl", settings.Tools.ExportFcpFullPathUrl.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("ExportPenLineJoin", settings.Tools.ExportPenLineJoin);
textWriter.WriteElementString("BinEditShowColumnGap", settings.Tools.BinEditShowColumnGap.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("FixCommonErrorsFixOverlapAllowEqualEndStart", settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("FixCommonErrorsSkipStepOne", settings.Tools.FixCommonErrorsSkipStepOne.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("ImportTextSplitting", settings.Tools.ImportTextSplitting);

View File

@ -120,6 +120,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
</styling>
<layout>
<region xml:id='bottom' tts:backgroundColor='transparent' tts:showBackground='whenActive' tts:origin='10% 55%' tts:extent='80% 80%' tts:displayAlign='after' />
<region xml:id='centerCenter' tts:backgroundColor='transparent' tts:showBackground='whenActive' tts:origin='10% 32%' tts:extent='80% 80%' tts:displayAlign='center ' />
<region xml:id='top' tts:backgroundColor='transparent' tts:showBackground='whenActive' tts:origin='10% 10%' tts:extent='80% 80%' tts:displayAlign='before' />
</layout>
</head>
@ -149,8 +150,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
}
var div = xml.DocumentElement.SelectSingleNode("//ttml:body", nsmgr).SelectSingleNode("ttml:div", nsmgr);
bool hasBottomCenterRegion = false;
bool hasTopCenterRegion = false;
var hasBottomCenterRegion = false;
var hasTopCenterRegion = false;
var hasMiddleRegion = false;
foreach (XmlNode node in xml.DocumentElement.SelectNodes("//ttml:head/ttml:layout/ttml:region", nsmgr))
{
string id = null;
@ -172,6 +174,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
hasTopCenterRegion = true;
}
if (id != null && (id == "centerCenter" || id == "center"))
{
hasMiddleRegion = true;
}
}
foreach (var p in subtitle.Paragraphs)
@ -204,6 +211,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
paragraph.Attributes.Append(regionP);
}
}
else if (hasMiddleRegion && (text.StartsWith("{\\an5}", StringComparison.Ordinal) || text.StartsWith("{\\an6}", StringComparison.Ordinal) || text.StartsWith("{\\an7}", StringComparison.Ordinal)))
{
regionP.InnerText = "centerCenter";
paragraph.Attributes.Append(regionP);
}
else if (hasBottomCenterRegion)
{
regionP.InnerText = "bottom";

View File

@ -201,7 +201,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
" <region tts:extent=\"80% 40%\" tts:origin=\"10% 50%\" tts:displayAlign=\"after\" tts:textAlign=\"start\" xml:id=\"bottomLeft\" />" + Environment.NewLine +
// Middle column
" <region tts:extent=\"80% 40%\" tts:origin=\"10% 10%\" tts:displayAlign=\"before\" tts:textAlign=\"center\" xml:id=\"topCenter\" />" + Environment.NewLine +
" <region tts:extent=\"80% 40%\" tts:origin=\"10% 30%\" tts:displayAlign=\"center\" tts:textAlign=\"center\" xml:id=\"centerСenter\" />" + Environment.NewLine +
" <region tts:extent=\"80% 40%\" tts:origin=\"10% 30%\" tts:displayAlign=\"center\" tts:textAlign=\"center\" xml:id=\"centerCenter\" />" + Environment.NewLine +
" <region tts:extent=\"80% 40%\" tts:origin=\"10% 50%\" tts:displayAlign=\"after\" tts:textAlign=\"center\" xml:id=\"bottomCenter\" />" + Environment.NewLine +
// Right column
" <region tts:extent=\"80% 40%\" tts:origin=\"10% 10%\" tts:displayAlign=\"before\" tts:textAlign=\"end\" xml:id=\"topRight\" />" + Environment.NewLine +
@ -448,7 +448,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
region = "centerLeft";
}
if (text.StartsWith("{\\an5}", StringComparison.Ordinal) && AddDefaultRegionIfNotExists(xml, "centerСenter"))
if (text.StartsWith("{\\an5}", StringComparison.Ordinal) && AddDefaultRegionIfNotExists(xml, "centerCenter"))
{
region = "centerСenter";
}
@ -882,7 +882,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
new KeyValuePair<string, string>("bottomCenter", "{\\an2}"),
new KeyValuePair<string, string>("bottomRight", "{\\an3}"),
new KeyValuePair<string, string>("centerLeft", "{\\an4}"),
new KeyValuePair<string, string>("centerСenter", "{\\an5}"),
new KeyValuePair<string, string>("centerCenter", "{\\an5}"),
new KeyValuePair<string, string>("centerRight", "{\\an6}"),
new KeyValuePair<string, string>("topLeft", "{\\an7}"),
new KeyValuePair<string, string>("topCenter", "{\\an8}"),

View File

@ -33,6 +33,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private bool _useCenterChannelOnly;
private Model _model;
private int _initialWidth = 725;
private readonly List<string> _outputBatchFileNames = new List<string>();
public Subtitle TranscribedSubtitle { get; private set; }
@ -236,7 +237,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
MessageBox.Show($"{errorCount} error(s)!{Environment.NewLine}{errors}");
}
MessageBox.Show(string.Format(LanguageSettings.Current.AudioToText.XFilesSavedToVideoSourceFolder, listViewInputFiles.Items.Count - errorCount));
var fileList = Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, _outputBatchFileNames);
MessageBox.Show(string.Format(LanguageSettings.Current.AudioToText.XFilesSavedToVideoSourceFolder, listViewInputFiles.Items.Count - errorCount) + fileList);
groupBoxInputFiles.Enabled = true;
buttonGenerate.Enabled = true;
@ -253,11 +255,12 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
var fileName = Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName)) + format.Extension;
if (File.Exists(fileName))
{
fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToByteArray()}.{format.Extension}";
fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToString()}.{format.Extension}";
}
File.WriteAllText(fileName, text, Encoding.UTF8);
textBoxLog.AppendText("Subtitle written to : " + fileName + Environment.NewLine);
_outputBatchFileNames.Add(fileName);
}
internal static string GetLanguage(string text)

View File

@ -44,6 +44,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private double _lastEstimatedMs = double.MaxValue;
private VideoInfo _videoInfo;
private readonly WavePeakData _wavePeaks;
private readonly List<string> _outputBatchFileNames = new List<string>();
public bool UnknownArgument { get; set; }
public bool RunningOnCuda { get; set; }
public bool IncompleteModel { get; set; }
@ -575,7 +577,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
MessageBox.Show(this, $"{errorCount} error(s)!{Environment.NewLine}{errors}", Text, MessageBoxButtons.OK);
}
MessageBox.Show(this, string.Format(LanguageSettings.Current.AudioToText.XFilesSavedToVideoSourceFolder, listViewInputFiles.Items.Count - errorCount), Text, MessageBoxButtons.OK);
var fileList = Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, _outputBatchFileNames);
MessageBox.Show(this, string.Format(LanguageSettings.Current.AudioToText.XFilesSavedToVideoSourceFolder, listViewInputFiles.Items.Count - errorCount) + fileList, Text, MessageBoxButtons.OK);
groupBoxInputFiles.Enabled = true;
buttonGenerate.Enabled = true;
@ -671,11 +674,12 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
var fileName = Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName)) + format.Extension;
if (File.Exists(fileName))
{
fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToByteArray()}.{format.Extension}";
fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToString()}.{format.Extension}";
}
File.WriteAllText(fileName, text, Encoding.UTF8);
_outputText.Add("Subtitle written to : " + fileName);
_outputBatchFileNames.Add(fileName);
}
internal static string GetLanguage(string name)

View File

@ -373,6 +373,12 @@ namespace Nikse.SubtitleEdit.Forms.BinaryEdit
videoPlayerContainer1.TryLoadGfx();
videoPlayerContainer1.HidePlayerName();
if (Configuration.Settings.Tools.BinEditShowColumnGap)
{
_columnIndexGap = 0;
UpdateListViewColumns();
}
}
private void OpenBinSubtitle(string fileName)
@ -616,7 +622,7 @@ namespace Nikse.SubtitleEdit.Forms.BinaryEdit
var paragraph = subtitle.Paragraphs[index];
var item = new ListViewItem { UseItemStyleForSubItems = false, Checked = extra.IsForced && _columnIndexForced >= 0 };
int count = startIndex;
var count = startIndex;
if (_columnIndexNumber >= 0)
{
count = AddListViewSubItem(item, count, (index + 1).ToString(CultureInfo.InvariantCulture));
@ -2895,6 +2901,8 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
Configuration.Settings.Tools.BinEditStartSize = WindowState == FormWindowState.Maximized ? "Maximized" : Width + ";" + Height;
}
Configuration.Settings.Tools.BinEditShowColumnGap = _columnIndexGap >= 0;
CloseVideo();
CleanUp();