public void Serialize_LengthNotNumberBecomesZero_True() { var sb = new StringBuilder() .AppendLine("[playlist]") .AppendLine() .AppendLine("File1=test path") .AppendLine("Length1=0") .AppendLine() .AppendLine("NumberOfEntries=1") .AppendLine("Version=2"); var serializer = new PlsSerializer(); var pls = new PlsPlaylist { Version = "2" }; pls.Add(new PlsItem("test path") { Length = "sgsgsgsg" }); var result = serializer.Serialize(pls); sb.ToString().Should().Be(result); }
public void Create_CreatePlaylistAndCompareWithFile_Equal() { PlsContent content = new PlsContent(); PlsPlaylist playlist = new PlsPlaylist(); playlist.Version = 2; playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.Zero, Nr = 1, Path = "http://stream3.polskieradio.pl:8902/", Title = null, }); playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.FromSeconds(-1), Nr = 1, Path = "http://stream.polskastacja.pl/ps43_mp3?player_group=PS_EXT_MP3", Title = "Server1-> >>> P O L S K A S T A C J A <<<- Ballady Rockowe", }); playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.FromSeconds(5720), Nr = 1, Path = "/home/uzytkownik/muzyka-1.mp3", Title = "Myslovitz - Sprzedawcy Marzeń", }); string created = content.ToText(playlist); string fromFile = Helpers.Read("Playlist.pls"); Assert.AreEqual(created, fromFile); }
public void Serialize_ItemTitleSerializedCorrect_True() { var sb = new StringBuilder() .AppendLine("[playlist]") .AppendLine() .AppendLine("File1=test path") .AppendLine("Title1=test title") .AppendLine() .AppendLine("NumberOfEntries=1") .AppendLine("Version=2"); var serializer = new PlsSerializer(); var pls = new PlsPlaylist { Version = "2" }; pls.Add(new PlsItem("test path") { Title = "test title" }); var result = serializer.Serialize(pls); sb.ToString().Should().Be(result); }
private static string SerializePlaylist(IPlaylist playlist, Format fileFormat) { switch (fileFormat) { case Format.XSPF: var xspfSerializer = new XspfSerializer(); var xspfPl = new XspfPlaylist(playlist); return(xspfSerializer.Serialize(xspfPl)); case Format.WPL: var wplSerializer = new WplSerializer(); var wplPlaylist = new WplPlaylist(playlist); return(wplSerializer.Serialize(wplPlaylist)); case Format.M3U: var m3USerializer = new M3uSerializer(); var m3UPlaylist = new M3uPlaylist(playlist); return(m3USerializer.Serialize(m3UPlaylist)); case Format.ASX: var asxSerializer = new AsxSerializer(); var asxPlaylist = new AsxPlaylist(playlist); return(asxSerializer.Serialize(asxPlaylist)); case Format.PLS: var plsSerializer = new PlsSerializer(); var plsPlaylist = new PlsPlaylist(playlist); return(plsSerializer.Serialize(plsPlaylist)); } return(String.Empty); }
private void CreatePlaylist() { string folder = textBoxFolder.Text; string textPlaylist = string.Empty; string playlistExtension = string.Empty; switch (comboBoxPlaylist.SelectedItem) { case Constants.WinMediaPlayerPLS: PlsPlaylist plsPlaylist = new PlsPlaylist(); playlistExtension = "pls"; foreach (var episode in listBoxEpisodes.Items) { plsPlaylist.PlaylistEntries.Add(new PlsPlaylistEntry() { Path = Path.Combine(folder, episode.ToString()), Title = Path.GetFileNameWithoutExtension(episode.ToString()) }); } PlsContent plsContent = new PlsContent(); textPlaylist = plsContent.ToText(plsPlaylist); break; case Constants.WinampM3U: M3uPlaylist m3uPlaylist = new M3uPlaylist(); playlistExtension = "m3u"; foreach (var episode in listBoxEpisodes.Items) { m3uPlaylist.PlaylistEntries.Add(new M3uPlaylistEntry() { Path = Path.Combine(folder, episode.ToString()), Title = Path.GetFileNameWithoutExtension(episode.ToString()) }); } M3uContent m3uContent = new M3uContent(); textPlaylist = m3uContent.ToText(m3uPlaylist); break; default: break; } string playlistName = $"Playlist - {Utils.GetTimestamp(DateTime.Now)}"; string playlistFullName = Path.Combine(folder, $"{playlistName}.{playlistExtension}"); using (FileStream fs = File.Create(playlistFullName)) { byte[] info = new UTF8Encoding(true).GetBytes(textPlaylist); fs.Write(info, 0, info.Length); } }
/// <summary> /// Returns the playlist in pls format. /// </summary> private string CreatePlsPlaylist() { var playlist = new PlsPlaylist(); foreach (Track track in _album.Tracks) { playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.FromSeconds(track.Duration), Path = Path.GetFileName(track.Path), Title = track.Title, }); } return(new PlsContent().ToText(playlist)); }
public void Serialize_CorrectNumberOfEntries_True() { var pls = new PlsPlaylist { Version = "2" }; pls.Add(new PlsItem("test path") { Title = "test title", Length = "sgsgsgsg" }); pls.Add(new PlsItem("test path") { Title = "test title2", Length = "10" }); var serializer = new PlsSerializer(); var result = serializer.Serialize(pls); result.Should().Contain("NumberOfEntries=2"); }
public void GetFromStream_ReadPlaylistAndCompareWithObject_Equal() { PlsContent content = new PlsContent(); PlsPlaylist playlist = new PlsPlaylist(); playlist.Version = 2; playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.Zero, Nr = 1, Path = "http://stream3.polskieradio.pl:8902/", Title = null, }); playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.FromSeconds(-1), Nr = 2, Path = "http://stream.polskastacja.pl/ps43_mp3?player_group=PS_EXT_MP3", Title = "Server1-> >>> P O L S K A S T A C J A <<<- Ballady Rockowe", }); playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.FromSeconds(5720), Nr = 3, Path = "/home/uzytkownik/muzyka-1.mp3", Title = "Myslovitz - Sprzedawcy Marzeń", }); playlist.PlaylistEntries.Add(new PlsPlaylistEntry() { Length = TimeSpan.Zero, Nr = 4, Path = "Weird Al - This Is The Life.mp3", Title = "Weird Al Yankovic - This is the Life", }); var stream = Helpers.ReadStream("Playlist2.pls"); var file = content.GetFromStream(stream); stream.Dispose(); Assert.AreEqual(playlist.PlaylistEntries.Count, file.PlaylistEntries.Count); Assert.AreEqual(playlist.NumberOfEntries, file.NumberOfEntries); Assert.AreEqual(playlist.Version, file.Version); Assert.AreEqual(playlist.PlaylistEntries[0].Path, file.PlaylistEntries[0].Path); Assert.AreEqual(playlist.PlaylistEntries[1].Path, file.PlaylistEntries[1].Path); Assert.AreEqual(playlist.PlaylistEntries[2].Path, file.PlaylistEntries[2].Path); Assert.AreEqual(playlist.PlaylistEntries[3].Path, file.PlaylistEntries[3].Path); Assert.AreEqual(playlist.PlaylistEntries[0].Title, file.PlaylistEntries[0].Title); Assert.AreEqual(playlist.PlaylistEntries[1].Title, file.PlaylistEntries[1].Title); Assert.AreEqual(playlist.PlaylistEntries[2].Title, file.PlaylistEntries[2].Title); Assert.AreEqual(playlist.PlaylistEntries[3].Title, file.PlaylistEntries[3].Title); Assert.AreEqual(playlist.PlaylistEntries[0].Length, file.PlaylistEntries[0].Length); Assert.AreEqual(playlist.PlaylistEntries[1].Length, file.PlaylistEntries[1].Length); Assert.AreEqual(playlist.PlaylistEntries[2].Length, file.PlaylistEntries[2].Length); Assert.AreEqual(playlist.PlaylistEntries[3].Length, file.PlaylistEntries[3].Length); Assert.AreEqual(playlist.PlaylistEntries[0].Nr, file.PlaylistEntries[0].Nr); Assert.AreEqual(playlist.PlaylistEntries[1].Nr, file.PlaylistEntries[1].Nr); Assert.AreEqual(playlist.PlaylistEntries[2].Nr, file.PlaylistEntries[2].Nr); Assert.AreEqual(playlist.PlaylistEntries[3].Nr, file.PlaylistEntries[3].Nr); stream.Dispose(); }
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); } }