Merge pull request #3089 from MrTimscampi/tmdb-original-title

Add more information to TmdbSeriesProvider
This commit is contained in:
dkanada 2020-05-14 13:43:00 +09:00 committed by GitHub
commit 11dd96f6c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 22 deletions

View File

@ -27,9 +27,6 @@ namespace MediaBrowser.Providers.Tmdb.TV
public class TmdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder public class TmdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
{ {
private const string GetTvInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}?api_key={1}&append_to_response=credits,images,keywords,external_ids,videos,content_ratings"; private const string GetTvInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}?api_key={1}&append_to_response=credits,images,keywords,external_ids,videos,content_ratings";
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
internal static TmdbSeriesProvider Current { get; private set; }
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
@ -39,6 +36,10 @@ namespace MediaBrowser.Providers.Tmdb.TV
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
internal static TmdbSeriesProvider Current { get; private set; }
public TmdbSeriesProvider( public TmdbSeriesProvider(
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IFileSystem fileSystem, IFileSystem fileSystem,
@ -217,10 +218,9 @@ namespace MediaBrowser.Providers.Tmdb.TV
var series = seriesResult.Item; var series = seriesResult.Item;
series.Name = seriesInfo.Name; series.Name = seriesInfo.Name;
series.OriginalTitle = seriesInfo.Original_Name;
series.SetProviderId(MetadataProviders.Tmdb, seriesInfo.Id.ToString(_usCulture)); series.SetProviderId(MetadataProviders.Tmdb, seriesInfo.Id.ToString(_usCulture));
//series.VoteCount = seriesInfo.vote_count;
string voteAvg = seriesInfo.Vote_Average.ToString(CultureInfo.InvariantCulture); string voteAvg = seriesInfo.Vote_Average.ToString(CultureInfo.InvariantCulture);
if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out float rating)) if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out float rating))
@ -240,7 +240,7 @@ namespace MediaBrowser.Providers.Tmdb.TV
series.Genres = seriesInfo.Genres.Select(i => i.Name).ToArray(); series.Genres = seriesInfo.Genres.Select(i => i.Name).ToArray();
} }
//series.HomePageUrl = seriesInfo.homepage; series.HomePageUrl = seriesInfo.Homepage;
series.RunTimeTicks = seriesInfo.Episode_Run_Time.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault(); series.RunTimeTicks = seriesInfo.Episode_Run_Time.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault();
@ -308,29 +308,61 @@ namespace MediaBrowser.Providers.Tmdb.TV
seriesResult.ResetPeople(); seriesResult.ResetPeople();
var tmdbImageUrl = settings.images.GetImageUrl("original"); var tmdbImageUrl = settings.images.GetImageUrl("original");
if (seriesInfo.Credits != null && seriesInfo.Credits.Cast != null) if (seriesInfo.Credits != null)
{ {
foreach (var actor in seriesInfo.Credits.Cast.OrderBy(a => a.Order)) if (seriesInfo.Credits.Cast != null)
{ {
var personInfo = new PersonInfo foreach (var actor in seriesInfo.Credits.Cast.OrderBy(a => a.Order))
{ {
Name = actor.Name.Trim(), var personInfo = new PersonInfo
Role = actor.Character, {
Type = PersonType.Actor, Name = actor.Name.Trim(),
SortOrder = actor.Order Role = actor.Character,
Type = PersonType.Actor,
SortOrder = actor.Order
};
if (!string.IsNullOrWhiteSpace(actor.Profile_Path))
{
personInfo.ImageUrl = tmdbImageUrl + actor.Profile_Path;
}
if (actor.Id > 0)
{
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture));
}
seriesResult.AddPerson(personInfo);
}
}
if (seriesInfo.Credits.Crew != null)
{
var keepTypes = new[]
{
PersonType.Director,
PersonType.Writer,
PersonType.Producer
}; };
if (!string.IsNullOrWhiteSpace(actor.Profile_Path)) foreach (var person in seriesInfo.Credits.Crew)
{ {
personInfo.ImageUrl = tmdbImageUrl + actor.Profile_Path; // Normalize this
} var type = TmdbUtils.MapCrewToPersonType(person);
if (actor.Id > 0) if (!keepTypes.Contains(type, StringComparer.OrdinalIgnoreCase)
{ && !keepTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture)); {
} continue;
}
seriesResult.AddPerson(personInfo); seriesResult.AddPerson(new PersonInfo
{
Name = person.Name.Trim(),
Role = person.Job,
Type = type
});
}
} }
} }
} }

View File

@ -4,18 +4,51 @@ using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb namespace MediaBrowser.Providers.Tmdb
{ {
/// <summary>
/// Utilities for the TMDb provider
/// </summary>
public static class TmdbUtils public static class TmdbUtils
{ {
/// <summary>
/// URL of the TMDB instance to use.
/// </summary>
public const string BaseTmdbUrl = "https://www.themoviedb.org/"; public const string BaseTmdbUrl = "https://www.themoviedb.org/";
/// <summary>
/// URL of the TMDB API instance to use.
/// </summary>
public const string BaseTmdbApiUrl = "https://api.themoviedb.org/"; public const string BaseTmdbApiUrl = "https://api.themoviedb.org/";
/// <summary>
/// Name of the provider.
/// </summary>
public const string ProviderName = "TheMovieDb"; public const string ProviderName = "TheMovieDb";
/// <summary>
/// API key to use when performing an API call.
/// </summary>
public const string ApiKey = "4219e299c89411838049ab0dab19ebd5"; public const string ApiKey = "4219e299c89411838049ab0dab19ebd5";
/// <summary>
/// Value of the Accept header for requests to the provider.
/// </summary>
public const string AcceptHeader = "application/json,image/*"; public const string AcceptHeader = "application/json,image/*";
/// <summary>
/// Maps the TMDB provided roles for crew members to Jellyfin roles.
/// </summary>
/// <param name="crew">Crew member to map against the Jellyfin person types.</param>
/// <returns>The Jellyfin person type.</returns>
public static string MapCrewToPersonType(Crew crew) public static string MapCrewToPersonType(Crew crew)
{ {
if (crew.Department.Equals("production", StringComparison.InvariantCultureIgnoreCase) if (crew.Department.Equals("production", StringComparison.InvariantCultureIgnoreCase)
&& crew.Job.IndexOf("producer", StringComparison.InvariantCultureIgnoreCase) != -1) && crew.Job.Contains("director", StringComparison.InvariantCultureIgnoreCase))
{
return PersonType.Director;
}
if (crew.Department.Equals("production", StringComparison.InvariantCultureIgnoreCase)
&& crew.Job.Contains("producer", StringComparison.InvariantCultureIgnoreCase))
{ {
return PersonType.Producer; return PersonType.Producer;
} }