Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded subtitle soft #8915

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 29 additions & 54 deletions src/ui/Forms/GenerateVideoWithSoftSubs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 48 additions & 17 deletions src/ui/Forms/GenerateVideoWithSoftSubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;

Expand Down Expand Up @@ -45,7 +46,6 @@ public GenerateVideoWithSoftSubs(Subtitle subtitle, string inputVideoFileName, V

_videoInfo = videoInfo;
_subtitle = new Subtitle(subtitle);
_inputVideoFileName = inputVideoFileName;

Text = LanguageSettings.Current.GenerateVideoWithEmbeddedSubs.Title;
labelInputVideoFile.Text = LanguageSettings.Current.GenerateVideoWithEmbeddedSubs.InputVideoFile;
Expand Down Expand Up @@ -107,7 +107,7 @@ private void AddCurrentSubtitle()
File.WriteAllText(fileName, targetFormat.ToText(_subtitle, string.Empty));
fileName = GetKnownFileNameOrConvertToSrtOrUtf8(fileName, _subtitle);

AddListViewItem(fileName);
AddListViewItem(CreateVideoPreviewGeneratorSub(fileName));

if (listViewSubtitles.Items.Count > 0)
{
Expand Down Expand Up @@ -186,6 +186,11 @@ private void AddListViewItem(Trak track)

private void AddListViewItem(VideoPreviewGeneratorSub sub)
{
if (sub is null)
{
return;
}

var item = new ListViewItem
{
Tag = sub,
Expand Down Expand Up @@ -284,17 +289,17 @@ private void AddListViewItem(MatroskaTrackInfo track, MatroskaFile matroska)
});
}

private void AddListViewItem(string fileName)
private VideoPreviewGeneratorSub CreateVideoPreviewGeneratorSub(string fileName)
{
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
{
return;
return null;
}

if (fileName.EndsWith(".sup", StringComparison.OrdinalIgnoreCase) &&
FileUtil.IsBluRaySup(fileName))
{
AddListViewItem(new VideoPreviewGeneratorSub
return new VideoPreviewGeneratorSub
{
Name = Path.GetFileName(fileName),
Language = GetLanguageFromFileName(fileName),
Expand All @@ -304,15 +309,13 @@ private void AddListViewItem(string fileName)
IsForced = false,
IsDefault = false,
FileName = fileName,
});

return;
};
}

var subtitle = Subtitle.Parse(fileName);
if (subtitle == null || subtitle.Paragraphs.Count == 0)
{
return;
return null;
}

fileName = GetKnownFileNameOrConvertToSrtOrUtf8(fileName, subtitle);
Expand All @@ -334,7 +337,7 @@ private void AddListViewItem(string fileName)
}
}

AddListViewItem(new VideoPreviewGeneratorSub
return new VideoPreviewGeneratorSub
{
Name = Path.GetFileName(fileName),
Language = language,
Expand All @@ -345,7 +348,7 @@ private void AddListViewItem(string fileName)
IsForced = false,
IsDefault = false,
FileName = fileName,
});
};
}

private static string GetLanguageFromFileName(string fileName)
Expand Down Expand Up @@ -782,7 +785,7 @@ private void buttonAddSubtitles_Click(object sender, EventArgs e)

foreach (var fileName in openFileDialog1.FileNames)
{
AddListViewItem(fileName);
AddListViewItem(CreateVideoPreviewGeneratorSub(fileName));
}
}

Expand Down Expand Up @@ -840,18 +843,46 @@ private void listViewSubtitles_DragEnter(object sender, DragEventArgs e)
}
}

private void listViewSubtitles_DragDrop(object sender, DragEventArgs e)
private async void listViewSubtitles_DragDrop(object sender, DragEventArgs e)
{
var fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var fileName in fileNames)

ActivateWaitState();
var previewGeneratorSubs = await Task.Run(() =>
{
if (!FileUtil.IsDirectory(fileName))
var previewItems = new List<VideoPreviewGeneratorSub>();
foreach (var fileName in fileNames)
{
AddListViewItem(fileName);
if (!FileUtil.IsDirectory(fileName))
{
previewItems.Add(CreateVideoPreviewGeneratorSub(fileName));
}
}
}

return previewItems.Where(previewItem => previewItem != null).ToList();
}).ConfigureAwait(true);

listViewSubtitles.BeginUpdate();
previewGeneratorSubs.ForEach(AddListViewItem);
listViewSubtitles.EndUpdate();

DeactivateWaitState();
}

private void ActivateWaitState()
{
progressBarDragDrop.Visible = true;
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait;
Cursor = Cursors.WaitCursor;
}

private void DeactivateWaitState()
{
progressBarDragDrop.Visible = false;
labelPleaseWait.Text = string.Empty;
Cursor = Cursors.Default;
}

private void ButtonRemoveSubtitles_Click(object sender, EventArgs e)
{
if (listViewSubtitles.Items.Count <= 0)
Expand Down