diff --git a/Dopamine.Core/Base/FileFormats.cs b/Dopamine.Core/Base/FileFormats.cs index 7eea7e889..78a5c9ed8 100644 --- a/Dopamine.Core/Base/FileFormats.cs +++ b/Dopamine.Core/Base/FileFormats.cs @@ -20,6 +20,7 @@ public static class FileFormats // Playlist extensions public static string M3U = ".m3u"; + public static string M3U8 = ".m3u8"; public static string WPL = ".wpl"; public static string ZPL = ".zpl"; @@ -49,6 +50,7 @@ public static class FileFormats public static string[] SupportedStaticPlaylistExtensions = { FileFormats.M3U, + FileFormats.M3U8, FileFormats.ZPL, FileFormats.WPL }; diff --git a/Dopamine.Core/IO/PlaylistDecoder.cs b/Dopamine.Core/IO/PlaylistDecoder.cs index aeaea34c1..582b399ee 100644 --- a/Dopamine.Core/IO/PlaylistDecoder.cs +++ b/Dopamine.Core/IO/PlaylistDecoder.cs @@ -46,7 +46,7 @@ public DecodePlaylistResult DecodePlaylist(string fileName) string playlistName = string.Empty; IList playlistEntries = new List(); - if (System.IO.Path.GetExtension(fileName.ToLower()) == FileFormats.M3U) + if (System.IO.Path.GetExtension(fileName.ToLower()) == FileFormats.M3U | System.IO.Path.GetExtension(fileName.ToLower()) == FileFormats.M3U8) { decodeResult = this.DecodeM3uPlaylist(fileName, ref playlistName, ref playlistEntries); } diff --git a/Dopamine.Services/Playlist/PlaylistService.cs b/Dopamine.Services/Playlist/PlaylistService.cs index 59ed292c7..f02448082 100644 --- a/Dopamine.Services/Playlist/PlaylistService.cs +++ b/Dopamine.Services/Playlist/PlaylistService.cs @@ -70,7 +70,7 @@ public PlaylistService(ITrackRepository trackRepository, public string PlaylistFolder { get; } - public string DialogFileFilter => $"(*{FileFormats.M3U};*{FileFormats.WPL};*{FileFormats.ZPL};*{FileFormats.DSPL})|*{FileFormats.M3U};*{FileFormats.WPL};*{FileFormats.ZPL};*{FileFormats.DSPL};*{FileFormats.DSPL}"; + public string DialogFileFilter => $"(*{FileFormats.M3U};*{FileFormats.M3U8};*{FileFormats.WPL};*{FileFormats.ZPL};*{FileFormats.DSPL})|*{FileFormats.M3U};*{FileFormats.M3U8};*{FileFormats.WPL};*{FileFormats.ZPL};*{FileFormats.DSPL};*{FileFormats.DSPL}"; public event EventHandler PlaylistFolderChanged = delegate { }; public event TracksAddedHandler TracksAdded = delegate { }; diff --git a/Dopamine.Tests/Dopamine.Tests.csproj b/Dopamine.Tests/Dopamine.Tests.csproj index 8646035c0..b18ff046e 100644 --- a/Dopamine.Tests/Dopamine.Tests.csproj +++ b/Dopamine.Tests/Dopamine.Tests.csproj @@ -132,6 +132,9 @@ Always + + Always + diff --git a/Dopamine.Tests/Files/PlaylistDecoder/Test.m3u8 b/Dopamine.Tests/Files/PlaylistDecoder/Test.m3u8 new file mode 100644 index 000000000..bedac8f18 --- /dev/null +++ b/Dopamine.Tests/Files/PlaylistDecoder/Test.m3u8 @@ -0,0 +1,3 @@ +C:\Music\File1.mp3 +C:\Music\File2.mp3 +C:\Music\File3.mp3 \ No newline at end of file diff --git a/Dopamine.Tests/PlaylistDecoderTest.cs b/Dopamine.Tests/PlaylistDecoderTest.cs index 2a3d978f7..847c679dd 100644 --- a/Dopamine.Tests/PlaylistDecoderTest.cs +++ b/Dopamine.Tests/PlaylistDecoderTest.cs @@ -11,14 +11,38 @@ public void DecodeM3uPlaylist() { // Arrange string playlistPath = System.IO.Path.GetFullPath(@"Files\PlaylistDecoder\Test.m3u"); - string playlistDirectory = System.IO.Path.GetDirectoryName(playlistPath); + + // Act + var decoder = new PlaylistDecoder(); + DecodePlaylistResult result = decoder.DecodePlaylist(playlistPath); + + // Assert + if (result.DecodeResult.Result && !string.IsNullOrWhiteSpace(result.PlaylistName)) + { + Assert.IsTrue(result.Paths.Count == 3); + Assert.AreEqual(result.Paths[0], @"C:\Music\File1.mp3"); + Assert.AreEqual(result.Paths[1], @"C:\Music\File2.mp3"); + Assert.AreEqual(result.Paths[2], @"C:\Music\File3.mp3"); + Assert.AreEqual(result.PlaylistName, "Test"); + } + else + { + Assert.Fail(); + } + } + + [TestMethod(), TestCategory(TestCategories.PlaylistDecoder)] + public void DecodeM3u8Playlist() + { + // Arrange + string playlistPath = System.IO.Path.GetFullPath(@"Files\PlaylistDecoder\Test.m3u8"); // Act - var decoder = new Core.IO.PlaylistDecoder(); + var decoder = new PlaylistDecoder(); DecodePlaylistResult result = decoder.DecodePlaylist(playlistPath); // Assert - if (result.DecodeResult.Result && result.Paths.Count == 3 && !string.IsNullOrWhiteSpace(result.PlaylistName)) + if (result.DecodeResult.Result && !string.IsNullOrWhiteSpace(result.PlaylistName)) { Assert.IsTrue(result.Paths.Count == 3); Assert.AreEqual(result.Paths[0], @"C:\Music\File1.mp3"); @@ -37,14 +61,13 @@ public void DecodeZplPlaylist() { // Arrange string playlistPath = System.IO.Path.GetFullPath(@"Files\PlaylistDecoder\Test.zpl"); - string playlistDirectory = System.IO.Path.GetDirectoryName(playlistPath); - + // Act - var decoder = new Core.IO.PlaylistDecoder(); + var decoder = new PlaylistDecoder(); DecodePlaylistResult result = decoder.DecodePlaylist(playlistPath); // Assert - if (result.DecodeResult.Result && result.Paths.Count == 3 && !string.IsNullOrWhiteSpace(result.PlaylistName)) + if (result.DecodeResult.Result && !string.IsNullOrWhiteSpace(result.PlaylistName)) { Assert.IsTrue(result.Paths.Count == 3); Assert.AreEqual(result.Paths[0], @"C:\Music\File1.mp3"); @@ -63,14 +86,13 @@ public void DecodeWplPlaylist() { // Arrange string playlistPath = System.IO.Path.GetFullPath(@"Files\PlaylistDecoder\Test.wpl"); - string playlistDirectory = System.IO.Path.GetDirectoryName(playlistPath); - + // Act - var decoder = new Core.IO.PlaylistDecoder(); + var decoder = new PlaylistDecoder(); DecodePlaylistResult result = decoder.DecodePlaylist(playlistPath); // Assert - if (result.DecodeResult.Result && result.Paths.Count == 3 && !string.IsNullOrWhiteSpace(result.PlaylistName)) + if (result.DecodeResult.Result && !string.IsNullOrWhiteSpace(result.PlaylistName)) { Assert.IsTrue(result.Paths.Count == 3); Assert.AreEqual(result.Paths[0], @"C:\Music\File1.mp3"); diff --git a/Dopamine/Changelog.txt b/Dopamine/Changelog.txt index 3127d56cd..74aa8dc92 100644 --- a/Dopamine/Changelog.txt +++ b/Dopamine/Changelog.txt @@ -2,6 +2,7 @@ -------------------------- - [Changed] Reverted some changes to audio decoding. This hopefully removes lag when decoding high bitrate files. +- [Added] Added support for m3u8 playlists 2020-01-11: Dopamine 2.0