public void Create_CreatePlaylistAndCompareWithFile_Equal() { ZplContent content = new ZplContent(); ZplPlaylist playlist = new ZplPlaylist(); playlist.Title = "Eurowizja"; playlist.PlaylistEntries.Add(new ZplPlaylistEntry() { AlbumArtist = null, AlbumTitle = "", Duration = TimeSpan.FromMilliseconds(185364), Path = @"D:\Muzyka\Eurowizja\Eurowizja 2014\Can-linn & Kasey Smith - Heartbeat(Irlandia).mp3", TrackArtist = "Can-linn & Kasey Smith", TrackTitle = "Heartbeat" }); playlist.PlaylistEntries.Add(new ZplPlaylistEntry() { AlbumArtist = "Elaiza", AlbumTitle = "Eurovision Song Contest 2014", Duration = TimeSpan.Zero, Path = @"D:\Muzyka\Eurowizja\Eurowizja 2014\Elaiza - Is It Right.mp3", TrackArtist = "Elaiza", TrackTitle = "Is It Right" }); string created = content.Create(playlist); string fromFile = Helpers.Read("Playlist2.zpl"); Assert.AreEqual(created, fromFile); }
public void GetFromStream_ReadEmptyPlaylistAndCompareWithObject_Equal() { ZplContent content = new ZplContent(); ZplPlaylist playlist = new ZplPlaylist(); playlist.Title = ""; var stream = Helpers.ReadStream("Empty.zpl"); var file = content.GetFromStream(stream); Assert.AreEqual(playlist.Title, file.Title); Assert.AreEqual(playlist.PlaylistEntries.Count, file.PlaylistEntries.Count); stream.Dispose(); }
public void GetFromStream_ReadPlaylistAndCompareWithObject_Equal() { ZplContent content = new ZplContent(); ZplPlaylist playlist = new ZplPlaylist(); playlist.Title = "Eurowizja"; playlist.PlaylistEntries.Add(new ZplPlaylistEntry() { AlbumArtist = null, AlbumTitle = "", Duration = TimeSpan.FromMilliseconds(185364), Path = @"D:\Muzyka\Eurowizja\Eurowizja 2014\Can-linn & Kasey Smith - Heartbeat(Irlandia).mp3", TrackArtist = "Can-linn & Kasey Smith", TrackTitle = "Heartbeat" }); playlist.PlaylistEntries.Add(new ZplPlaylistEntry() { AlbumArtist = "Elaiza", AlbumTitle = "Eurovision Song Contest 2014", Path = @"D:\Muzyka\Eurowizja\Eurowizja 2014\Elaiza - Is It Right.mp3", TrackArtist = "Elaiza", TrackTitle = "Is It Right" }); var stream = Helpers.ReadStream("Playlist.zpl"); var file = content.GetFromStream(stream); stream.Dispose(); Assert.AreEqual(playlist.PlaylistEntries.Count, file.PlaylistEntries.Count); Assert.AreEqual(playlist.Title, file.Title); Assert.AreEqual(playlist.PlaylistEntries[0].AlbumArtist, file.PlaylistEntries[0].AlbumArtist); Assert.AreEqual(playlist.PlaylistEntries[1].AlbumArtist, file.PlaylistEntries[1].AlbumArtist); Assert.AreEqual(String.IsNullOrEmpty(playlist.PlaylistEntries[0].AlbumTitle), String.IsNullOrEmpty(file.PlaylistEntries[0].AlbumTitle)); Assert.AreEqual(playlist.PlaylistEntries[1].AlbumTitle, file.PlaylistEntries[1].AlbumTitle); Assert.AreEqual(playlist.PlaylistEntries[0].TrackArtist, file.PlaylistEntries[0].TrackArtist); Assert.AreEqual(playlist.PlaylistEntries[1].TrackArtist, file.PlaylistEntries[1].TrackArtist); Assert.AreEqual(playlist.PlaylistEntries[0].TrackTitle, file.PlaylistEntries[0].TrackTitle); Assert.AreEqual(playlist.PlaylistEntries[1].TrackTitle, file.PlaylistEntries[1].TrackTitle); Assert.AreEqual(playlist.PlaylistEntries[0].Path, file.PlaylistEntries[0].Path); Assert.AreEqual(playlist.PlaylistEntries[1].Path, file.PlaylistEntries[1].Path); stream.Dispose(); }
/// <summary> /// Returns the playlist in zpl format. /// </summary> private string CreateZplPlaylist() { var playlist = new ZplPlaylist() { Title = _album.Title, }; foreach (Track track in _album.Tracks) { playlist.PlaylistEntries.Add(new ZplPlaylistEntry() { AlbumArtist = _album.Artist, AlbumTitle = _album.Title, Duration = TimeSpan.FromSeconds(track.Duration), Path = Path.GetFileName(track.Path), TrackArtist = _album.Artist, TrackTitle = track.Title, }); } return(new ZplContent().ToText(playlist)); }
private void SavePlaylistFile(Playlist item) { // this is probably best done as a metadata provider // saving a file over itself will require some work to prevent this from happening when not needed var playlistPath = item.Path; var extension = Path.GetExtension(playlistPath); if (string.Equals(".wpl", extension, StringComparison.OrdinalIgnoreCase)) { var playlist = new WplPlaylist(); foreach (var child in item.GetLinkedChildren()) { var entry = new WplPlaylistEntry() { Path = NormalizeItemPath(playlistPath, child.Path), TrackTitle = child.Name, AlbumTitle = child.Album }; var hasAlbumArtist = child as IHasAlbumArtist; if (hasAlbumArtist != null) { entry.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); } var hasArtist = child as IHasArtist; if (hasArtist != null) { entry.TrackArtist = hasArtist.Artists.FirstOrDefault(); } if (child.RunTimeTicks.HasValue) { entry.Duration = TimeSpan.FromTicks(child.RunTimeTicks.Value); } playlist.PlaylistEntries.Add(entry); } string text = new WplContent().ToText(playlist); File.WriteAllText(playlistPath, text); } if (string.Equals(".zpl", extension, StringComparison.OrdinalIgnoreCase)) { var playlist = new ZplPlaylist(); foreach (var child in item.GetLinkedChildren()) { var entry = new ZplPlaylistEntry() { Path = NormalizeItemPath(playlistPath, child.Path), TrackTitle = child.Name, AlbumTitle = child.Album }; var hasAlbumArtist = child as IHasAlbumArtist; if (hasAlbumArtist != null) { entry.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); } var hasArtist = child as IHasArtist; if (hasArtist != null) { entry.TrackArtist = hasArtist.Artists.FirstOrDefault(); } if (child.RunTimeTicks.HasValue) { entry.Duration = TimeSpan.FromTicks(child.RunTimeTicks.Value); } playlist.PlaylistEntries.Add(entry); } string text = new ZplContent().ToText(playlist); File.WriteAllText(playlistPath, text); } if (string.Equals(".m3u", extension, StringComparison.OrdinalIgnoreCase)) { var playlist = new M3uPlaylist(); playlist.IsExtended = true; foreach (var child in item.GetLinkedChildren()) { var entry = new M3uPlaylistEntry() { Path = NormalizeItemPath(playlistPath, child.Path), Title = child.Name, Album = child.Album }; var hasAlbumArtist = child as IHasAlbumArtist; if (hasAlbumArtist != null) { entry.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); } if (child.RunTimeTicks.HasValue) { entry.Duration = TimeSpan.FromTicks(child.RunTimeTicks.Value); } playlist.PlaylistEntries.Add(entry); } string text = new M3uContent().ToText(playlist); File.WriteAllText(playlistPath, text); } if (string.Equals(".m3u8", extension, StringComparison.OrdinalIgnoreCase)) { var playlist = new M3uPlaylist(); playlist.IsExtended = true; foreach (var child in item.GetLinkedChildren()) { var entry = new M3uPlaylistEntry() { Path = NormalizeItemPath(playlistPath, child.Path), Title = child.Name, Album = child.Album }; var hasAlbumArtist = child as IHasAlbumArtist; if (hasAlbumArtist != null) { entry.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); } if (child.RunTimeTicks.HasValue) { entry.Duration = TimeSpan.FromTicks(child.RunTimeTicks.Value); } playlist.PlaylistEntries.Add(entry); } string text = new M3u8Content().ToText(playlist); File.WriteAllText(playlistPath, text); } if (string.Equals(".pls", extension, StringComparison.OrdinalIgnoreCase)) { var playlist = new PlsPlaylist(); foreach (var child in item.GetLinkedChildren()) { var entry = new PlsPlaylistEntry() { Path = NormalizeItemPath(playlistPath, child.Path), Title = child.Name }; if (child.RunTimeTicks.HasValue) { entry.Length = TimeSpan.FromTicks(child.RunTimeTicks.Value); } playlist.PlaylistEntries.Add(entry); } string text = new PlsContent().ToText(playlist); File.WriteAllText(playlistPath, text); } }