/// <summary> /// Add a new playlist with the specified name to the current library /// </summary> /// <param name="playlistName"></param> public static async Task <AlbumPlaylist> AddAlbumPlaylistAsync(string playlistName) { AlbumPlaylist newPlaylist = new() { Name = playlistName, LibraryId = PlaylistsViewModel.LibraryId }; await Playlists.AddPlaylistAsync(newPlaylist); // Refresh the playlists held by the model and report the change StorageDataAvailable(); return(newPlaylist); }
/// <summary> /// Duplicate the SongPlaylist in the specified library /// </summary> /// <param name="playlistToDuplicate"></param> /// <returns></returns> private static async void DuplicateSongPlaylistAsync(SongPlaylist playlistToDuplicate, int libraryId) { // Attempt to find matching songs for each SongPlaylistItem in the SongPlaylist // Need to access the songs via the Sources associated with the Library List <Source> sources = Sources.GetSourcesForLibrary(libraryId); // Keep track of the matching songs List <Song> songsToAdd = new(); foreach (SongPlaylistItem item in playlistToDuplicate.PlaylistItems) { Song matchingSong = null; int sourceIndex = 0; while ((matchingSong == null) && (sourceIndex < sources.Count)) { // Get a list of all the songs with matching Titles in the source List <Song> matchingTitles = Songs.GetSourceSongsWithName(sources[sourceIndex++].Id, item.Song.Title); // Now for each song access the associated artist int titleIndex = 0; while ((matchingSong == null) && (titleIndex < matchingTitles.Count)) { Artist nameCheck = Artists.GetArtistById(ArtistAlbums.GetArtistAlbumById(matchingTitles[titleIndex].ArtistAlbumId).ArtistId); // Correct name? if (nameCheck.Name == item.Artist.Name) { matchingSong = matchingTitles[titleIndex]; songsToAdd.Add(matchingSong); // Make sure that the Artist is stored with the song matchingSong.Artist = nameCheck; } titleIndex++; } } } // Only create the playlist if at least one of the songs was found if (songsToAdd.Count > 0) { SongPlaylist duplicatedPlaylist = new() { Name = playlistToDuplicate.Name, LibraryId = libraryId }; // Wait for the playlist to be added as we're going to use its id await Playlists.AddPlaylistAsync(duplicatedPlaylist); // Add the songs to the new SongPlaylist. duplicatedPlaylist.AddSongs(songsToAdd); } }
/// <summary> /// Duplicate the AlbumPlaylist in the specified library /// </summary> /// <param name="playlistToDuplicate"></param> /// <param name="libararyId"></param> private static async void DuplicateAlbumPlaylistAsync(AlbumPlaylist playlistToDuplicate, int libraryId) { List <Album> albumsToAdd = new(); foreach (AlbumPlaylistItem item in playlistToDuplicate.PlaylistItems) { // Find a matching Album name with the same Artist name Album matchingAlbum = Albums.AlbumCollection.Where(album => (album.LibraryId == libraryId) && (album.Name == item.Album.Name) && (album.ArtistName == item.Album.ArtistName)).FirstOrDefault(); if (matchingAlbum != null) { albumsToAdd.Add(matchingAlbum); } } // Only create the playlist if we've got something to add to it if (albumsToAdd.Count > 0) { AlbumPlaylist duplicatedPlaylist = new() { Name = playlistToDuplicate.Name, LibraryId = libraryId }; await Playlists.AddPlaylistAsync(duplicatedPlaylist); duplicatedPlaylist.AddAlbums(albumsToAdd); } }