mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Refactor video and subtitle batch creation code
Code for creating and validating batch video and subtitle entities has been extracted into separate methods, improving the readability of the main method. These changes also include a rectification in the logic for handling invalid video dimensions. Signed-off-by: Ivandro Jao <ivandrofly@gmail.com>
This commit is contained in:
parent
3d24cdcbb6
commit
93c9e9947a
@ -2141,29 +2141,52 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
var ext = Path.GetExtension(videoFileName).ToLowerInvariant();
|
var ext = Path.GetExtension(videoFileName).ToLowerInvariant();
|
||||||
if ((Utilities.AudioFileExtensions.Contains(ext) || Utilities.VideoFileExtensions.Contains(ext)) && File.Exists(videoFileName))
|
if ((Utilities.AudioFileExtensions.Contains(ext) || Utilities.VideoFileExtensions.Contains(ext)) && File.Exists(videoFileName))
|
||||||
{
|
{
|
||||||
var item = new BatchVideoAndSub();
|
var videoDimension = GetVideoDimension(videoFileName);
|
||||||
item.VideoFileName = videoFileName;
|
if (!videoDimension.IsValid())
|
||||||
item.VideoFileSizeInBytes = new FileInfo(videoFileName).Length;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var batchVideoAndSub = CreateBatchVideoAndSub(videoFileName);
|
||||||
|
var listViewItem = new ListViewItem(videoFileName) { Tag = batchVideoAndSub };
|
||||||
|
listViewItem.SubItems.Add(videoDimension.ToString());
|
||||||
|
var s = Utilities.FormatBytesToDisplayFileSize(batchVideoAndSub.VideoFileSizeInBytes);
|
||||||
|
listViewItem.SubItems.Add(s);
|
||||||
|
listViewItem.SubItems.Add(Path.GetFileName(batchVideoAndSub.SubtitleFileName));
|
||||||
|
listViewItem.SubItems.Add(string.Empty);
|
||||||
|
listViewBatch.Items.Add(listViewItem);
|
||||||
|
_batchVideoAndSubList.Add(batchVideoAndSub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BatchVideoAndSub CreateBatchVideoAndSub(string videoFileName)
|
||||||
|
{
|
||||||
|
var batchVideoAndSub = new BatchVideoAndSub
|
||||||
|
{
|
||||||
|
VideoFileName = videoFileName,
|
||||||
|
VideoFileSizeInBytes = new FileInfo(videoFileName).Length
|
||||||
|
};
|
||||||
|
|
||||||
var path = Path.GetDirectoryName(videoFileName);
|
var path = Path.GetDirectoryName(videoFileName);
|
||||||
// try to locate subtitle file for the input vide file
|
// try to locate subtitle file for the input vide file
|
||||||
var subtitleFile = FileUtil.TryLocateSubtitleFile(path, videoFileName);
|
var subtitleFile = FileUtil.TryLocateSubtitleFile(path, videoFileName);
|
||||||
if (File.Exists(subtitleFile))
|
if (File.Exists(subtitleFile))
|
||||||
{
|
{
|
||||||
item.SubtitleFileName = subtitleFile;
|
batchVideoAndSub.SubtitleFileName = subtitleFile;
|
||||||
item.SubtitleFileFileSizeInBytes = new FileInfo(subtitleFile).Length;
|
batchVideoAndSub.SubtitleFileFileSizeInBytes = new FileInfo(subtitleFile).Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mediaInfo = FfmpegMediaInfo.Parse(videoFileName);
|
return batchVideoAndSub;
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
if (mediaInfo.VideoWidth > 0 && mediaInfo.VideoHeight > 0)
|
|
||||||
{
|
|
||||||
width = mediaInfo.VideoWidth;
|
|
||||||
height = mediaInfo.VideoHeight;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
private Dimension GetVideoDimension(string videoFileName)
|
||||||
{
|
{
|
||||||
|
var mediaInfo = FfmpegMediaInfo.Parse(videoFileName);
|
||||||
|
if (mediaInfo.Dimension.IsValid())
|
||||||
|
{
|
||||||
|
return mediaInfo.Dimension;
|
||||||
|
}
|
||||||
|
|
||||||
var vInfo = new VideoInfo { Success = false };
|
var vInfo = new VideoInfo { Success = false };
|
||||||
if (videoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase))
|
if (videoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
@ -2179,26 +2202,14 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
vInfo = UiUtil.GetVideoInfo(videoFileName);
|
vInfo = UiUtil.GetVideoInfo(videoFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
width = vInfo.Width;
|
if (vInfo.Width == 0 || vInfo.Height == 0)
|
||||||
height = vInfo.Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (width == 0 || height == 0)
|
|
||||||
{
|
{
|
||||||
SeLogger.Error("Skipping burn-in file with no video: " + videoFileName);
|
SeLogger.Error("Skipping burn-in file with no video: " + videoFileName);
|
||||||
return; // skip audio or damaged files
|
// return; // skip audio or damaged files
|
||||||
|
return new Dimension();
|
||||||
}
|
}
|
||||||
|
|
||||||
var listViewItem = new ListViewItem(videoFileName);
|
return new Dimension(vInfo.Height, vInfo.Width);
|
||||||
listViewItem.Tag = item;
|
|
||||||
listViewItem.SubItems.Add($"{width}x{height}");
|
|
||||||
var s = Utilities.FormatBytesToDisplayFileSize(item.VideoFileSizeInBytes);
|
|
||||||
listViewItem.SubItems.Add(s);
|
|
||||||
listViewItem.SubItems.Add(Path.GetFileName(item.SubtitleFileName));
|
|
||||||
listViewItem.SubItems.Add(string.Empty);
|
|
||||||
listViewBatch.Items.Add(listViewItem);
|
|
||||||
_batchVideoAndSubList.Add(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
|
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
Loading…
Reference in New Issue
Block a user