Fix tests

Former-commit-id: 1d6517796f
This commit is contained in:
Malte Rosenbjerg 2021-03-15 23:43:22 +01:00
parent 399da85257
commit 263645f83b
3 changed files with 17 additions and 21 deletions

View file

@ -25,20 +25,22 @@ public async Task Audio_FromStream_Duration()
Assert.IsTrue(fileAnalysis.Duration == streamAnalysis.Duration);
}
[TestMethod]
public void MediaAnalysis_ParseDuration()
[DataTestMethod]
[DataRow("0:00:03.008000", 0, 0, 0, 3, 8)]
[DataRow("05:12:59.177", 0, 5, 12, 59, 177)]
[DataRow("149:07:50.911750", 6, 5, 7, 50, 911750)]
[DataRow("00:00:00.83", 0, 0, 0, 0, 830)]
public void MediaAnalysis_ParseDuration(string duration, int expectedDays, int expectedHours, int expectedMinutes, int expectedSeconds, int expectedMilliseconds)
{
var durationHHMMSS = new FFProbeStream { Duration = "05:12:59.177" };
var longDuration = new FFProbeStream { Duration = "149:07:50.911750" };
var shortDuration = new FFProbeStream { Duration = "00:00:00.83" };
var ffprobeStream = new FFProbeStream { Duration = duration };
var testdurationHHMMSS = MediaAnalysis.ParseDuration(durationHHMMSS);
var testlongDuration = MediaAnalysis.ParseDuration(longDuration);
var testshortDuration = MediaAnalysis.ParseDuration(shortDuration);
var parsedDuration = MediaAnalysisUtils.ParseDuration(ffprobeStream);
Assert.IsTrue(testdurationHHMMSS.Days == 0 && testdurationHHMMSS.Hours == 5 && testdurationHHMMSS.Minutes == 12 && testdurationHHMMSS.Seconds == 59 && testdurationHHMMSS.Milliseconds == 177);
Assert.IsTrue(testlongDuration.Days == 6 && testlongDuration.Hours == 5 && testlongDuration.Minutes == 7 && testlongDuration.Seconds == 50 && testlongDuration.Milliseconds == 911);
Assert.IsTrue(testdurationHHMMSS.Days == 0 && testshortDuration.Hours == 0 && testshortDuration.Minutes == 0 && testshortDuration.Seconds == 0 && testshortDuration.Milliseconds == 830);
Assert.AreEqual(parsedDuration.Days, expectedDays);
Assert.AreEqual(parsedDuration.Hours, expectedHours);
Assert.AreEqual(parsedDuration.Minutes, expectedMinutes);
Assert.AreEqual(parsedDuration.Seconds, expectedSeconds);
Assert.AreEqual(parsedDuration.Milliseconds, expectedMilliseconds);
}
[TestMethod]

View file

@ -163,8 +163,8 @@ public static bool Convert(
var source = FFProbe.Analyse(input);
FFMpegHelper.ConversionSizeExceptionCheck(source);
var scale = VideoSize.Original == size ? 1 : (double)source.PrimaryVideoStream.Height / (int)size;
var outputSize = new Size((int)(source.PrimaryVideoStream.Width / scale), (int)(source.PrimaryVideoStream.Height / scale));
var scale = VideoSize.Original == size ? 1 : (double)source.PrimaryVideoStream!.Height / (int)size;
var outputSize = new Size((int)(source.PrimaryVideoStream!.Width / scale), (int)(source.PrimaryVideoStream.Height / scale));
if (outputSize.Width % 2 != 0)
outputSize.Width += 1;

View file

@ -18,7 +18,7 @@ private MediaFormat ParseFormat(Format analysisFormat)
{
return new MediaFormat
{
Duration = ParseDuration(analysisFormat.Duration),
Duration = MediaAnalysisUtils.ParseDuration(analysisFormat.Duration),
FormatName = analysisFormat.FormatName,
FormatLongName = analysisFormat.FormatLongName,
StreamCount = analysisFormat.NbStreams,
@ -89,7 +89,7 @@ private AudioStream ParseAudioStream(FFProbeStream stream)
public static class MediaAnalysisUtils
{
private static readonly Regex DurationRegex = new Regex("^(\\d{1,5}:\\d{1,2}:\\d{1,2}(.\\d{1,7})?)", RegexOptions.Compiled);
private static readonly Regex DurationRegex = new Regex(@"^(\d+):(\d{1,2}):(\d{1,2})\.(\d{1,3})", RegexOptions.Compiled);
public static double DivideRatio((double, double) ratio) => ratio.Item1 / ratio.Item2;
@ -150,11 +150,5 @@ public static TimeSpan ParseDuration(FFProbeStream ffProbeStream)
{
return ParseDuration(ffProbeStream.Duration);
}
private static string? TrimTimeSpan(string? durationTag)
{
var durationMatch = DurationRegex.Match(durationTag ?? "");
return durationMatch.Success ? durationMatch.Groups[1].Value : null;
}
}
}