本文整理汇总了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;
//.........这里部分代码省略.........
示例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);
}
}
}