mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 15:02:35 +01:00
Merge pull request #7145 from Flitskikker/feature/btc-fix-20230723
Add more null and count checks
This commit is contained in:
commit
b1eb3c6bfa
@ -11,7 +11,6 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
{
|
||||
public static class ShotChangeHelper
|
||||
{
|
||||
|
||||
private static string GetShotChangesFileName(string videoFileName)
|
||||
{
|
||||
var dir = Configuration.ShotChangesDirectory.TrimEnd(Path.DirectorySeparatorChar);
|
||||
@ -89,6 +88,11 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
|
||||
public static double? GetPreviousShotChange(List<double> shotChanges, TimeCode currentTime)
|
||||
{
|
||||
if (shotChanges == null || shotChanges.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return shotChanges.Last(x => SubtitleFormat.MillisecondsToFrames(x * 1000) <= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds));
|
||||
@ -123,6 +127,11 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
|
||||
public static double? GetNextShotChange(List<double> shotChanges, TimeCode currentTime)
|
||||
{
|
||||
if (shotChanges == null || shotChanges.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return shotChanges.First(x => SubtitleFormat.MillisecondsToFrames(x * 1000) >= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds));
|
||||
|
@ -815,6 +815,11 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
|
||||
private int? GetFirstShotChangeFrameInBetween(int leftCueFrame, int rightCueFrame)
|
||||
{
|
||||
if (_shotChangesFrames == null || _shotChangesFrames.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return _shotChangesFrames.First(x => x >= leftCueFrame && x <= rightCueFrame);
|
||||
@ -827,6 +832,11 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
|
||||
private int? GetClosestShotChangeFrame(int cueFrame)
|
||||
{
|
||||
if (_shotChangesFrames == null || _shotChangesFrames.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return _shotChangesFrames.Aggregate((x, y) => Math.Abs(x - cueFrame) < Math.Abs(y - cueFrame) ? x : y);
|
||||
|
Loading…
Reference in New Issue
Block a user