public bool RemoveArtist(Artist input) { if (input != null) { if (Artists.Count != 0) { if (Artists.Contains(input)) { Artists.Remove(input); return(true); } else { return(false); } } else { return(false); } } else { throw new ArgumentNullException(); } }
private void LoadAlbumAndArtists() { foreach (var song in Songs) { if (!Albums.Contains(song.Album)) { Albums.Add(song.Album); } if (!Artists.Contains(song.Artist)) { Artists.Add(song.Artist); } } }
private void OnLibraryUpdated(Track track) { var returnToArtist = SelectedArtist; SelectedArtist = null; if (track == null) { ResetSelections(); FilterGroupings(); } else { FilterArtists(); } if (Artists.Contains(returnToArtist)) { SelectedArtist = returnToArtist; } }
public void AddSong(Song song) { if (!songCore.ContainsKey(song.ID)) { songCore.Add(song.ID, song); if (!Albums.Contains(song.Album)) { Albums.Add(song.Album); } if (!Artists.Contains(song.Artist)) { Artists.Add(song.Artist); } //LoadAlbumAndArtists(); } else if (!songCore[song.ID].Equals(song)) { songCore[song.ID].Merge(song); LoadAlbumAndArtists(); } }
/// <summary> /// Determines whether the specified name has artist. /// </summary> /// <param name="name">The name.</param> /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns> public bool HasArtist(string name) { return(Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Determines whether the specified artist has artist. /// </summary> /// <param name="artist">The artist.</param> /// <returns><c>true</c> if the specified artist has artist; otherwise, <c>false</c>.</returns> public bool HasArtist(string artist) { return(string.Equals(AlbumArtist, artist, StringComparison.OrdinalIgnoreCase) || Artists.Contains(artist, StringComparer.OrdinalIgnoreCase)); }
public async Task AddSongAsync(Song song, Tag tags = null) { var primaryArtist = (song.Album == null ? song.Artist : song.Album.PrimaryArtist) ?? new Artist { Name = "Unknown Artist", ProviderId = "autc.unknown" }; var artist = _inProgressArtists.Union(Artists).FirstOrDefault( entry => entry.ProviderId == primaryArtist.ProviderId || string.Equals(entry.Name, primaryArtist.Name, StringComparison.CurrentCultureIgnoreCase)); if (artist == null) { await _sqlService.InsertAsync(primaryArtist); _inProgressArtists.Add(primaryArtist); song.Artist = primaryArtist; song.ArtistId = primaryArtist.Id; if (song.Album != null) { song.Album.PrimaryArtistId = song.Artist.Id; song.Album.PrimaryArtist = song.Artist; } } else { song.Artist = artist; if (song.Album != null) { song.Album.PrimaryArtistId = artist.Id; song.Album.PrimaryArtist = artist; } } song.ArtistId = song.Artist.Id; if (song.Album == null) { song.Album = new Album { PrimaryArtistId = song.ArtistId, Name = song.Name, PrimaryArtist = song.Artist, ProviderId = "autc.single." + song.ProviderId }; } var album = _inProgressAlbums.Union(Albums).FirstOrDefault(p => p.ProviderId == song.Album.ProviderId); if (album != null) { song.Album = album; } else { await _sqlService.InsertAsync(song.Album); _inProgressAlbums.Add(song.Album); await _dispatcher.RunAsync(() => { var artwork = song.Artist.HasArtwork ? song.Artist.Artwork : _missingArtwork; song.Album.Artwork = artwork; song.Album.MediumArtwork = artwork; song.Album.SmallArtwork = artwork; }); if (tags != null && tags.Pictures != null && tags.Pictures.Length > 0) { var albumFilePath = string.Format(_artworkFilePath, song.Album.Id); Stream artwork = null; var image = tags.Pictures.FirstOrDefault(); if (image != null) { artwork = new MemoryStream(image.Data.Data); } if (artwork != null) { using (artwork) { try { var file = await StorageHelper.CreateFileAsync( albumFilePath, option : CreationCollisionOption.ReplaceExisting); using (var fileStream = await file.OpenAsync(FileAccess.ReadAndWrite)) { var bytes = tags.Pictures[0].Data.Data; await fileStream.WriteAsync(bytes, 0, bytes.Length); song.Album.HasArtwork = true; await _sqlService.UpdateItemAsync(song.Album); } } catch { // ignored } } } // set it if (song.Album.HasArtwork) { await _dispatcher.RunAsync( () => { var path = _localFilePrefix + albumFilePath; song.Album.Artwork = _bitmapFactory.CreateImage(new Uri(path)); if (ScaledImageSize == 0) { return; } song.Album.Artwork.SetDecodedPixel(ScaledImageSize); song.Album.MediumArtwork = _bitmapFactory.CreateImage(new Uri(path)); song.Album.MediumArtwork.SetDecodedPixel(ScaledImageSize / 2); song.Album.SmallArtwork = _bitmapFactory.CreateImage(new Uri(path)); song.Album.SmallArtwork.SetDecodedPixel(50); }); } } } song.AlbumId = song.Album.Id; if (string.IsNullOrEmpty(song.ArtistName)) { song.ArtistName = song.Artist.Name; } await _sqlService.InsertAsync(song); await _dispatcher.RunAsync( () => { if (!song.IsTemp) { var orderedAlbumSong = song.Album.Songs.ToList(); orderedAlbumSong.Add(song); orderedAlbumSong = orderedAlbumSong.OrderBy(p => p.TrackNumber).ToList(); var index = orderedAlbumSong.IndexOf(song); song.Album.Songs.Insert(index, song); var orderedArtistSong = song.Artist.Songs.ToList(); orderedArtistSong.Add(song); orderedArtistSong = orderedArtistSong.OrderBy(p => p.Name).ToList(); index = orderedArtistSong.IndexOf(song); song.Artist.Songs.Insert(index, song); #region Order artist album if (!song.Artist.Albums.Contains(song.Album)) { var orderedArtistAlbum = song.Artist.Albums.ToList(); orderedArtistAlbum.Add(song.Album); orderedArtistAlbum = orderedArtistAlbum.OrderBy(p => p.Name).ToList(); index = orderedArtistAlbum.IndexOf(song.Album); song.Artist.Albums.Insert(index, song.Album); } #endregion } _inProgressAlbums.Remove(song.Album); _inProgressArtists.Remove(song.Artist); if (!Albums.Contains(song.Album)) { Albums.Add(song.Album); } else if (song.Album.Songs.Count == 1) { // This means the album was added with a temp song // Have to remove and readd it to get it to show up Albums.Remove(song.Album); Albums.Add(song.Album); } if (!Artists.Contains(song.Artist)) { Artists.Add(song.Artist); } else if (song.Artist.Songs.Count == 1) { // This means the album was added with a temp song // Have to remove and readd it to get it to show up Artists.Remove(song.Artist); Artists.Add(song.Artist); } Songs.Add(song); }); }
public override void SaveChanges() { _context.Artists.AddOrUpdate(Artists.ToArray()); _context.Albums.AddOrUpdate(Albums.ToArray()); _context.Tracks.AddOrUpdate(Tracks.ToArray()); RemoveEntities(_context.Artists, _context.Artists.AsEnumerable().Where(a => !Artists.Contains(a))); RemoveEntities(_context.Albums, _context.Albums.AsEnumerable().Where(a => !Albums.Contains(a))); RemoveEntities(_context.Tracks, _context.Tracks.AsEnumerable().Where(a => !Tracks.Contains(a))); _context.SaveChanges(); }