示例#1
0
        public async Task <AudioDbArtist> GetArtistAsync(long tadbArtistID, string language, bool cacheOnly)
        {
            AudioDbArtists audioDbArtists = null;
            string         cache          = CreateAndGetCacheName(tadbArtistID, "Artist");

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                audioDbArtists = await _downloader.ReadCacheAsync <AudioDbArtists>(cache).ConfigureAwait(false);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_ARTIST_BY_TADB, tadbArtistID);
                audioDbArtists = await _downloader.DownloadAsync <AudioDbArtists>(url, cache).ConfigureAwait(false);
            }
            if (audioDbArtists.Artists != null && audioDbArtists.Artists.Count > 0)
            {
                AudioDbArtist artist = audioDbArtists.Artists.Where(a => a.ArtistId > 0).FirstOrDefault();
                if (artist != null)
                {
                    artist.SetLanguage(language);
                }
                return(artist);
            }
            return(null);
        }
        public override async Task <bool> UpdateFromOnlineMusicTrackAlbumPersonAsync(AlbumInfo albumInfo, PersonInfo person, string language, bool cacheOnly)
        {
            try
            {
                AudioDbArtist artistDetail = null;
                language = language ?? PreferredLanguage;

                if (person.AudioDbId > 0)
                {
                    artistDetail = await _audioDbHandler.GetArtistAsync(person.AudioDbId, language, cacheOnly).ConfigureAwait(false);
                }
                if (artistDetail == null && !string.IsNullOrEmpty(person.MusicBrainzId))
                {
                    List <AudioDbArtist> foundArtists = await _audioDbHandler.GetArtistByMbidAsync(person.MusicBrainzId, language, cacheOnly).ConfigureAwait(false);

                    if (foundArtists != null && foundArtists.Count == 1)
                    {
                        artistDetail = await _audioDbHandler.GetArtistAsync(foundArtists[0].ArtistId, language, cacheOnly).ConfigureAwait(false);
                    }
                }
                if (artistDetail == null)
                {
                    return(false);
                }

                bool languageSet = artistDetail.SetLanguage(language);

                int?     year = artistDetail.BornYear == null ? artistDetail.FormedYear : artistDetail.BornYear;
                DateTime?born = null;
                if (year.HasValue && year.Value > 1900)
                {
                    born = new DateTime(year.Value, 1, 1);
                }
                DateTime?died = null;
                if (artistDetail.DiedYear.HasValue && artistDetail.DiedYear.Value > 1900)
                {
                    died = new DateTime(artistDetail.DiedYear.Value, 1, 1);
                }

                person.MusicBrainzId = artistDetail.MusicBrainzID;
                person.Name          = artistDetail.Artist;
                person.AlternateName = artistDetail.ArtistAlternate;
                person.Biography     = new SimpleTitle(artistDetail.Biography, !languageSet);
                person.DateOfBirth   = born;
                person.DateOfDeath   = died;
                person.Orign         = artistDetail.Country;
                person.IsGroup       = artistDetail.Members.HasValue ? artistDetail.Members.Value > 1 : false;
                person.Occupation    = PersonAspect.OCCUPATION_ARTIST;

                return(true);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug("TheAudioDbWrapper: Exception while processing person {0}", ex, person.ToString());
                return(false);
            }
        }