Exemple #1
0
        public static void Merge(this List <ArtistWithTracks> to, TrackWithArtists from)
        {
            foreach (var artist in from.Artists)
            {
                var existingArtistWithRoles = to.FirstOrDefault(t =>
                                                                t.Name.Trim().ToLower() == artist.Name.Trim().ToLower());
                if (existingArtistWithRoles == null)
                {
                    to.Add(new ArtistWithTracks
                    {
                        ArtistId = Guid.NewGuid(),
                        Name     = artist.Name,
                        Tracks   = new List <TrackByArtist>
                        {
                            new TrackByArtist
                            {
                                TrackId = from.TrackId, Type = artist.Type, File = from.File,
                                Name    = from.Name, IsFeatured = artist.IsFeatured, IsComposer = artist.IsComposer
                            }
                        }
                    });
                }
                else
                {
                    var existingTrack =
                        existingArtistWithRoles.Tracks.FirstOrDefault(t =>
                                                                      t.File.ToLower().Trim() == from.File.ToLower().Trim());
                    if (existingTrack == null)
                    {
                        existingArtistWithRoles.Tracks.Add(new TrackByArtist
                        {
                            File       = from.File,
                            Type       = artist.Type,
                            IsFeatured = artist.IsFeatured,
                            IsComposer = artist.IsComposer,
                            Name       = from.Name,
                            TrackId    = from.TrackId
                        });
                    }
                    else
                    {
                        if (existingTrack.IsComposer == false)
                        {
                            existingTrack.IsComposer = artist.IsComposer;
                        }

                        if (existingTrack.IsFeatured == false)
                        {
                            existingTrack.IsFeatured = artist.IsFeatured;
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static TrackWithArtists ExtractArtists(this FileWithTags input,
                                                      IArtistProcessor artistProcessor, TrackWithFile trackWithFile)
        {
            var trackWithArtistsWithRoles = new TrackWithArtists
            {
                File    = trackWithFile.File,
                Name    = trackWithFile.Name,
                TrackId = trackWithFile.TrackId,
                Artists = new List <Artist>(),
                TrackNo = trackWithFile.TrackNo,
                Year    = trackWithFile.Year
            };

            if (!string.IsNullOrEmpty(input.Composers))
            {
                var composers = artistProcessor.GetArtists(input.Composers, false, true);
                if (composers != null)
                {
                    trackWithArtistsWithRoles.Artists.AddRange(composers);
                }
            }
            if (!string.IsNullOrEmpty(input.Artists))
            {
                var artists = artistProcessor.GetArtists(input.Artists, false, false);
                if (artists != null)
                {
                    trackWithArtistsWithRoles.Artists.AddRange(artists);
                }
            }
            if (!string.IsNullOrEmpty(input.AlbumArtists))
            {
                var albumArtists = artistProcessor.GetArtists(input.AlbumArtists, false, false);
                if (albumArtists != null)
                {
                    trackWithArtistsWithRoles.Artists.AddRange(albumArtists);
                }
            }
            if (!string.IsNullOrEmpty(input.Title))
            {
                var featuredArtists = artistProcessor.GetArtists(input.Title, true, false);
                if (featuredArtists != null)
                {
                    trackWithArtistsWithRoles.Artists.AddRange(featuredArtists);
                }
            }

            return(trackWithArtistsWithRoles);
        }