2020-09-24 10:49:35 -07:00
|
|
|
#nullable enable
|
|
|
|
|
2019-08-18 04:20:52 -07:00
|
|
|
using System;
|
2020-09-24 10:49:35 -07:00
|
|
|
using System.Collections.Generic;
|
2020-08-17 12:59:29 -07:00
|
|
|
using System.Net.Mime;
|
2019-08-18 04:20:52 -07:00
|
|
|
using MediaBrowser.Model.Entities;
|
2020-09-24 10:49:35 -07:00
|
|
|
using TMDbLib.Objects.General;
|
2019-08-18 04:20:52 -07:00
|
|
|
|
2020-05-30 23:23:09 -07:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb
|
2019-08-18 04:20:52 -07:00
|
|
|
{
|
2020-05-12 06:05:58 -07:00
|
|
|
/// <summary>
|
2020-05-30 23:28:01 -07:00
|
|
|
/// Utilities for the TMDb provider.
|
2020-05-12 06:05:58 -07:00
|
|
|
/// </summary>
|
2019-08-18 04:20:52 -07:00
|
|
|
public static class TmdbUtils
|
|
|
|
{
|
2020-05-12 06:05:58 -07:00
|
|
|
/// <summary>
|
|
|
|
/// URL of the TMDB instance to use.
|
|
|
|
/// </summary>
|
2019-08-18 04:34:44 -07:00
|
|
|
public const string BaseTmdbUrl = "https://www.themoviedb.org/";
|
2020-05-12 06:05:58 -07:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// URL of the TMDB API instance to use.
|
|
|
|
/// </summary>
|
2019-08-18 04:34:44 -07:00
|
|
|
public const string BaseTmdbApiUrl = "https://api.themoviedb.org/";
|
2020-05-12 06:05:58 -07:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Name of the provider.
|
|
|
|
/// </summary>
|
2019-08-18 04:20:52 -07:00
|
|
|
public const string ProviderName = "TheMovieDb";
|
2020-05-12 06:05:58 -07:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// API key to use when performing an API call.
|
|
|
|
/// </summary>
|
2019-08-18 04:20:52 -07:00
|
|
|
public const string ApiKey = "4219e299c89411838049ab0dab19ebd5";
|
2020-05-12 06:05:58 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Maximum number of cast members to pull.
|
|
|
|
/// </summary>
|
|
|
|
public const int MaxCastMembers = 15;
|
|
|
|
|
2020-05-12 06:05:58 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Value of the Accept header for requests to the provider.
|
|
|
|
/// </summary>
|
2020-08-17 12:59:29 -07:00
|
|
|
public static readonly string[] AcceptHeaders = { MediaTypeNames.Application.Json, "image/*" };
|
2019-08-18 04:20:52 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
/// <summary>
|
|
|
|
/// The crew types to keep.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly string[] WantedCrewTypes =
|
|
|
|
{
|
|
|
|
PersonType.Director,
|
|
|
|
PersonType.Writer,
|
|
|
|
PersonType.Producer
|
|
|
|
};
|
|
|
|
|
2020-05-12 06:05:58 -07:00
|
|
|
/// <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>
|
2019-08-18 04:20:52 -07:00
|
|
|
public static string MapCrewToPersonType(Crew crew)
|
|
|
|
{
|
2020-05-10 06:16:19 -07:00
|
|
|
if (crew.Department.Equals("production", StringComparison.InvariantCultureIgnoreCase)
|
2020-05-12 06:05:58 -07:00
|
|
|
&& crew.Job.Contains("director", StringComparison.InvariantCultureIgnoreCase))
|
2020-05-10 06:16:19 -07:00
|
|
|
{
|
|
|
|
return PersonType.Director;
|
|
|
|
}
|
|
|
|
|
2019-08-18 05:44:13 -07:00
|
|
|
if (crew.Department.Equals("production", StringComparison.InvariantCultureIgnoreCase)
|
2020-05-12 06:05:58 -07:00
|
|
|
&& crew.Job.Contains("producer", StringComparison.InvariantCultureIgnoreCase))
|
2019-08-18 04:20:52 -07:00
|
|
|
{
|
|
|
|
return PersonType.Producer;
|
|
|
|
}
|
|
|
|
|
2019-08-18 05:44:13 -07:00
|
|
|
if (crew.Department.Equals("writing", StringComparison.InvariantCultureIgnoreCase))
|
2019-08-18 04:20:52 -07:00
|
|
|
{
|
|
|
|
return PersonType.Writer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2020-09-24 10:49:35 -07:00
|
|
|
|
|
|
|
public static bool IsTrailerType(Video video)
|
|
|
|
{
|
|
|
|
return video.Site.Equals("youtube", StringComparison.OrdinalIgnoreCase)
|
|
|
|
&& (!video.Type.Equals("trailer", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|| !video.Type.Equals("teaser", StringComparison.OrdinalIgnoreCase));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetImageLanguagesParam(string preferredLanguage)
|
|
|
|
{
|
|
|
|
var languages = new List<string>();
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(preferredLanguage))
|
|
|
|
{
|
|
|
|
preferredLanguage = NormalizeLanguage(preferredLanguage);
|
|
|
|
|
|
|
|
languages.Add(preferredLanguage);
|
|
|
|
|
|
|
|
if (preferredLanguage.Length == 5) // like en-US
|
|
|
|
{
|
|
|
|
// Currenty, TMDB supports 2-letter language codes only
|
|
|
|
// They are planning to change this in the future, thus we're
|
|
|
|
// supplying both codes if we're having a 5-letter code.
|
|
|
|
languages.Add(preferredLanguage.Substring(0, 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
languages.Add("null");
|
|
|
|
|
|
|
|
if (!string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
languages.Add("en");
|
|
|
|
}
|
|
|
|
|
|
|
|
return string.Join(',', languages);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string NormalizeLanguage(string language)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(language))
|
|
|
|
{
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
|
|
|
// They require this to be uppercase
|
|
|
|
// Everything after the hyphen must be written in uppercase due to a way TMDB wrote their api.
|
|
|
|
// See here: https://www.themoviedb.org/talk/5119221d760ee36c642af4ad?page=3#56e372a0c3a3685a9e0019ab
|
|
|
|
var parts = language.Split('-');
|
|
|
|
|
|
|
|
if (parts.Length == 2)
|
|
|
|
{
|
|
|
|
language = parts[0] + "-" + parts[1].ToUpperInvariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string AdjustImageLanguage(string imageLanguage, string requestLanguage)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(imageLanguage)
|
|
|
|
&& !string.IsNullOrEmpty(requestLanguage)
|
|
|
|
&& requestLanguage.Length > 2
|
|
|
|
&& imageLanguage.Length == 2
|
|
|
|
&& requestLanguage.StartsWith(imageLanguage, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return requestLanguage;
|
|
|
|
}
|
|
|
|
|
|
|
|
return imageLanguage;
|
|
|
|
}
|
2019-08-18 04:20:52 -07:00
|
|
|
}
|
|
|
|
}
|