当前位置: 首页>>代码示例>>C#>>正文


C# BaseItem.GetPreferredMetadataCountryCode方法代码示例

本文整理汇总了C#中BaseItem.GetPreferredMetadataCountryCode方法的典型用法代码示例。如果您正苦于以下问题:C# BaseItem.GetPreferredMetadataCountryCode方法的具体用法?C# BaseItem.GetPreferredMetadataCountryCode怎么用?C# BaseItem.GetPreferredMetadataCountryCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseItem的用法示例。


在下文中一共展示了BaseItem.GetPreferredMetadataCountryCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessMainInfo

        /// <summary>
        /// Processes the main info.
        /// </summary>
        /// <param name="movie">The movie.</param>
        /// <param name="movieData">The movie data.</param>
        private void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData)
        {
            if (!movie.LockedFields.Contains(MetadataFields.Name))
            {
                movie.Name = movieData.title ?? movieData.original_title ?? movieData.name ?? movie.Name;
            }
            if (!movie.LockedFields.Contains(MetadataFields.Overview))
            {
                // Bug in Mono: WebUtility.HtmlDecode should return null if the string is null but in Mono it generate an System.ArgumentNullException.
                movie.Overview = movieData.overview != null ? WebUtility.HtmlDecode(movieData.overview) : null;
                movie.Overview = movie.Overview != null ? movie.Overview.Replace("\n\n", "\n") : null;
            }
            movie.HomePageUrl = movieData.homepage;

            var hasBudget = movie as IHasBudget;
            if (hasBudget != null)
            {
                hasBudget.Budget = movieData.budget;
                hasBudget.Revenue = movieData.revenue;
            }

            if (!string.IsNullOrEmpty(movieData.tagline))
            {
                var hasTagline = movie as IHasTaglines;
                if (hasTagline != null)
                {
                    hasTagline.Taglines.Clear();
                    hasTagline.AddTagline(movieData.tagline);
                }
            }

            movie.SetProviderId(MetadataProviders.Tmdb, movieData.id.ToString(_usCulture));
            movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id);

            if (movieData.belongs_to_collection != null)
            {
                movie.SetProviderId(MetadataProviders.TmdbCollection,
                                    movieData.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture));

                var movieItem = movie as Movie;

                if (movieItem != null)
                {
                    movieItem.TmdbCollectionName = movieData.belongs_to_collection.name;
                }
            }
            else
            {
                movie.SetProviderId(MetadataProviders.TmdbCollection, null); // clear out any old entry
            }

            float rating;
            string voteAvg = movieData.vote_average.ToString(CultureInfo.InvariantCulture);

            // tmdb appears to have unified their numbers to always report "7.3" regardless of country
            // so I removed the culture-specific processing here because it was not working for other countries -ebr
            // Movies get this from imdb
            if (!(movie is Movie) && float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
            {
                movie.CommunityRating = rating;
            }

            // Movies get this from imdb
            if (!(movie is Movie))
            {
                movie.VoteCount = movieData.vote_count;
            }

            var preferredCountryCode = movie.GetPreferredMetadataCountryCode();

            //release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match
            if (movieData.releases != null && movieData.releases.countries != null)
            {
                var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(preferredCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country();
                var usRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country();
                var minimunRelease = movieData.releases.countries.OrderBy(c => c.release_date).FirstOrDefault() ?? new Country();

                if (!movie.LockedFields.Contains(MetadataFields.OfficialRating))
                {
                    var ratingPrefix = string.Equals(preferredCountryCode, "us", StringComparison.OrdinalIgnoreCase) ? "" : preferredCountryCode + "-";
                    movie.OfficialRating = !string.IsNullOrEmpty(ourRelease.certification)
                                               ? ratingPrefix + ourRelease.certification
                                               : !string.IsNullOrEmpty(usRelease.certification)
                                                     ? usRelease.certification
                                                     : !string.IsNullOrEmpty(minimunRelease.certification)
                                                           ? minimunRelease.iso_3166_1 + "-" + minimunRelease.certification
                                                           : null;
                }
            }

            if (movieData.release_date.Year != 1)
            {
                //no specific country release info at all
                movie.PremiereDate = movieData.release_date.ToUniversalTime();
                movie.ProductionYear = movieData.release_date.Year;
//.........这里部分代码省略.........
开发者ID:jscorrea,项目名称:MediaBrowser,代码行数:101,代码来源:MovieDbProvider.cs

示例2: FetchMovieData

        /// <summary>
        /// Fetches the movie data.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="id">The id.</param>
        /// <param name="isForcedRefresh">if set to <c>true</c> [is forced refresh].</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Task.</returns>
        private async Task FetchMovieData(BaseItem item, string id, bool isForcedRefresh, CancellationToken cancellationToken)
        {
            // Id could be ImdbId or TmdbId

            var language = item.GetPreferredMetadataLanguage();
            var country = item.GetPreferredMetadataCountryCode();

            var dataFilePath = GetDataFilePath(item);

            var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);

            var isBoxSet = item is BoxSet;

            if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath))
            {
                var mainResult = await FetchMainResult(id, isBoxSet, language, cancellationToken).ConfigureAwait(false);

                if (mainResult == null) return;

                tmdbId = mainResult.id.ToString(_usCulture);

                dataFilePath = GetDataFilePath(isBoxSet, tmdbId, language);

                var directory = Path.GetDirectoryName(dataFilePath);

                Directory.CreateDirectory(directory);

                JsonSerializer.SerializeToFile(mainResult, dataFilePath);
            }

            if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(item))
            {
                dataFilePath = GetDataFilePath(isBoxSet, tmdbId, language);

                if (!string.IsNullOrEmpty(dataFilePath))
                {
                    var mainResult = JsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath);

                    ProcessMainInfo(item, mainResult);
                }
            }
        }
开发者ID:jscorrea,项目名称:MediaBrowser,代码行数:50,代码来源:MovieDbProvider.cs


注:本文中的BaseItem.GetPreferredMetadataCountryCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。