From 9520f58240bd7f6ed9fb3168b7d9c7185c5ccfa2 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 17 Jun 2025 11:37:37 -0400 Subject: [PATCH] Fill out DetermineMediaType for Redumper --- CHANGELIST.md | 1 + MPF.Processors.Test/RedumperTests.cs | 194 ++++++++++++++++-- .../TestData/Redumper/BDR/test.log | 3 + .../TestData/Redumper/BluRay/test.log | 3 + .../TestData/Redumper/CDROM/test.log | 6 +- .../TestData/Redumper/DVD/test.log | 3 + .../TestData/Redumper/HDDVD/test.log | 3 + MPF.Processors/Redumper.cs | 139 ++++++++++++- 8 files changed, 329 insertions(+), 23 deletions(-) create mode 100644 MPF.Processors.Test/TestData/Redumper/BDR/test.log create mode 100644 MPF.Processors.Test/TestData/Redumper/BluRay/test.log create mode 100644 MPF.Processors.Test/TestData/Redumper/DVD/test.log create mode 100644 MPF.Processors.Test/TestData/Redumper/HDDVD/test.log diff --git a/CHANGELIST.md b/CHANGELIST.md index 4884ec5a..f3fb1235 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -5,6 +5,7 @@ - Ignore volume labels with path separators - Reduce media-specific checks where unnecessary - Add DetermineMediaType scaffolding and tests +- Fill out DetermineMediaType for Redumper ### 3.3.2 (2025-06-12) diff --git a/MPF.Processors.Test/RedumperTests.cs b/MPF.Processors.Test/RedumperTests.cs index 8cf0ff53..ebfa6392 100644 --- a/MPF.Processors.Test/RedumperTests.cs +++ b/MPF.Processors.Test/RedumperTests.cs @@ -11,27 +11,71 @@ namespace MPF.Processors.Test #region DetermineMediaType [Fact] - public void DetermineMediaType_Null_Throws() + public void DetermineMediaType_Null_Null() { string? basePath = null; var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); - Assert.Throws(() => processor.DetermineMediaType(basePath)); + var actual = processor.DetermineMediaType(basePath); + Assert.Null(actual); } [Fact] - public void DetermineMediaType_Invalid_Throws() + public void DetermineMediaType_Invalid_Null() { string? basePath = "INVALID"; var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); - Assert.Throws(() => processor.DetermineMediaType(basePath)); + var actual = processor.DetermineMediaType(basePath); + Assert.Null(actual); } [Fact] - public void DetermineMediaType_Valid_Throws() + public void DetermineMediaType_BD_Filled() { - string? basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test"); + MediaType? expected = MediaType.BluRay; + string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BluRay", "test"); var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); - Assert.Throws(() => processor.DetermineMediaType(basePath)); + var actual = processor.DetermineMediaType(basePath); + Assert.Equal(expected, actual); + } + + [Fact] + public void DetermineMediaType_BDR_Filled() + { + MediaType? expected = MediaType.BluRay; + string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BDR", "test"); + var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); + var actual = processor.DetermineMediaType(basePath); + Assert.Equal(expected, actual); + } + + [Fact] + public void DetermineMediaType_CD_Filled() + { + MediaType? expected = MediaType.CDROM; + string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test"); + var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); + var actual = processor.DetermineMediaType(basePath); + Assert.Equal(expected, actual); + } + + [Fact] + public void DetermineMediaType_DVD_Filled() + { + MediaType? expected = MediaType.DVD; + string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "DVD", "test"); + var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); + var actual = processor.DetermineMediaType(basePath); + Assert.Equal(expected, actual); + } + + [Fact] + public void DetermineMediaType_HDDVD_Filled() + { + MediaType? expected = MediaType.HDDVD; + string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "HDDVD", "test"); + var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); + var actual = processor.DetermineMediaType(basePath); + Assert.Equal(expected, actual); } #endregion @@ -294,32 +338,154 @@ namespace MPF.Processors.Test #endregion + #region GetDiscProfile + + [Fact] + public void GetDiscProfile_Empty_Null() + { + string log = string.Empty; + bool actual = Redumper.GetDiscProfile(log, out string? discProfile); + Assert.False(actual); + Assert.Null(discProfile); + } + + [Fact] + public void GetDiscProfile_Invalid_Null() + { + string log = "INVALID"; + bool actual = Redumper.GetDiscProfile(log, out string? discProfile); + Assert.False(actual); + Assert.Null(discProfile); + } + + [Fact] + public void GetDiscProfile_Valid_Filled() + { + string? expected = "CD-ROM"; + string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log"); + bool actual = Redumper.GetDiscProfile(log, out string? discProfile); + Assert.True(actual); + Assert.Equal(expected, discProfile); + } + + #endregion + #region GetDiscType [Fact] public void GetDiscType_Empty_Null() { string log = string.Empty; - bool actual = Redumper.GetDiscType(log, out string? discTypeOrBookType); + bool actual = Redumper.GetDiscType(log, out MediaType? discType); Assert.False(actual); + Assert.Null(discType); } [Fact] public void GetDiscType_Invalid_Null() { string log = "INVALID"; - bool actual = Redumper.GetDiscType(log, out string? discTypeOrBookType); + bool actual = Redumper.GetDiscType(log, out MediaType? discType); Assert.False(actual); + Assert.Null(discType); } [Fact] - public void GetDiscType_Valid_Filled() + public void GetDiscType_BD_Filled() { - string? expected = "CD-ROM"; - string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log"); - bool actual = Redumper.GetDiscType(log, out string? discTypeOrBookType); + MediaType? expected = MediaType.BluRay; + string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BluRay", "test.log"); + bool actual = Redumper.GetDiscType(log, out MediaType? discType); Assert.True(actual); - Assert.Equal(expected, discTypeOrBookType); + Assert.Equal(expected, discType); + } + + [Fact] + public void GetDiscType_BDR_Filled() + { + MediaType? expected = MediaType.BluRay; + string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BDR", "test.log"); + bool actual = Redumper.GetDiscType(log, out MediaType? discType); + Assert.True(actual); + Assert.Equal(expected, discType); + } + + [Fact] + public void GetDiscType_CD_Filled() + { + MediaType? expected = MediaType.CDROM; + string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log"); + bool actual = Redumper.GetDiscType(log, out MediaType? discType); + Assert.True(actual); + Assert.Equal(expected, discType); + } + + [Fact] + public void GetDiscType_DVD_Filled() + { + MediaType? expected = MediaType.DVD; + string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "DVD", "test.log"); + bool actual = Redumper.GetDiscType(log, out MediaType? discType); + Assert.True(actual); + Assert.Equal(expected, discType); + } + + [Fact] + public void GetDiscType_HDDVD_Filled() + { + MediaType? expected = MediaType.HDDVD; + string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "HDDVD", "test.log"); + bool actual = Redumper.GetDiscType(log, out MediaType? discType); + Assert.True(actual); + Assert.Equal(expected, discType); + } + + #endregion + + #region GetDiscTypeFromProfile + + [Theory] + [InlineData(null, null)] + [InlineData("", null)] + [InlineData("INVALID", null)] + [InlineData("reserved", null)] + [InlineData("non removable disk", null)] + [InlineData("removable disk", null)] + [InlineData("MO erasable", null)] + [InlineData("MO write once", null)] + [InlineData("AS MO", null)] + [InlineData("CD-ROM", MediaType.CDROM)] + [InlineData("CD-R", MediaType.CDROM)] + [InlineData("CD-RW", MediaType.CDROM)] + [InlineData("DVD-ROM", MediaType.DVD)] + [InlineData("DVD-R", MediaType.DVD)] + [InlineData("DVD-RAM", MediaType.DVD)] + [InlineData("DVD-RW RO", MediaType.DVD)] + [InlineData("DVD-RW", MediaType.DVD)] + [InlineData("DVD-R DL", MediaType.DVD)] + [InlineData("DVD-R DL LJR", MediaType.DVD)] + [InlineData("DVD+RW", MediaType.DVD)] + [InlineData("DVD+R", MediaType.DVD)] + [InlineData("DDCD-ROM", MediaType.CDROM)] + [InlineData("DDCD-R", MediaType.CDROM)] + [InlineData("DDCD-RW", MediaType.CDROM)] + [InlineData("DVD+RW DL", MediaType.DVD)] + [InlineData("DVD+R DL", MediaType.DVD)] + [InlineData("BD-ROM", MediaType.BluRay)] + [InlineData("BD-R", MediaType.BluRay)] + [InlineData("BD-R RRM", MediaType.BluRay)] + [InlineData("BD-RW", MediaType.BluRay)] + [InlineData("HD DVD-ROM", MediaType.HDDVD)] + [InlineData("HD DVD-R", MediaType.HDDVD)] + [InlineData("HD DVD-RAM", MediaType.HDDVD)] + [InlineData("HD DVD-RW", MediaType.HDDVD)] + [InlineData("HD DVD-R DL", MediaType.HDDVD)] + [InlineData("HD DVD-RW DL", MediaType.HDDVD)] + [InlineData("NON STANDARD", null)] + public void GetDiscTypeFromProfileTest(string? profile, MediaType? expected) + { + var actual = Redumper.GetDiscTypeFromProfile(profile); + Assert.Equal(expected, actual); } #endregion diff --git a/MPF.Processors.Test/TestData/Redumper/BDR/test.log b/MPF.Processors.Test/TestData/Redumper/BDR/test.log new file mode 100644 index 00000000..a6bda25f --- /dev/null +++ b/MPF.Processors.Test/TestData/Redumper/BDR/test.log @@ -0,0 +1,3 @@ +<< GetDiscType >> + disc type: INVALID +disc type: BLURAY-R \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/Redumper/BluRay/test.log b/MPF.Processors.Test/TestData/Redumper/BluRay/test.log new file mode 100644 index 00000000..ed90736d --- /dev/null +++ b/MPF.Processors.Test/TestData/Redumper/BluRay/test.log @@ -0,0 +1,3 @@ +<< GetDiscType >> + disc type: INVALID +disc type: BLURAY \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/Redumper/CDROM/test.log b/MPF.Processors.Test/TestData/Redumper/CDROM/test.log index 57493f8a..3f9cff63 100644 --- a/MPF.Processors.Test/TestData/Redumper/CDROM/test.log +++ b/MPF.Processors.Test/TestData/Redumper/CDROM/test.log @@ -13,9 +13,13 @@ CUE [ dat: -<< GetDiscType >> +<< GetDiscProfile >> current profile: CD-ROM +<< GetDiscType >> + disc type: INVALID +disc type: CD + << GetDVDProtection >> copyright: protection system type: none diff --git a/MPF.Processors.Test/TestData/Redumper/DVD/test.log b/MPF.Processors.Test/TestData/Redumper/DVD/test.log new file mode 100644 index 00000000..5de95187 --- /dev/null +++ b/MPF.Processors.Test/TestData/Redumper/DVD/test.log @@ -0,0 +1,3 @@ +<< GetDiscType >> + disc type: INVALID +disc type: DVD \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/Redumper/HDDVD/test.log b/MPF.Processors.Test/TestData/Redumper/HDDVD/test.log new file mode 100644 index 00000000..b23ceafd --- /dev/null +++ b/MPF.Processors.Test/TestData/Redumper/HDDVD/test.log @@ -0,0 +1,3 @@ +<< GetDiscType >> + disc type: INVALID +disc type: HD-DVD \ No newline at end of file diff --git a/MPF.Processors/Redumper.cs b/MPF.Processors/Redumper.cs index 189e2967..be9d5f67 100644 --- a/MPF.Processors/Redumper.cs +++ b/MPF.Processors/Redumper.cs @@ -25,7 +25,20 @@ namespace MPF.Processors /// public override MediaType? DetermineMediaType(string? basePath) { - throw new NotImplementedException(); + // If the base path is invalid + if (string.IsNullOrEmpty(basePath)) + return null; + + // Use the log first, if it exists + if (GetDiscType($"{basePath}.log", out MediaType? mediaType)) + return mediaType; + + // Use the profile for older Redumper versions + if (GetDiscProfile($"{basePath}.log", out string? discProfile)) + return GetDiscTypeFromProfile(discProfile); + + // The type could not be determined + return null; } /// @@ -49,7 +62,7 @@ namespace MPF.Processors } // Fill in the disc type data - if (GetDiscType($"{basePath}.log", out var discTypeOrBookType)) + if (GetDiscProfile($"{basePath}.log", out var discTypeOrBookType)) info.DumpingInfo.ReportedDiscType = discTypeOrBookType; // Get the PVD, if it exists @@ -873,14 +886,14 @@ namespace MPF.Processors } /// - /// Get reported disc type information, if possible + /// Get reported disc profile information, if possible /// /// Log file location - /// True if disc type info was set, false otherwise - internal static bool GetDiscType(string log, out string? discTypeOrBookType) + /// True if disc profile information was set, false otherwise + internal static bool GetDiscProfile(string log, out string? discProfile) { // Set the default values - discTypeOrBookType = null; + discProfile = null; // If the file doesn't exist, we can't get the info if (string.IsNullOrEmpty(log)) @@ -901,7 +914,7 @@ namespace MPF.Processors if (line.StartsWith("current profile:")) { // current profile: - discTypeOrBookType = line.Substring("current profile: ".Length); + discProfile = line.Substring("current profile: ".Length); } line = sr.ReadLine(); @@ -912,11 +925,121 @@ namespace MPF.Processors catch { // We don't care what the exception is right now - discTypeOrBookType = null; + discProfile = null; return false; } } + /// + /// Get reported disc type, if possible + /// + /// Log file location + /// True if disc type was set, false otherwise + internal static bool GetDiscType(string log, out MediaType? discType) + { + // Set the default values + discType = null; + + // If the file doesn't exist, we can't get the info + if (string.IsNullOrEmpty(log)) + return false; + if (!File.Exists(log)) + return false; + + try + { + using var sr = File.OpenText(log); + var line = sr.ReadLine()?.TrimEnd(); + while (line != null) + { + // If the line isn't the non-embedded disc type, skip + if (!line.StartsWith("disc type:")) + { + line = sr.ReadLine()?.TrimEnd(); + continue; + } + + // disc type: + string discTypeStr = line.Substring("disc type: ".Length); + + // Set the media type based on the string + discType = discTypeStr switch + { + "CD" => MediaType.CDROM, + "DVD" => MediaType.DVD, + "BLURAY" => MediaType.BluRay, + "BLURAY-R" => MediaType.BluRay, + "HD-DVD" => MediaType.HDDVD, + _ => null, + }; + return discType != null; + } + + return false; + } + catch + { + // We don't care what the exception is right now + discType = null; + return false; + } + } + + /// + /// Convert the profile to a media type, if possible + /// + /// Profile string to check + /// Media type on success, null otherwise + internal static MediaType? GetDiscTypeFromProfile(string? profile) + { + return profile switch + { + "reserved" => null, + "non removable disk" => null, + "removable disk" => null, + "MO erasable" => null, + "MO write once" => null, + "AS MO" => null, + + "CD-ROM" => MediaType.CDROM, + "CD-R" => MediaType.CDROM, + "CD-RW" => MediaType.CDROM, + + "DVD-ROM" => MediaType.DVD, + "DVD-R" => MediaType.DVD, + "DVD-RAM" => MediaType.DVD, + "DVD-RW RO" => MediaType.DVD, + "DVD-RW" => MediaType.DVD, + "DVD-R DL" => MediaType.DVD, + "DVD-R DL LJR" => MediaType.DVD, + "DVD+RW" => MediaType.DVD, + "DVD+R" => MediaType.DVD, + + "DDCD-ROM" => MediaType.CDROM, + "DDCD-R" => MediaType.CDROM, + "DDCD-RW" => MediaType.CDROM, + + "DVD+RW DL" => MediaType.DVD, + "DVD+R DL" => MediaType.DVD, + + "BD-ROM" => MediaType.BluRay, + "BD-R" => MediaType.BluRay, + "BD-R RRM" => MediaType.BluRay, + "BD-RW" => MediaType.BluRay, + + "HD DVD-ROM" => MediaType.HDDVD, + "HD DVD-R" => MediaType.HDDVD, + "HD DVD-RAM" => MediaType.HDDVD, + "HD DVD-RW" => MediaType.HDDVD, + "HD DVD-R DL" => MediaType.HDDVD, + "HD DVD-RW DL" => MediaType.HDDVD, + + "NON STANDARD" => null, + + _ => null, + }; + } + /// /// Get the DVD protection information, if possible ///