/// <summary>
        /// Gets the TMDB id.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{System.String}.</returns>
        private async Task <string> GetTmdbId(BaseItem person, CancellationToken cancellationToken)
        {
            string url = string.Format(@"http://api.themoviedb.org/3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(person.Name), MovieDbProvider.ApiKey);
            PersonSearchResults searchResult = null;

            using (Stream json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = MovieDbProvider.AcceptHeader
            }).ConfigureAwait(false))
            {
                searchResult = JsonSerializer.DeserializeFromStream <PersonSearchResults>(json);
            }

            return(searchResult != null && searchResult.Total_Results > 0 ? searchResult.Results[0].Id.ToString(UsCulture) : null);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the TMDB id.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{System.String}.</returns>
        private async Task <string> GetTmdbId(BaseItem person, CancellationToken cancellationToken)
        {
            string url = string.Format(@"http://api.themoviedb.org/3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(person.Name), MovieDbProvider.ApiKey);
            PersonSearchResults searchResult = null;

            try
            {
                using (Stream json = await HttpClient.Get(url, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
                {
                    searchResult = JsonSerializer.DeserializeFromStream <PersonSearchResults>(json);
                }
            }
            catch (HttpException)
            {
            }

            return(searchResult != null && searchResult.Total_Results > 0 ? searchResult.Results[0].Id.ToString() : null);
        }