コード例 #1
0
        internal async Task <SeasonResult> FetchMainResult(string id, int seasonNumber, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(GetTvInfo3, id, seasonNumber.ToString(CultureInfo.InvariantCulture), TmdbUtils.ApiKey);

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

            var includeImageLanguageParam = TmdbMovieProvider.GetImageLanguagesParam(language);

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

            cancellationToken.ThrowIfCancellationRequested();

            using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = TmdbUtils.AcceptHeader
            }).ConfigureAwait(false))
            {
                using (var json = response.Content)
                {
                    return(await _jsonSerializer.DeserializeFromStreamAsync <SeasonResult>(json).ConfigureAwait(false));
                }
            }
        }
コード例 #2
0
ファイル: TmdbBoxSetProvider.cs プロジェクト: xumix/jellyfin
        private async Task <CollectionResult> FetchMainResult(string id, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(GetCollectionInfo3, id, TmdbUtils.ApiKey);

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

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

            cancellationToken.ThrowIfCancellationRequested();

            CollectionResult mainResult;

            using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = TmdbUtils.AcceptHeader
            }).ConfigureAwait(false))
            {
                using (var json = response.Content)
                {
                    mainResult = await _json.DeserializeFromStreamAsync <CollectionResult>(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, TmdbUtils.ApiKey) + "&language=en";

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

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

            return(mainResult);
        }
コード例 #3
0
        internal async Task <SeasonResult> FetchMainResult(string id, int seasonNumber, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(
                CultureInfo.InvariantCulture,
                GetTvInfo3,
                id,
                seasonNumber.ToString(CultureInfo.InvariantCulture),
                TmdbUtils.ApiKey);

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

            var includeImageLanguageParam = TmdbMovieProvider.GetImageLanguagesParam(language);

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

            cancellationToken.ThrowIfCancellationRequested();

            using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
            foreach (var header in TmdbUtils.AcceptHeaders)
            {
                requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
            }

            using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage, cancellationToken).ConfigureAwait(false);

            await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

            return(await _jsonSerializer.DeserializeFromStreamAsync <SeasonResult>(stream).ConfigureAwait(false));
        }
コード例 #4
0
        private async Task <CollectionResult> FetchMainResult(string id, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(CultureInfo.InvariantCulture, GetCollectionInfo3, id, TmdbUtils.ApiKey);

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

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

            cancellationToken.ThrowIfCancellationRequested();

            using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
            foreach (var header in TmdbUtils.AcceptHeaders)
            {
                requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
            }

            using var mainResponse = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage, cancellationToken).ConfigureAwait(false);

            await using var stream = await mainResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);

            var mainResult = await _json.DeserializeFromStreamAsync <CollectionResult>(stream).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();

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

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

                    using var langRequestMessage = new HttpRequestMessage(HttpMethod.Get, url);
                    foreach (var header in TmdbUtils.AcceptHeaders)
                    {
                        langRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
                    }

                    await using var langStream = await mainResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);

                    mainResult = await _json.DeserializeFromStreamAsync <CollectionResult>(langStream).ConfigureAwait(false);
                }
            }

            return(mainResult);
        }
コード例 #5
0
ファイル: TmdbSeriesProvider.cs プロジェクト: zjklee/jellyfin
        internal async Task <SeriesResult> FetchMainResult(string id, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(GetTvInfo3, id, TmdbUtils.ApiKey);

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

            cancellationToken.ThrowIfCancellationRequested();

            SeriesResult mainResult;

            using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = TmdbUtils.AcceptHeader
            }).ConfigureAwait(false))
            {
                using (var json = response.Content)
                {
                    mainResult = await _jsonSerializer.DeserializeFromStreamAsync <SeriesResult>(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.LogInformation("MovieDbSeriesProvider couldn't find meta for language {Language}. Trying English...", language);

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

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

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

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

            return(mainResult);
        }
コード例 #6
0
        internal async Task <SeriesResult> FetchMainResult(string id, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(GetTvInfo3, id, TmdbUtils.ApiKey);

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

            cancellationToken.ThrowIfCancellationRequested();

            using var mainRequestMessage = new HttpRequestMessage(HttpMethod.Get, url);
            foreach (var header in TmdbUtils.AcceptHeaders)
            {
                mainRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
            }

            using var mainResponse = await TmdbMovieProvider.Current.GetMovieDbResponse(mainRequestMessage);

            await using var mainStream = await mainResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);

            var mainResult = await _jsonSerializer.DeserializeFromStreamAsync <SeriesResult>(mainStream).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.LogInformation("MovieDbSeriesProvider couldn't find meta for language {Language}. Trying English...", language);

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

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

                using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
                foreach (var header in TmdbUtils.AcceptHeaders)
                {
                    mainRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header));
                }

                using var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage);

                await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                var englishResult = await _jsonSerializer.DeserializeFromStreamAsync <SeriesResult>(stream).ConfigureAwait(false);

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

            return(mainResult);
        }