/// <summary>
        /// Merge two album metadata instances
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public static AlbumMetadata Merge(AlbumMetadata first, AlbumMetadata second)
        {
            // Merge the artwork:

            var outputList = new List <Artwork>(first.Artwork ?? new Artwork[0]);;

            foreach (var image in second.Artwork)
            {
                if (outputList.Contains(image))
                {
                    continue;
                }
                if (first.FindMatch(outputList, image) != null)
                {
                    continue;
                }
                outputList.Add(image);
            }
            int?rating = first.Rating ?? second.rating;

            if (first.Rating.HasValue && second.rating.HasValue)
            {
                rating = (first.rating.Value + second.Rating.Value) / 2;
            }

            return(new AlbumMetadata
            {
                ArtistName = string.IsNullOrWhiteSpace(first.ArtistName) ? second.ArtistName : first.ArtistName,
                Artwork = outputList.ToArray(),
                Comments = string.IsNullOrWhiteSpace(first.Comments) ? second.Comments : first.Comments,
                DiscCount = first.DiscCount < second.DiscCount ? second.DiscCount : first.DiscCount,
                IsCollection = first.IsCollection | second.IsCollection,
                Name = string.IsNullOrWhiteSpace(first.Name) ? second.Name : first.Name,
                Rating = rating,
                SortName = string.IsNullOrWhiteSpace(first.SortName) ? second.SortName : first.sortName,
                TrackCount = first.TrackCount < second.TrackCount ? second.TrackCount : first.TrackCount,
                Year = first.Year ?? second.Year
            });
        }
        /// <summary>
        /// Create an album from a bunch of songs
        /// </summary>
        /// <param name="songs"></param>
        /// <returns></returns>
        public static AlbumMetadata Factory(IEnumerable <SongMetadata> songs = null)
        {
            // If no songs, create an empty album

            if (songs == null)
            {
                return(new AlbumMetadata());
            }

            // Compute the number of tracks in the album:

            int?trackCount = (from song in songs
                              where song.TrackCount.HasValue
                              select song.TrackCount).Max();
            int?trackMax = songs.Max(song => song.TrackNumber);

            trackCount = trackCount ?? trackMax ?? songs.Count();
            int?discCount = (from song in songs
                             where song.DiscCount.HasValue
                             select song.DiscCount).Max();
            int?discMax = songs.Max(song => song.DiscNumber);

            discCount = discCount ?? discMax;

            string albumArtist = (from song in songs
                                  where !string.IsNullOrWhiteSpace(song.AlbumArtist)
                                  select song.AlbumArtist).FirstOrDefault();

            var ret = new AlbumMetadata
            {
                ArtistName = albumArtist,
                DiscCount  = discCount,
            };

            ret.ClearChanges();
            return(ret);
        }