Skip to content

Commit

Permalink
Fixes #1090: Add support for m3u8 playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël committed Jan 12, 2020
1 parent bb2d29a commit 02c5f43
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Dopamine.Core/Base/FileFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -49,6 +50,7 @@ public static class FileFormats

public static string[] SupportedStaticPlaylistExtensions = {
FileFormats.M3U,
FileFormats.M3U8,
FileFormats.ZPL,
FileFormats.WPL
};
Expand Down
2 changes: 1 addition & 1 deletion Dopamine.Core/IO/PlaylistDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DecodePlaylistResult DecodePlaylist(string fileName)
string playlistName = string.Empty;
IList<PlaylistEntry> playlistEntries = new List<PlaylistEntry>();

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);
}
Expand Down
2 changes: 1 addition & 1 deletion Dopamine.Services/Playlist/PlaylistService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down
3 changes: 3 additions & 0 deletions Dopamine.Tests/Dopamine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<Content Include="Files\LyricsParser\SynchronizedLyricsWithDuplicateTimestamps.lrc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\PlaylistDecoder\Test.m3u8">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
Expand Down
3 changes: 3 additions & 0 deletions Dopamine.Tests/Files/PlaylistDecoder/Test.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C:\Music\File1.mp3
C:\Music\File2.mp3
C:\Music\File3.mp3
44 changes: 33 additions & 11 deletions Dopamine.Tests/PlaylistDecoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions Dopamine/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02c5f43

Please sign in to comment.