Esempio n. 1
0
        internal async Task <RootObject> FetchMainResult(string id, int seasonNumber, string language, string preferredMetadataCountry, CancellationToken cancellationToken)
        {
            var url = string.Format(GetTvInfo3, id, seasonNumber.ToString(CultureInfo.InvariantCulture), MovieDbProvider.ApiKey);

            if (!string.IsNullOrEmpty(language))
            {
                url += string.Format("&language={0}", MovieDbProvider.NormalizeLanguage(language, preferredMetadataCountry));
            }

            var includeImageLanguageParam = MovieDbProvider.GetImageLanguagesParam(language, preferredMetadataCountry);

            // Get images in english and with no language
            url += "&include_image_language=" + includeImageLanguageParam;

            cancellationToken.ThrowIfCancellationRequested();

            using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = MovieDbProvider.AcceptHeader
            }).ConfigureAwait(false))
            {
                using (var json = response.Content)
                {
                    return(await _jsonSerializer.DeserializeFromStreamAsync <RootObject>(json).ConfigureAwait(false));
                }
            }
        }
Esempio n. 2
0
        private async Task <RootObject> FetchMainResult(string id, string language, string preferredMetadataCountry, CancellationToken cancellationToken)
        {
            var url = string.Format(GetCollectionInfo3, id, MovieDbProvider.ApiKey);

            if (!string.IsNullOrEmpty(language))
            {
                url += string.Format("&language={0}", MovieDbProvider.NormalizeLanguage(language, preferredMetadataCountry));

                // Get images in english and with no language
                url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language, preferredMetadataCountry);
            }

            cancellationToken.ThrowIfCancellationRequested();

            RootObject mainResult = null;

            using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = MovieDbSearch.AcceptHeader
            }).ConfigureAwait(false))
            {
                using (var json = response.Content)
                {
                    mainResult = await _json.DeserializeFromStreamAsync <RootObject>(json).ConfigureAwait(false);
                }
            }

            cancellationToken.ThrowIfCancellationRequested();

            if (mainResult != null && string.IsNullOrEmpty(mainResult.name))
            {
                if (!string.IsNullOrEmpty(language) && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
                {
                    url = string.Format(GetCollectionInfo3, id, MovieDbSearch.ApiKey) + "&language=en";

                    if (!string.IsNullOrEmpty(language))
                    {
                        // Get images in english and with no language
                        url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language, preferredMetadataCountry);
                    }

                    using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = cancellationToken,
                        AcceptHeader = MovieDbSearch.AcceptHeader
                    }).ConfigureAwait(false))
                    {
                        using (var json = response.Content)
                        {
                            mainResult = await _json.DeserializeFromStreamAsync <RootObject>(json).ConfigureAwait(false);
                        }
                    }
                }
            }
            return(mainResult);
        }
Esempio n. 3
0
 public MovieDbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IApplicationHost appHost)
 {
     _jsonSerializer       = jsonSerializer;
     _httpClient           = httpClient;
     _fileSystem           = fileSystem;
     _configurationManager = configurationManager;
     _logger         = logger;
     _localization   = localization;
     _libraryManager = libraryManager;
     _appHost        = appHost;
     Current         = this;
 }
Esempio n. 4
0
        internal async Task <RootObject> FetchMainResult(string id, string language, string country, CancellationToken cancellationToken)
        {
            var url = string.Format(GetTvInfo3, id, MovieDbProvider.ApiKey);

            if (!string.IsNullOrEmpty(language))
            {
                url += string.Format("&language={0}", MovieDbProvider.NormalizeLanguage(language, country));

                // Get images in english and with no language
                url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language, country);
            }

            cancellationToken.ThrowIfCancellationRequested();

            RootObject mainResult;

            using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = MovieDbProvider.AcceptHeader
            }).ConfigureAwait(false))
            {
                using (var json = response.Content)
                {
                    mainResult = await _jsonSerializer.DeserializeFromStreamAsync <RootObject>(json).ConfigureAwait(false);

                    if (!string.IsNullOrEmpty(language))
                    {
                        mainResult.ResultLanguage = language;
                    }
                }
            }

            cancellationToken.ThrowIfCancellationRequested();

            // If the language preference isn't english, then have the overview fallback to english if it's blank
            if (mainResult != null &&
                string.IsNullOrEmpty(mainResult.overview) &&
                !string.IsNullOrEmpty(language) &&
                !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
            {
                _logger.Info("MovieDbSeriesProvider couldn't find meta for language " + language + ". Trying English...");

                url = string.Format(GetTvInfo3, id, MovieDbProvider.ApiKey) + "&language=en";

                if (!string.IsNullOrEmpty(language))
                {
                    // Get images in english and with no language
                    url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language, country);
                }

                using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
                {
                    Url = url,
                    CancellationToken = cancellationToken,
                    AcceptHeader = MovieDbProvider.AcceptHeader
                }).ConfigureAwait(false))
                {
                    using (var json = response.Content)
                    {
                        var englishResult = await _jsonSerializer.DeserializeFromStreamAsync <RootObject>(json).ConfigureAwait(false);

                        mainResult.overview       = englishResult.overview;
                        mainResult.ResultLanguage = "en";
                    }
                }
            }

            return(mainResult);
        }