Example #1
0
 private void DeleteAlbum(Track track, Artist albumArtist)
 {
     var album = Albums.FirstOrDefault(p =>
         p.Title.EqualsIgnoreCase(track.AlbumTitle) && p.Artist == albumArtist);
     if (album == null)
     {
         return;
     }
     album.Tracks.Remove(track);
     if (album.Tracks.Count == 0)
     {
         Albums.Remove(album);
         albumArtist.Albums.Remove(album);
     }
 }
Example #2
0
        private void CreateSecondaryArtists(Track track)
        {
            var artistAppearing = track.Artists.Split(';').Select(p => p.Trim());

            foreach (var artistName in artistAppearing
                .Where(p => !p.EqualsIgnoreCase(track.DisplayArtist)
                    && !p.EqualsIgnoreCase(track.AlbumArtist)))
            {
                var artist = Artists.FirstOrDefault(p =>
                    p.Name.EqualsIgnoreCase(artistName));
                if (artist == null)
                {
                    artist = new Artist
                    {
                        Name = artistName
                    };
                    Artists.Add(artist);
                }

                artist.TracksThatAppearsIn.Add(track);
            }
        }
Example #3
0
        private void CreateDisplayArtist(Track track)
        {
            var displayArtist = Artists.FirstOrDefault(p =>
                p.Name.EqualsIgnoreCase(track.DisplayArtist));
            var newRelation = displayArtist == null;

            if (newRelation)
            {
                displayArtist = new Artist
                {
                    Name = track.DisplayArtist,
                    ArtworkUri = track.ArtistArtworkUri
                };
            }
            else if (displayArtist.ArtworkUri == null)
            {
                displayArtist.ArtworkUri = track.ArtistArtworkUri;
            }

            displayArtist.Tracks.Add(track);
            if (newRelation)
            {
                Artists.Add(displayArtist);
            }
        }
Example #4
0
        private void CreateRelatedObjects(Track track)
        {
            var displaySameAsAlbumArtist = track.DisplayArtist.EqualsIgnoreCase(track.AlbumArtist);

            var albumArtist = Artists.FirstOrDefault(p =>
                p.Name.EqualsIgnoreCase(track.AlbumArtist));
            var newRelation = albumArtist == null;

            if (newRelation)
            {
                albumArtist = new Artist
                {
                    Name = track.AlbumArtist,
                    ArtworkUri = track.AlbumArtist == track.DisplayArtist ? track.ArtistArtworkUri : null
                };
            }
            else if (albumArtist.ArtworkUri == null && displaySameAsAlbumArtist)
            {
                albumArtist.ArtworkUri = track.ArtistArtworkUri;
            }

            albumArtist.Tracks.Add(track);
            if (newRelation)
            {
                Artists.Add(albumArtist);
            }

            CreateAlbum(track, albumArtist);

            if (!displaySameAsAlbumArtist)
            {
                CreateDisplayArtist(track);
            }

            CreateSecondaryArtists(track);
        }
Example #5
0
        private void CreateAlbum(Track track, Artist albumArtist)
        {
            var album = Albums.FirstOrDefault(p =>
                p.Title.EqualsIgnoreCase(track.AlbumTitle) && p.Artist == albumArtist);
            if (album == null)
            {
                album = new Album
                {
                    Title = track.AlbumTitle,
                    Artist = albumArtist,
                    ArtworkUri = track.ArtworkUri,
                    Year = track.Year,
                    Copyright = track.Copyright,
                    Publisher = track.Publisher
                };
                Albums.Add(album);
                albumArtist.Albums.Add(album);
            }
            else if (album.ArtworkUri == null)
            {
                album.ArtworkUri = track.ArtworkUri;
            }

            var sort = album.Tracks.ToList();
            sort.Add(track);
            sort.Sort(
                (track1, track2) =>
                    (int)track1.TrackNumber + (int)track1.DiscCount - (int)(track2.TrackNumber + track2.DiscCount));
            var index = sort.IndexOf(track);
            album.Tracks.Insert(index, track);
        }