From 333f1ea6a4744b304a5c0991b4d4c3796c97ac16 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 14 Sep 2013 17:58:51 -0400 Subject: [PATCH] fixes #540 - Get tv genres from Imdb via Omdb --- .../Movies/OpenMovieDatabaseProvider.cs | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs b/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs index b41b74ee7..3e01ad5be 100644 --- a/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs +++ b/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Net; +using System.Linq; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; @@ -45,7 +46,7 @@ namespace MediaBrowser.Providers.Movies { get { - return "6"; + return "8"; } } @@ -105,7 +106,7 @@ namespace MediaBrowser.Providers.Movies } protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); - + public override async Task FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) { BaseProviderInfo data; @@ -173,14 +174,37 @@ namespace MediaBrowser.Providers.Movies { item.CommunityRating = imdbRating; } + + ParseAdditionalMetadata(item, result); } - + data.LastRefreshStatus = ProviderRefreshStatus.Success; SetLastRefreshed(item, DateTime.UtcNow); return true; } + private void ParseAdditionalMetadata(BaseItem item, RootObject result) + { + // Grab series genres because imdb data is better than tvdb. Leave movies alone + // But only do it if english is the preferred language because this data will not be localized + if (!item.LockedFields.Contains(MetadataFields.Genres) && + item is Series && + !string.IsNullOrWhiteSpace(result.Genre) && + !string.Equals(result.Genre, "n/a", StringComparison.OrdinalIgnoreCase) + && string.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, "en")) + { + item.Genres.Clear(); + + foreach (var genre in result.Genre + .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) + .Select(i => i.Trim()) + .Where(i => !string.IsNullOrWhiteSpace(i))) + { + item.AddGenre(genre); + } + } + } protected class RootObject {