Merge pull request #1641 from cvium/tmdb_cleanup

Tmdb cleanup and re-add Writer and Producer
This commit is contained in:
Anthony Lavado 2019-08-27 23:29:01 -04:00 committed by GitHub
commit 874f02631b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
72 changed files with 1344 additions and 1415 deletions

View File

@ -24,4 +24,9 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<!-- We need at least C# 7.1 -->
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>

View File

@ -7,85 +7,6 @@ using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Movies
{
public class MovieDbMovieExternalId : IExternalId
{
public const string BaseMovieDbUrl = "https://www.themoviedb.org/";
public string Name => "TheMovieDb";
public string Key => MetadataProviders.Tmdb.ToString();
public string UrlFormatString => BaseMovieDbUrl + "movie/{0}";
public bool Supports(IHasProviderIds item)
{
// Supports images for tv movies
var tvProgram = item as LiveTvProgram;
if (tvProgram != null && tvProgram.IsMovie)
{
return true;
}
return item is Movie || item is MusicVideo || item is Trailer;
}
}
public class MovieDbSeriesExternalId : IExternalId
{
public string Name => "TheMovieDb";
public string Key => MetadataProviders.Tmdb.ToString();
public string UrlFormatString => MovieDbMovieExternalId.BaseMovieDbUrl + "tv/{0}";
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
}
public class MovieDbMovieCollectionExternalId : IExternalId
{
public string Name => "TheMovieDb Collection";
public string Key => MetadataProviders.TmdbCollection.ToString();
public string UrlFormatString => MovieDbMovieExternalId.BaseMovieDbUrl + "collection/{0}";
public bool Supports(IHasProviderIds item)
{
return item is Movie || item is MusicVideo || item is Trailer;
}
}
public class MovieDbPersonExternalId : IExternalId
{
public string Name => "TheMovieDb";
public string Key => MetadataProviders.Tmdb.ToString();
public string UrlFormatString => MovieDbMovieExternalId.BaseMovieDbUrl + "person/{0}";
public bool Supports(IHasProviderIds item)
{
return item is Person;
}
}
public class MovieDbCollectionExternalId : IExternalId
{
public string Name => "TheMovieDb";
public string Key => MetadataProviders.Tmdb.ToString();
public string UrlFormatString => MovieDbMovieExternalId.BaseMovieDbUrl + "collection/{0}";
public bool Supports(IHasProviderIds item)
{
return item is BoxSet;
}
}
public class ImdbExternalId : IExternalId
{
public string Name => "IMDb";

View File

@ -0,0 +1,25 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Tmdb.BoxSets
{
public class TmdbBoxSetExternalId : IExternalId
{
/// <inheritdoc />
public string Name => TmdbUtils.ProviderName;
/// <inheritdoc />
public string Key => MetadataProviders.TmdbCollection.ToString();
/// <inheritdoc />
public string UrlFormatString => TmdbUtils.BaseTmdbUrl + "collection/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Movie || item is MusicVideo || item is Trailer;
}
}
}

View File

@ -11,21 +11,24 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.Collections;
using MediaBrowser.Providers.Tmdb.Models.General;
using MediaBrowser.Providers.Tmdb.Movies;
namespace MediaBrowser.Providers.BoxSets
namespace MediaBrowser.Providers.Tmdb.BoxSets
{
public class MovieDbBoxSetImageProvider : IRemoteImageProvider, IHasOrder
public class TmdbBoxSetImageProvider : IRemoteImageProvider, IHasOrder
{
private readonly IHttpClient _httpClient;
public MovieDbBoxSetImageProvider(IHttpClient httpClient)
public TmdbBoxSetImageProvider(IHttpClient httpClient)
{
_httpClient = httpClient;
}
public string Name => ProviderName;
public static string ProviderName => "TheMovieDb";
public static string ProviderName => TmdbUtils.ProviderName;
public bool Supports(BaseItem item)
{
@ -49,11 +52,11 @@ namespace MediaBrowser.Providers.BoxSets
{
var language = item.GetPreferredMetadataLanguage();
var mainResult = await MovieDbBoxSetProvider.Current.GetMovieDbResult(tmdbId, null, cancellationToken).ConfigureAwait(false);
var mainResult = await TmdbBoxSetProvider.Current.GetMovieDbResult(tmdbId, null, cancellationToken).ConfigureAwait(false);
if (mainResult != null)
{
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
@ -64,20 +67,20 @@ namespace MediaBrowser.Providers.BoxSets
return new List<RemoteImageInfo>();
}
private IEnumerable<RemoteImageInfo> GetImages(MovieDbBoxSetProvider.RootObject obj, string language, string baseUrl)
private IEnumerable<RemoteImageInfo> GetImages(CollectionResult obj, string language, string baseUrl)
{
var list = new List<RemoteImageInfo>();
var images = obj.images ?? new MovieDbBoxSetProvider.Images();
var images = obj.Images ?? new CollectionImages();
list.AddRange(GetPosters(images).Select(i => new RemoteImageInfo
{
Url = baseUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
Url = baseUrl + i.File_Path,
CommunityRating = i.Vote_Average,
VoteCount = i.Vote_Count,
Width = i.Width,
Height = i.Height,
Language = TmdbMovieProvider.AdjustImageLanguage(i.Iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score
@ -85,11 +88,11 @@ namespace MediaBrowser.Providers.BoxSets
list.AddRange(GetBackdrops(images).Select(i => new RemoteImageInfo
{
Url = baseUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Url = baseUrl + i.File_Path,
CommunityRating = i.Vote_Average,
VoteCount = i.Vote_Count,
Width = i.Width,
Height = i.Height,
ProviderName = Name,
Type = ImageType.Backdrop,
RatingType = RatingType.Score
@ -125,9 +128,9 @@ namespace MediaBrowser.Providers.BoxSets
/// </summary>
/// <param name="images">The images.</param>
/// <returns>IEnumerable{MovieDbProvider.Poster}.</returns>
private IEnumerable<MovieDbBoxSetProvider.Poster> GetPosters(MovieDbBoxSetProvider.Images images)
private IEnumerable<Poster> GetPosters(CollectionImages images)
{
return images.posters ?? new List<MovieDbBoxSetProvider.Poster>();
return images.Posters ?? new List<Poster>();
}
/// <summary>
@ -135,13 +138,13 @@ namespace MediaBrowser.Providers.BoxSets
/// </summary>
/// <param name="images">The images.</param>
/// <returns>IEnumerable{MovieDbProvider.Backdrop}.</returns>
private IEnumerable<MovieDbBoxSetProvider.Backdrop> GetBackdrops(MovieDbBoxSetProvider.Images images)
private IEnumerable<Backdrop> GetBackdrops(CollectionImages images)
{
var eligibleBackdrops = images.backdrops == null ? new List<MovieDbBoxSetProvider.Backdrop>() :
images.backdrops;
var eligibleBackdrops = images.Backdrops == null ? new List<Backdrop>() :
images.Backdrops;
return eligibleBackdrops.OrderByDescending(i => i.vote_average)
.ThenByDescending(i => i.vote_count);
return eligibleBackdrops.OrderByDescending(i => i.Vote_Average)
.ThenByDescending(i => i.Vote_Count);
}
public int Order => 0;

View File

@ -16,16 +16,18 @@ using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.Collections;
using MediaBrowser.Providers.Tmdb.Models.General;
using MediaBrowser.Providers.Tmdb.Movies;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.BoxSets
namespace MediaBrowser.Providers.Tmdb.BoxSets
{
public class MovieDbBoxSetProvider : IRemoteMetadataProvider<BoxSet, BoxSetInfo>
public class TmdbBoxSetProvider : IRemoteMetadataProvider<BoxSet, BoxSetInfo>
{
private const string GetCollectionInfo3 = MovieDbProvider.BaseMovieDbUrl + @"3/collection/{0}?api_key={1}&append_to_response=images";
private const string GetCollectionInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/collection/{0}?api_key={1}&append_to_response=images";
internal static MovieDbBoxSetProvider Current;
internal static TmdbBoxSetProvider Current;
private readonly ILogger _logger;
private readonly IJsonSerializer _json;
@ -35,7 +37,7 @@ namespace MediaBrowser.Providers.BoxSets
private readonly IHttpClient _httpClient;
private readonly ILibraryManager _libraryManager;
public MovieDbBoxSetProvider(ILogger logger, IJsonSerializer json, IServerConfigurationManager config, IFileSystem fileSystem, ILocalizationManager localization, IHttpClient httpClient, ILibraryManager libraryManager)
public TmdbBoxSetProvider(ILogger logger, IJsonSerializer json, IServerConfigurationManager config, IFileSystem fileSystem, ILocalizationManager localization, IHttpClient httpClient, ILibraryManager libraryManager)
{
_logger = logger;
_json = json;
@ -58,29 +60,29 @@ namespace MediaBrowser.Providers.BoxSets
await EnsureInfo(tmdbId, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
var dataFilePath = GetDataFilePath(_config.ApplicationPaths, tmdbId, searchInfo.MetadataLanguage);
var info = _json.DeserializeFromFile<RootObject>(dataFilePath);
var info = _json.DeserializeFromFile<CollectionResult>(dataFilePath);
var images = (info.images ?? new Images()).posters ?? new List<Poster>();
var images = (info.Images ?? new CollectionImages()).Posters ?? new List<Poster>();
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
var result = new RemoteSearchResult
{
Name = info.name,
Name = info.Name,
SearchProviderName = Name,
ImageUrl = images.Count == 0 ? null : (tmdbImageUrl + images[0].file_path)
ImageUrl = images.Count == 0 ? null : (tmdbImageUrl + images[0].File_Path)
};
result.SetProviderId(MetadataProviders.Tmdb, info.id.ToString(_usCulture));
result.SetProviderId(MetadataProviders.Tmdb, info.Id.ToString(_usCulture));
return new[] { result };
}
return await new MovieDbSearch(_logger, _json, _libraryManager).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
return await new TmdbSearch(_logger, _json, _libraryManager).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
}
public async Task<MetadataResult<BoxSet>> GetMetadata(BoxSetInfo id, CancellationToken cancellationToken)
@ -90,7 +92,7 @@ namespace MediaBrowser.Providers.BoxSets
// We don't already have an Id, need to fetch it
if (string.IsNullOrEmpty(tmdbId))
{
var searchResults = await new MovieDbSearch(_logger, _json, _libraryManager).GetSearchResults(id, cancellationToken).ConfigureAwait(false);
var searchResults = await new TmdbSearch(_logger, _json, _libraryManager).GetSearchResults(id, cancellationToken).ConfigureAwait(false);
var searchResult = searchResults.FirstOrDefault();
@ -116,7 +118,7 @@ namespace MediaBrowser.Providers.BoxSets
return result;
}
internal async Task<RootObject> GetMovieDbResult(string tmdbId, string language, CancellationToken cancellationToken)
internal async Task<CollectionResult> GetMovieDbResult(string tmdbId, string language, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(tmdbId))
{
@ -129,21 +131,21 @@ namespace MediaBrowser.Providers.BoxSets
if (!string.IsNullOrEmpty(dataFilePath))
{
return _json.DeserializeFromFile<RootObject>(dataFilePath);
return _json.DeserializeFromFile<CollectionResult>(dataFilePath);
}
return null;
}
private BoxSet GetItem(RootObject obj)
private BoxSet GetItem(CollectionResult obj)
{
var item = new BoxSet
{
Name = obj.name,
Overview = obj.overview
Name = obj.Name,
Overview = obj.Overview
};
item.SetProviderId(MetadataProviders.Tmdb, obj.id.ToString(_usCulture));
item.SetProviderId(MetadataProviders.Tmdb, obj.Id.ToString(_usCulture));
return item;
}
@ -161,61 +163,61 @@ namespace MediaBrowser.Providers.BoxSets
_json.SerializeToFile(mainResult, dataFilePath);
}
private async Task<RootObject> FetchMainResult(string id, string language, CancellationToken cancellationToken)
private async Task<CollectionResult> FetchMainResult(string id, string language, CancellationToken cancellationToken)
{
var url = string.Format(GetCollectionInfo3, id, MovieDbProvider.ApiKey);
var url = string.Format(GetCollectionInfo3, id, TmdbUtils.ApiKey);
if (!string.IsNullOrEmpty(language))
{
url += string.Format("&language={0}", MovieDbProvider.NormalizeLanguage(language));
url += string.Format("&language={0}", TmdbMovieProvider.NormalizeLanguage(language));
// Get images in english and with no language
url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language);
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
}
cancellationToken.ThrowIfCancellationRequested();
RootObject mainResult = null;
CollectionResult mainResult;
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbSearch.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
mainResult = await _json.DeserializeFromStreamAsync<RootObject>(json).ConfigureAwait(false);
mainResult = await _json.DeserializeFromStreamAsync<CollectionResult>(json).ConfigureAwait(false);
}
}
cancellationToken.ThrowIfCancellationRequested();
if (mainResult != null && string.IsNullOrEmpty(mainResult.name))
if (mainResult != null && string.IsNullOrEmpty(mainResult.Name))
{
if (!string.IsNullOrEmpty(language) && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
{
url = string.Format(GetCollectionInfo3, id, MovieDbSearch.ApiKey) + "&language=en";
url = string.Format(GetCollectionInfo3, id, TmdbUtils.ApiKey) + "&language=en";
if (!string.IsNullOrEmpty(language))
{
// Get images in english and with no language
url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language);
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
}
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbSearch.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
mainResult = await _json.DeserializeFromStreamAsync<RootObject>(json).ConfigureAwait(false);
mainResult = await _json.DeserializeFromStreamAsync<CollectionResult>(json).ConfigureAwait(false);
}
}
}
@ -241,7 +243,7 @@ namespace MediaBrowser.Providers.BoxSets
return DownloadInfo(tmdbId, preferredMetadataLanguage, cancellationToken);
}
public string Name => "TheMovieDb";
public string Name => TmdbUtils.ProviderName;
private static string GetDataFilePath(IApplicationPaths appPaths, string tmdbId, string preferredLanguage)
{
@ -266,54 +268,6 @@ namespace MediaBrowser.Providers.BoxSets
return dataPath;
}
internal class Part
{
public string title { get; set; }
public int id { get; set; }
public string release_date { get; set; }
public string poster_path { get; set; }
public string backdrop_path { get; set; }
}
internal class Backdrop
{
public double aspect_ratio { get; set; }
public string file_path { get; set; }
public int height { get; set; }
public string iso_639_1 { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public int width { get; set; }
}
internal class Poster
{
public double aspect_ratio { get; set; }
public string file_path { get; set; }
public int height { get; set; }
public string iso_639_1 { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public int width { get; set; }
}
internal class Images
{
public List<Backdrop> backdrops { get; set; }
public List<Poster> posters { get; set; }
}
internal class RootObject
{
public int id { get; set; }
public string name { get; set; }
public string overview { get; set; }
public string poster_path { get; set; }
public string backdrop_path { get; set; }
public List<Part> parts { get; set; }
public Images images { get; set; }
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.Collections
{
public class CollectionImages
{
public List<Backdrop> Backdrops { get; set; }
public List<Poster> Posters { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.Collections
{
public class CollectionResult
{
public int Id { get; set; }
public string Name { get; set; }
public string Overview { get; set; }
public string Poster_Path { get; set; }
public string Backdrop_Path { get; set; }
public List<Part> Parts { get; set; }
public CollectionImages Images { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace MediaBrowser.Providers.Tmdb.Models.Collections
{
public class Part
{
public string Title { get; set; }
public int Id { get; set; }
public string Release_Date { get; set; }
public string Poster_Path { get; set; }
public string Backdrop_Path { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Backdrop
{
public double Aspect_Ratio { get; set; }
public string File_Path { get; set; }
public int Height { get; set; }
public string Iso_639_1 { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
public int Width { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Crew
{
public int Id { get; set; }
public string Credit_Id { get; set; }
public string Name { get; set; }
public string Department { get; set; }
public string Job { get; set; }
public string Profile_Path { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class ExternalIds
{
public string Imdb_Id { get; set; }
public object Freebase_Id { get; set; }
public string Freebase_Mid { get; set; }
public int Tvdb_Id { get; set; }
public int Tvrage_Id { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Genre
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Images
{
public List<Backdrop> Backdrops { get; set; }
public List<Poster> Posters { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Keyword
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Keywords
{
public List<Keyword> Results { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Poster
{
public double Aspect_Ratio { get; set; }
public string File_Path { get; set; }
public int Height { get; set; }
public string Iso_639_1 { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
public int Width { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Profile
{
public string File_Path { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public object Iso_639_1 { get; set; }
public double Aspect_Ratio { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Still
{
public double Aspect_Ratio { get; set; }
public string File_Path { get; set; }
public int Height { get; set; }
public string Id { get; set; }
public string Iso_639_1 { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
public int Width { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class StillImages
{
public List<Still> Stills { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Video
{
public string Id { get; set; }
public string Iso_639_1 { get; set; }
public string Iso_3166_1 { get; set; }
public string Key { get; set; }
public string Name { get; set; }
public string Site { get; set; }
public string Size { get; set; }
public string Type { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.General
{
public class Videos
{
public List<Video> Results { get; set; }
}
}

View File

@ -0,0 +1,10 @@
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class BelongsToCollection
{
public int Id { get; set; }
public string Name { get; set; }
public string Poster_Path { get; set; }
public string Backdrop_Path { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class Cast
{
public int Id { get; set; }
public string Name { get; set; }
public string Character { get; set; }
public int Order { get; set; }
public int Cast_Id { get; set; }
public string Profile_Path { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class Casts
{
public List<Cast> Cast { get; set; }
public List<Crew> Crew { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class Country
{
public string Iso_3166_1 { get; set; }
public string Certification { get; set; }
public DateTime Release_Date { get; set; }
}
}

View File

@ -0,0 +1,49 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class MovieResult
{
public bool Adult { get; set; }
public string Backdrop_Path { get; set; }
public BelongsToCollection Belongs_To_Collection { get; set; }
public int Budget { get; set; }
public List<Genre> Genres { get; set; }
public string Homepage { get; set; }
public int Id { get; set; }
public string Imdb_Id { get; set; }
public string Original_Title { get; set; }
public string Original_Name { get; set; }
public string Overview { get; set; }
public double Popularity { get; set; }
public string Poster_Path { get; set; }
public List<ProductionCompany> Production_Companies { get; set; }
public List<ProductionCountry> Production_Countries { get; set; }
public string Release_Date { get; set; }
public int Revenue { get; set; }
public int Runtime { get; set; }
public List<SpokenLanguage> Spoken_Languages { get; set; }
public string Status { get; set; }
public string Tagline { get; set; }
public string Title { get; set; }
public string Name { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
public Casts Casts { get; set; }
public Releases Releases { get; set; }
public Images Images { get; set; }
public Keywords Keywords { get; set; }
public Trailers Trailers { get; set; }
public string GetOriginalTitle()
{
return Original_Name ?? Original_Title;
}
public string GetTitle()
{
return Name ?? Title ?? GetOriginalTitle();
}
}
}

View File

@ -0,0 +1,8 @@
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class ProductionCompany
{
public string Name { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class ProductionCountry
{
public string Iso_3166_1 { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class Releases
{
public List<Country> Countries { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class SpokenLanguage
{
public string Iso_639_1 { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class Trailers
{
public List<Youtube> Youtube { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace MediaBrowser.Providers.Tmdb.Models.Movies
{
public class Youtube
{
public string Name { get; set; }
public string Size { get; set; }
public string Source { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.People
{
public class PersonImages
{
public List<Profile> Profiles { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.People
{
public class PersonResult
{
public bool Adult { get; set; }
public List<string> Also_Known_As { get; set; }
public string Biography { get; set; }
public string Birthday { get; set; }
public string Deathday { get; set; }
public string Homepage { get; set; }
public int Id { get; set; }
public string Imdb_Id { get; set; }
public string Name { get; set; }
public string Place_Of_Birth { get; set; }
public double Popularity { get; set; }
public string Profile_Path { get; set; }
public PersonImages Images { get; set; }
public ExternalIds External_Ids { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Movies;
namespace MediaBrowser.Providers.Tmdb.Models.Search
{
public class ExternalIdLookupResult
{
public List<TvResult> Tv_Results { get; set; }
}
}

View File

@ -0,0 +1,65 @@
namespace MediaBrowser.Providers.Tmdb.Models.Search
{
public class MovieResult
{
/// <summary>
/// Gets or sets a value indicating whether this <see cref="TmdbMovieSearchResult" /> is adult.
/// </summary>
/// <value><c>true</c> if adult; otherwise, <c>false</c>.</value>
public bool Adult { get; set; }
/// <summary>
/// Gets or sets the backdrop_path.
/// </summary>
/// <value>The backdrop_path.</value>
public string Backdrop_Path { get; set; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public int Id { get; set; }
/// <summary>
/// Gets or sets the original_title.
/// </summary>
/// <value>The original_title.</value>
public string Original_Title { get; set; }
/// <summary>
/// Gets or sets the original_name.
/// </summary>
/// <value>The original_name.</value>
public string Original_Name { get; set; }
/// <summary>
/// Gets or sets the release_date.
/// </summary>
/// <value>The release_date.</value>
public string Release_Date { get; set; }
/// <summary>
/// Gets or sets the poster_path.
/// </summary>
/// <value>The poster_path.</value>
public string Poster_Path { get; set; }
/// <summary>
/// Gets or sets the popularity.
/// </summary>
/// <value>The popularity.</value>
public double Popularity { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public string Title { get; set; }
/// <summary>
/// Gets or sets the vote_average.
/// </summary>
/// <value>The vote_average.</value>
public double Vote_Average { get; set; }
/// <summary>
/// For collection search results
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the vote_count.
/// </summary>
/// <value>The vote_count.</value>
public int Vote_Count { get; set; }
}
}

View File

@ -0,0 +1,29 @@
namespace MediaBrowser.Providers.Tmdb.Models.Search
{
public class PersonSearchResult
{
/// <summary>
/// Gets or sets a value indicating whether this <see cref="PersonSearchResult" /> is adult.
/// </summary>
/// <value><c>true</c> if adult; otherwise, <c>false</c>.</value>
public bool Adult { get; set; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public int Id { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the profile_ path.
/// </summary>
/// <value>The profile_ path.</value>
public string Profile_Path { get; set; }
}
}

View File

@ -0,0 +1,31 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.Search
{
public class TmdbSearchResult<T>
{
/// <summary>
/// Gets or sets the page.
/// </summary>
/// <value>The page.</value>
public int Page { get; set; }
/// <summary>
/// Gets or sets the results.
/// </summary>
/// <value>The results.</value>
public List<T> Results { get; set; }
/// <summary>
/// Gets or sets the total_pages.
/// </summary>
/// <value>The total_pages.</value>
public int Total_Pages { get; set; }
/// <summary>
/// Gets or sets the total_results.
/// </summary>
/// <value>The total_results.</value>
public int Total_Results { get; set; }
}
}

View File

@ -0,0 +1,15 @@
namespace MediaBrowser.Providers.Tmdb.Models.Search
{
public class TvResult
{
public string Backdrop_Path { get; set; }
public string First_Air_Date { get; set; }
public int Id { get; set; }
public string Original_Name { get; set; }
public string Poster_Path { get; set; }
public double Popularity { get; set; }
public string Name { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class Cast
{
public string Character { get; set; }
public string Credit_Id { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Profile_Path { get; set; }
public int Order { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class ContentRating
{
public string Iso_3166_1 { get; set; }
public string Rating { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class ContentRatings
{
public List<ContentRating> Results { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class CreatedBy
{
public int Id { get; set; }
public string Name { get; set; }
public string Profile_Path { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class Credits
{
public List<Cast> Cast { get; set; }
public List<Crew> Crew { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class Episode
{
public string Air_Date { get; set; }
public int Episode_Number { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Overview { get; set; }
public string Still_Path { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class EpisodeCredits
{
public List<Cast> Cast { get; set; }
public List<Crew> Crew { get; set; }
public List<GuestStar> Guest_Stars { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using System;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class EpisodeResult
{
public DateTime Air_Date { get; set; }
public int Episode_Number { get; set; }
public string Name { get; set; }
public string Overview { get; set; }
public int Id { get; set; }
public object Production_Code { get; set; }
public int Season_Number { get; set; }
public string Still_Path { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
public StillImages Images { get; set; }
public ExternalIds External_Ids { get; set; }
public EpisodeCredits Credits { get; set; }
public Tmdb.Models.General.Videos Videos { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class GuestStar
{
public int Id { get; set; }
public string Name { get; set; }
public string Credit_Id { get; set; }
public string Character { get; set; }
public int Order { get; set; }
public string Profile_Path { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class Network
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class Season
{
public string Air_Date { get; set; }
public int Episode_Count { get; set; }
public int Id { get; set; }
public string Poster_Path { get; set; }
public int Season_Number { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class SeasonImages
{
public List<Poster> Posters { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class SeasonResult
{
public DateTime Air_Date { get; set; }
public List<Episode> Episodes { get; set; }
public string Name { get; set; }
public string Overview { get; set; }
public int Id { get; set; }
public string Poster_Path { get; set; }
public int Season_Number { get; set; }
public Credits Credits { get; set; }
public SeasonImages Images { get; set; }
public ExternalIds External_Ids { get; set; }
public General.Videos Videos { get; set; }
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb.Models.TV
{
public class SeriesResult
{
public string Backdrop_Path { get; set; }
public List<CreatedBy> Created_By { get; set; }
public List<int> Episode_Run_Time { get; set; }
public DateTime First_Air_Date { get; set; }
public List<Genre> Genres { get; set; }
public string Homepage { get; set; }
public int Id { get; set; }
public bool In_Production { get; set; }
public List<string> Languages { get; set; }
public DateTime Last_Air_Date { get; set; }
public string Name { get; set; }
public List<Network> Networks { get; set; }
public int Number_Of_Episodes { get; set; }
public int Number_Of_Seasons { get; set; }
public string Original_Name { get; set; }
public List<string> Origin_Country { get; set; }
public string Overview { get; set; }
public string Popularity { get; set; }
public string Poster_Path { get; set; }
public List<Season> Seasons { get; set; }
public string Status { get; set; }
public double Vote_Average { get; set; }
public int Vote_Count { get; set; }
public Credits Credits { get; set; }
public Images Images { get; set; }
public Keywords Keywords { get; set; }
public ExternalIds External_Ids { get; set; }
public General.Videos Videos { get; set; }
public ContentRatings Content_Ratings { get; set; }
public string ResultLanguage { get; set; }
}
}

View File

@ -14,11 +14,13 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.Movies;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Movies
namespace MediaBrowser.Providers.Tmdb.Movies
{
public class GenericMovieDbInfo<T>
public class GenericTmdbMovieInfo<T>
where T : BaseItem, new()
{
private readonly ILogger _logger;
@ -28,7 +30,7 @@ namespace MediaBrowser.Providers.Movies
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public GenericMovieDbInfo(ILogger logger, IJsonSerializer jsonSerializer, ILibraryManager libraryManager, IFileSystem fileSystem)
public GenericTmdbMovieInfo(ILogger logger, IJsonSerializer jsonSerializer, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_logger = logger;
_jsonSerializer = jsonSerializer;
@ -44,7 +46,7 @@ namespace MediaBrowser.Providers.Movies
// Don't search for music video id's because it is very easy to misidentify.
if (string.IsNullOrEmpty(tmdbId) && string.IsNullOrEmpty(imdbId) && typeof(T) != typeof(MusicVideo))
{
var searchResults = await new MovieDbSearch(_logger, _jsonSerializer, _libraryManager).GetMovieSearchResults(itemId, cancellationToken).ConfigureAwait(false);
var searchResults = await new TmdbSearch(_logger, _jsonSerializer, _libraryManager).GetMovieSearchResults(itemId, cancellationToken).ConfigureAwait(false);
var searchResult = searchResults.FirstOrDefault();
@ -81,17 +83,17 @@ namespace MediaBrowser.Providers.Movies
};
string dataFilePath = null;
MovieDbProvider.CompleteMovieData movieInfo = null;
MovieResult movieInfo = null;
// Id could be ImdbId or TmdbId
if (string.IsNullOrEmpty(tmdbId))
{
movieInfo = await MovieDbProvider.Current.FetchMainResult(imdbId, false, language, cancellationToken).ConfigureAwait(false);
movieInfo = await TmdbMovieProvider.Current.FetchMainResult(imdbId, false, language, cancellationToken).ConfigureAwait(false);
if (movieInfo != null)
{
tmdbId = movieInfo.id.ToString(_usCulture);
tmdbId = movieInfo.Id.ToString(_usCulture);
dataFilePath = MovieDbProvider.Current.GetDataFilePath(tmdbId, language);
dataFilePath = TmdbMovieProvider.Current.GetDataFilePath(tmdbId, language);
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
_jsonSerializer.SerializeToFile(movieInfo, dataFilePath);
}
@ -99,12 +101,12 @@ namespace MediaBrowser.Providers.Movies
if (!string.IsNullOrWhiteSpace(tmdbId))
{
await MovieDbProvider.Current.EnsureMovieInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
await TmdbMovieProvider.Current.EnsureMovieInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
dataFilePath = dataFilePath ?? MovieDbProvider.Current.GetDataFilePath(tmdbId, language);
movieInfo = movieInfo ?? _jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(dataFilePath);
dataFilePath = dataFilePath ?? TmdbMovieProvider.Current.GetDataFilePath(tmdbId, language);
movieInfo = movieInfo ?? _jsonSerializer.DeserializeFromFile<MovieResult>(dataFilePath);
var settings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var settings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
ProcessMainInfo(item, settings, preferredCountryCode, movieInfo);
item.HasMetadata = true;
@ -120,7 +122,7 @@ namespace MediaBrowser.Providers.Movies
/// <param name="settings">The settings.</param>
/// <param name="preferredCountryCode">The preferred country code.</param>
/// <param name="movieData">The movie data.</param>
private void ProcessMainInfo(MetadataResult<T> resultItem, TmdbSettingsResult settings, string preferredCountryCode, MovieDbProvider.CompleteMovieData movieData)
private void ProcessMainInfo(MetadataResult<T> resultItem, TmdbSettingsResult settings, string preferredCountryCode, MovieResult movieData)
{
var movie = resultItem.Item;
@ -128,41 +130,39 @@ namespace MediaBrowser.Providers.Movies
movie.OriginalTitle = movieData.GetOriginalTitle();
movie.Overview = string.IsNullOrWhiteSpace(movieData.overview) ? null : WebUtility.HtmlDecode(movieData.overview);
movie.Overview = string.IsNullOrWhiteSpace(movieData.Overview) ? null : WebUtility.HtmlDecode(movieData.Overview);
movie.Overview = movie.Overview != null ? movie.Overview.Replace("\n\n", "\n") : null;
//movie.HomePageUrl = movieData.homepage;
if (!string.IsNullOrEmpty(movieData.tagline))
if (!string.IsNullOrEmpty(movieData.Tagline))
{
movie.Tagline = movieData.tagline;
movie.Tagline = movieData.Tagline;
}
if (movieData.production_countries != null)
if (movieData.Production_Countries != null)
{
movie.ProductionLocations = movieData
.production_countries
.Select(i => i.name)
.Production_Countries
.Select(i => i.Name)
.ToArray();
}
movie.SetProviderId(MetadataProviders.Tmdb, movieData.id.ToString(_usCulture));
movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id);
movie.SetProviderId(MetadataProviders.Tmdb, movieData.Id.ToString(_usCulture));
movie.SetProviderId(MetadataProviders.Imdb, movieData.Imdb_Id);
if (movieData.belongs_to_collection != null)
if (movieData.Belongs_To_Collection != null)
{
movie.SetProviderId(MetadataProviders.TmdbCollection,
movieData.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture));
movieData.Belongs_To_Collection.Id.ToString(CultureInfo.InvariantCulture));
var movieItem = movie as Movie;
if (movieItem != null)
if (movie is Movie movieItem)
{
movieItem.CollectionName = movieData.belongs_to_collection.name;
movieItem.CollectionName = movieData.Belongs_To_Collection.Name;
}
}
string voteAvg = movieData.vote_average.ToString(CultureInfo.InvariantCulture);
string voteAvg = movieData.Vote_Average.ToString(CultureInfo.InvariantCulture);
if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var rating))
{
@ -171,17 +171,17 @@ namespace MediaBrowser.Providers.Movies
//movie.VoteCount = movieData.vote_count;
if (movieData.releases != null && movieData.releases.countries != null)
if (movieData.Releases != null && movieData.Releases.Countries != null)
{
var releases = movieData.releases.countries.Where(i => !string.IsNullOrWhiteSpace(i.certification)).ToList();
var releases = movieData.Releases.Countries.Where(i => !string.IsNullOrWhiteSpace(i.Certification)).ToList();
var ourRelease = releases.FirstOrDefault(c => string.Equals(c.iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
var usRelease = releases.FirstOrDefault(c => string.Equals(c.iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));
var ourRelease = releases.FirstOrDefault(c => string.Equals(c.Iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
var usRelease = releases.FirstOrDefault(c => string.Equals(c.Iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));
if (ourRelease != null)
{
var ratingPrefix = string.Equals(preferredCountryCode, "us", StringComparison.OrdinalIgnoreCase) ? "" : preferredCountryCode + "-";
var newRating = ratingPrefix + ourRelease.certification;
var newRating = ratingPrefix + ourRelease.Certification;
newRating = newRating.Replace("de-", "FSK-", StringComparison.OrdinalIgnoreCase);
@ -189,14 +189,14 @@ namespace MediaBrowser.Providers.Movies
}
else if (usRelease != null)
{
movie.OfficialRating = usRelease.certification;
movie.OfficialRating = usRelease.Certification;
}
}
if (!string.IsNullOrWhiteSpace(movieData.release_date))
if (!string.IsNullOrWhiteSpace(movieData.Release_Date))
{
// These dates are always in this exact format
if (DateTime.TryParse(movieData.release_date, _usCulture, DateTimeStyles.None, out var r))
if (DateTime.TryParse(movieData.Release_Date, _usCulture, DateTimeStyles.None, out var r))
{
movie.PremiereDate = r.ToUniversalTime();
movie.ProductionYear = movie.PremiereDate.Value.Year;
@ -204,16 +204,16 @@ namespace MediaBrowser.Providers.Movies
}
//studios
if (movieData.production_companies != null)
if (movieData.Production_Companies != null)
{
movie.SetStudios(movieData.production_companies.Select(c => c.name));
movie.SetStudios(movieData.Production_Companies.Select(c => c.Name));
}
// genres
// Movies get this from imdb
var genres = movieData.genres ?? new List<MovieDbProvider.GenreItem>();
var genres = movieData.Genres ?? new List<Tmdb.Models.General.Genre>();
foreach (var genre in genres.Select(g => g.name))
foreach (var genre in genres.Select(g => g.Name))
{
movie.AddGenre(genre);
}
@ -223,26 +223,26 @@ namespace MediaBrowser.Providers.Movies
//Actors, Directors, Writers - all in People
//actors come from cast
if (movieData.casts != null && movieData.casts.cast != null)
if (movieData.Casts != null && movieData.Casts.Cast != null)
{
foreach (var actor in movieData.casts.cast.OrderBy(a => a.order))
foreach (var actor in movieData.Casts.Cast.OrderBy(a => a.Order))
{
var personInfo = new PersonInfo
{
Name = actor.name.Trim(),
Role = actor.character,
Name = actor.Name.Trim(),
Role = actor.Character,
Type = PersonType.Actor,
SortOrder = actor.order
SortOrder = actor.Order
};
if (!string.IsNullOrWhiteSpace(actor.profile_path))
if (!string.IsNullOrWhiteSpace(actor.Profile_Path))
{
personInfo.ImageUrl = tmdbImageUrl + actor.profile_path;
personInfo.ImageUrl = tmdbImageUrl + actor.Profile_Path;
}
if (actor.id > 0)
if (actor.Id > 0)
{
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.id.ToString(CultureInfo.InvariantCulture));
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture));
}
resultItem.AddPerson(personInfo);
@ -250,45 +250,41 @@ namespace MediaBrowser.Providers.Movies
}
//and the rest from crew
if (movieData.casts != null && movieData.casts.crew != null)
if (movieData.Casts?.Crew != null)
{
var keepTypes = new[]
{
PersonType.Director,
//PersonType.Writer,
//PersonType.Producer
PersonType.Writer,
PersonType.Producer
};
foreach (var person in movieData.casts.crew)
foreach (var person in movieData.Casts.Crew)
{
// Normalize this
var type = person.department;
if (string.Equals(type, "writing", StringComparison.OrdinalIgnoreCase))
{
type = PersonType.Writer;
}
var type = TmdbUtils.MapCrewToPersonType(person);
if (!keepTypes.Contains(type ?? string.Empty, StringComparer.OrdinalIgnoreCase) &&
!keepTypes.Contains(person.job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
if (!keepTypes.Contains(type, StringComparer.OrdinalIgnoreCase) &&
!keepTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
{
continue;
}
var personInfo = new PersonInfo
{
Name = person.name.Trim(),
Role = person.job,
Name = person.Name.Trim(),
Role = person.Job,
Type = type
};
if (!string.IsNullOrWhiteSpace(person.profile_path))
if (!string.IsNullOrWhiteSpace(person.Profile_Path))
{
personInfo.ImageUrl = tmdbImageUrl + person.profile_path;
personInfo.ImageUrl = tmdbImageUrl + person.Profile_Path;
}
if (person.id > 0)
if (person.Id > 0)
{
personInfo.SetProviderId(MetadataProviders.Tmdb, person.id.ToString(CultureInfo.InvariantCulture));
personInfo.SetProviderId(MetadataProviders.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
}
resultItem.AddPerson(personInfo);
@ -300,12 +296,12 @@ namespace MediaBrowser.Providers.Movies
// movie.Keywords = movieData.keywords.keywords.Select(i => i.name).ToList();
//}
if (movieData.trailers != null && movieData.trailers.youtube != null)
if (movieData.Trailers != null && movieData.Trailers.Youtube != null)
{
movie.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl
movie.RemoteTrailers = movieData.Trailers.Youtube.Select(i => new MediaUrl
{
Url = string.Format("https://www.youtube.com/watch?v={0}", i.source),
Name = i.name
Url = string.Format("https://www.youtube.com/watch?v={0}", i.Source),
Name = i.Name
}).ToArray();
}

View File

@ -13,16 +13,19 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.General;
using MediaBrowser.Providers.Tmdb.Models.Movies;
namespace MediaBrowser.Providers.Movies
namespace MediaBrowser.Providers.Tmdb.Movies
{
public class MovieDbImageProvider : IRemoteImageProvider, IHasOrder
public class TmdbImageProvider : IRemoteImageProvider, IHasOrder
{
private readonly IJsonSerializer _jsonSerializer;
private readonly IHttpClient _httpClient;
private readonly IFileSystem _fileSystem;
public MovieDbImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem)
public TmdbImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem)
{
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
@ -31,7 +34,7 @@ namespace MediaBrowser.Providers.Movies
public string Name => ProviderName;
public static string ProviderName => "TheMovieDb";
public static string ProviderName => TmdbUtils.ProviderName;
public bool Supports(BaseItem item)
{
@ -60,7 +63,7 @@ namespace MediaBrowser.Providers.Movies
return list;
}
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
@ -70,12 +73,12 @@ namespace MediaBrowser.Providers.Movies
{
list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
Url = tmdbImageUrl + i.File_Path,
CommunityRating = i.Vote_Average,
VoteCount = i.Vote_Count,
Width = i.Width,
Height = i.Height,
Language = TmdbMovieProvider.AdjustImageLanguage(i.Iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score
@ -86,11 +89,11 @@ namespace MediaBrowser.Providers.Movies
{
list.AddRange(GetBackdrops(results).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Url = tmdbImageUrl + i.File_Path,
CommunityRating = i.Vote_Average,
VoteCount = i.Vote_Count,
Width = i.Width,
Height = i.Height,
ProviderName = Name,
Type = ImageType.Backdrop,
RatingType = RatingType.Score
@ -127,9 +130,9 @@ namespace MediaBrowser.Providers.Movies
/// </summary>
/// <param name="images">The images.</param>
/// <returns>IEnumerable{MovieDbProvider.Poster}.</returns>
private IEnumerable<MovieDbProvider.Poster> GetPosters(MovieDbProvider.Images images)
private IEnumerable<Poster> GetPosters(Images images)
{
return images.posters ?? new List<MovieDbProvider.Poster>();
return images.Posters ?? new List<Poster>();
}
/// <summary>
@ -137,13 +140,13 @@ namespace MediaBrowser.Providers.Movies
/// </summary>
/// <param name="images">The images.</param>
/// <returns>IEnumerable{MovieDbProvider.Backdrop}.</returns>
private IEnumerable<MovieDbProvider.Backdrop> GetBackdrops(MovieDbProvider.Images images)
private IEnumerable<Backdrop> GetBackdrops(Images images)
{
var eligibleBackdrops = images.backdrops == null ? new List<MovieDbProvider.Backdrop>() :
images.backdrops;
var eligibleBackdrops = images.Backdrops == null ? new List<Backdrop>() :
images.Backdrops;
return eligibleBackdrops.OrderByDescending(i => i.vote_average)
.ThenByDescending(i => i.vote_count);
return eligibleBackdrops.OrderByDescending(i => i.Vote_Average)
.ThenByDescending(i => i.Vote_Count);
}
/// <summary>
@ -154,7 +157,7 @@ namespace MediaBrowser.Providers.Movies
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MovieImages}.</returns>
private async Task<MovieDbProvider.Images> FetchImages(BaseItem item, string language, IJsonSerializer jsonSerializer, CancellationToken cancellationToken)
private async Task<Images> FetchImages(BaseItem item, string language, IJsonSerializer jsonSerializer, CancellationToken cancellationToken)
{
var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);
@ -163,10 +166,10 @@ namespace MediaBrowser.Providers.Movies
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(imdbId))
{
var movieInfo = await MovieDbProvider.Current.FetchMainResult(imdbId, false, language, cancellationToken).ConfigureAwait(false);
var movieInfo = await TmdbMovieProvider.Current.FetchMainResult(imdbId, false, language, cancellationToken).ConfigureAwait(false);
if (movieInfo != null)
{
tmdbId = movieInfo.id.ToString(CultureInfo.InvariantCulture);
tmdbId = movieInfo.Id.ToString(CultureInfo.InvariantCulture);
}
}
}
@ -176,9 +179,9 @@ namespace MediaBrowser.Providers.Movies
return null;
}
await MovieDbProvider.Current.EnsureMovieInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
await TmdbMovieProvider.Current.EnsureMovieInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
var path = MovieDbProvider.Current.GetDataFilePath(tmdbId, language);
var path = TmdbMovieProvider.Current.GetDataFilePath(tmdbId, language);
if (!string.IsNullOrEmpty(path))
{
@ -186,7 +189,7 @@ namespace MediaBrowser.Providers.Movies
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(path).images;
return jsonSerializer.DeserializeFromFile<MovieResult>(path).Images;
}
}

View File

@ -0,0 +1,32 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Tmdb.Movies
{
public class TmdbMovieExternalId : IExternalId
{
/// <inheritdoc />
public string Name => TmdbUtils.ProviderName;
/// <inheritdoc />
public string Key => MetadataProviders.Tmdb.ToString();
/// <inheritdoc />
public string UrlFormatString => TmdbUtils.BaseTmdbUrl + "movie/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
// Supports images for tv movies
if (item is LiveTvProgram tvProgram && tvProgram.IsMovie)
{
return true;
}
return item is Movie || item is MusicVideo || item is Trailer;
}
}
}

View File

@ -19,16 +19,18 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.Movies;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Movies
namespace MediaBrowser.Providers.Tmdb.Movies
{
/// <summary>
/// Class MovieDbProvider
/// </summary>
public class MovieDbProvider : IRemoteMetadataProvider<Movie, MovieInfo>, IHasOrder
public class TmdbMovieProvider : IRemoteMetadataProvider<Movie, MovieInfo>, IHasOrder
{
internal static MovieDbProvider Current { get; private set; }
internal static TmdbMovieProvider Current { get; private set; }
private readonly IJsonSerializer _jsonSerializer;
private readonly IHttpClient _httpClient;
@ -41,7 +43,7 @@ namespace MediaBrowser.Providers.Movies
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public MovieDbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IApplicationHost appHost)
public TmdbMovieProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IApplicationHost appHost)
{
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
@ -71,7 +73,7 @@ namespace MediaBrowser.Providers.Movies
var dataFilePath = GetDataFilePath(tmdbId, searchInfo.MetadataLanguage);
var obj = _jsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath);
var obj = _jsonSerializer.DeserializeFromFile<MovieResult>(dataFilePath);
var tmdbSettings = await GetTmdbSettings(cancellationToken).ConfigureAwait(false);
@ -81,30 +83,30 @@ namespace MediaBrowser.Providers.Movies
{
Name = obj.GetTitle(),
SearchProviderName = Name,
ImageUrl = string.IsNullOrWhiteSpace(obj.poster_path) ? null : tmdbImageUrl + obj.poster_path
ImageUrl = string.IsNullOrWhiteSpace(obj.Poster_Path) ? null : tmdbImageUrl + obj.Poster_Path
};
if (!string.IsNullOrWhiteSpace(obj.release_date))
if (!string.IsNullOrWhiteSpace(obj.Release_Date))
{
// These dates are always in this exact format
if (DateTime.TryParse(obj.release_date, _usCulture, DateTimeStyles.None, out var r))
if (DateTime.TryParse(obj.Release_Date, _usCulture, DateTimeStyles.None, out var r))
{
remoteResult.PremiereDate = r.ToUniversalTime();
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
}
}
remoteResult.SetProviderId(MetadataProviders.Tmdb, obj.id.ToString(_usCulture));
remoteResult.SetProviderId(MetadataProviders.Tmdb, obj.Id.ToString(_usCulture));
if (!string.IsNullOrWhiteSpace(obj.imdb_id))
if (!string.IsNullOrWhiteSpace(obj.Imdb_Id))
{
remoteResult.SetProviderId(MetadataProviders.Imdb, obj.imdb_id);
remoteResult.SetProviderId(MetadataProviders.Imdb, obj.Imdb_Id);
}
return new[] { remoteResult };
}
return await new MovieDbSearch(_logger, _jsonSerializer, _libraryManager).GetMovieSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
return await new TmdbSearch(_logger, _jsonSerializer, _libraryManager).GetMovieSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
}
public Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
@ -115,12 +117,12 @@ namespace MediaBrowser.Providers.Movies
public Task<MetadataResult<T>> GetItemMetadata<T>(ItemLookupInfo id, CancellationToken cancellationToken)
where T : BaseItem, new()
{
var movieDb = new GenericMovieDbInfo<T>(_logger, _jsonSerializer, _libraryManager, _fileSystem);
var movieDb = new GenericTmdbMovieInfo<T>(_logger, _jsonSerializer, _libraryManager, _fileSystem);
return movieDb.GetMetadata(id, cancellationToken);
}
public string Name => "TheMovieDb";
public string Name => TmdbUtils.ProviderName;
/// <summary>
/// The _TMDB settings task
@ -140,9 +142,9 @@ namespace MediaBrowser.Providers.Movies
using (HttpResponseInfo response = await GetMovieDbResponse(new HttpRequestOptions
{
Url = string.Format(TmdbConfigUrl, ApiKey),
Url = string.Format(TmdbConfigUrl, TmdbUtils.ApiKey),
CancellationToken = cancellationToken,
AcceptHeader = AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
@ -155,13 +157,8 @@ namespace MediaBrowser.Providers.Movies
}
}
public const string BaseMovieDbUrl = "https://api.themoviedb.org/";
private const string TmdbConfigUrl = BaseMovieDbUrl + "3/configuration?api_key={0}";
private const string GetMovieInfo3 = BaseMovieDbUrl + @"3/movie/{0}?api_key={1}&append_to_response=casts,releases,images,keywords,trailers";
internal static string ApiKey = "4219e299c89411838049ab0dab19ebd5";
internal static string AcceptHeader = "application/json,image/*";
private const string TmdbConfigUrl = TmdbUtils.BaseTmdbApiUrl + "3/configuration?api_key={0}";
private const string GetMovieInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/movie/{0}?api_key={1}&append_to_response=casts,releases,images,keywords,trailers";
/// <summary>
/// Gets the movie data path.
@ -314,9 +311,9 @@ namespace MediaBrowser.Providers.Movies
/// <param name="language">The language.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task{CompleteMovieData}.</returns>
internal async Task<CompleteMovieData> FetchMainResult(string id, bool isTmdbId, string language, CancellationToken cancellationToken)
internal async Task<MovieResult> FetchMainResult(string id, bool isTmdbId, string language, CancellationToken cancellationToken)
{
var url = string.Format(GetMovieInfo3, id, ApiKey);
var url = string.Format(GetMovieInfo3, id, TmdbUtils.ApiKey);
if (!string.IsNullOrEmpty(language))
{
@ -326,7 +323,7 @@ namespace MediaBrowser.Providers.Movies
url += "&include_image_language=" + GetImageLanguagesParam(language);
}
CompleteMovieData mainResult;
MovieResult mainResult;
cancellationToken.ThrowIfCancellationRequested();
@ -340,7 +337,7 @@ namespace MediaBrowser.Providers.Movies
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = AcceptHeader,
AcceptHeader = TmdbUtils.AcceptHeader,
CacheMode = cacheMode,
CacheLength = cacheLength
@ -348,7 +345,7 @@ namespace MediaBrowser.Providers.Movies
{
using (var json = response.Content)
{
mainResult = await _jsonSerializer.DeserializeFromStreamAsync<CompleteMovieData>(json).ConfigureAwait(false);
mainResult = await _jsonSerializer.DeserializeFromStreamAsync<MovieResult>(json).ConfigureAwait(false);
}
}
}
@ -367,13 +364,13 @@ namespace MediaBrowser.Providers.Movies
// If the language preference isn't english, then have the overview fallback to english if it's blank
if (mainResult != null &&
string.IsNullOrEmpty(mainResult.overview) &&
string.IsNullOrEmpty(mainResult.Overview) &&
!string.IsNullOrEmpty(language) &&
!string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
{
_logger.LogInformation("MovieDbProvider couldn't find meta for language " + language + ". Trying English...");
url = string.Format(GetMovieInfo3, id, ApiKey) + "&language=en";
url = string.Format(GetMovieInfo3, id, TmdbUtils.ApiKey) + "&language=en";
if (!string.IsNullOrEmpty(language))
{
@ -385,7 +382,7 @@ namespace MediaBrowser.Providers.Movies
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = AcceptHeader,
AcceptHeader = TmdbUtils.AcceptHeader,
CacheMode = cacheMode,
CacheLength = cacheLength
@ -393,9 +390,9 @@ namespace MediaBrowser.Providers.Movies
{
using (var json = response.Content)
{
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<CompleteMovieData>(json).ConfigureAwait(false);
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<MovieResult>(json).ConfigureAwait(false);
mainResult.overview = englishResult.overview;
mainResult.Overview = englishResult.Overview;
}
}
}
@ -429,205 +426,6 @@ namespace MediaBrowser.Providers.Movies
return await _httpClient.SendAsync(options, "GET").ConfigureAwait(false);
}
/// <summary>
/// Class TmdbTitle
/// </summary>
internal class TmdbTitle
{
/// <summary>
/// Gets or sets the iso_3166_1.
/// </summary>
/// <value>The iso_3166_1.</value>
public string iso_3166_1 { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public string title { get; set; }
}
/// <summary>
/// Class TmdbAltTitleResults
/// </summary>
internal class TmdbAltTitleResults
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public int id { get; set; }
/// <summary>
/// Gets or sets the titles.
/// </summary>
/// <value>The titles.</value>
public List<TmdbTitle> titles { get; set; }
}
internal class BelongsToCollection
{
public int id { get; set; }
public string name { get; set; }
public string poster_path { get; set; }
public string backdrop_path { get; set; }
}
internal class GenreItem
{
public int id { get; set; }
public string name { get; set; }
}
internal class ProductionCompany
{
public string name { get; set; }
public int id { get; set; }
}
internal class ProductionCountry
{
public string iso_3166_1 { get; set; }
public string name { get; set; }
}
internal class SpokenLanguage
{
public string iso_639_1 { get; set; }
public string name { get; set; }
}
internal class Cast
{
public int id { get; set; }
public string name { get; set; }
public string character { get; set; }
public int order { get; set; }
public int cast_id { get; set; }
public string profile_path { get; set; }
}
internal class Crew
{
public int id { get; set; }
public string name { get; set; }
public string department { get; set; }
public string job { get; set; }
public string profile_path { get; set; }
}
internal class Casts
{
public List<Cast> cast { get; set; }
public List<Crew> crew { get; set; }
}
internal class Country
{
public string iso_3166_1 { get; set; }
public string certification { get; set; }
public DateTime release_date { get; set; }
}
internal class Releases
{
public List<Country> countries { get; set; }
}
internal class Backdrop
{
public string file_path { get; set; }
public int width { get; set; }
public int height { get; set; }
public object iso_639_1 { get; set; }
public double aspect_ratio { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
}
internal class Poster
{
public string file_path { get; set; }
public int width { get; set; }
public int height { get; set; }
public string iso_639_1 { get; set; }
public double aspect_ratio { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
}
internal class Images
{
public List<Backdrop> backdrops { get; set; }
public List<Poster> posters { get; set; }
}
internal class Keyword
{
public int id { get; set; }
public string name { get; set; }
}
internal class Keywords
{
public List<Keyword> keywords { get; set; }
}
internal class Youtube
{
public string name { get; set; }
public string size { get; set; }
public string source { get; set; }
}
internal class Trailers
{
public List<object> quicktime { get; set; }
public List<Youtube> youtube { get; set; }
}
internal class CompleteMovieData
{
public bool adult { get; set; }
public string backdrop_path { get; set; }
public BelongsToCollection belongs_to_collection { get; set; }
public int budget { get; set; }
public List<GenreItem> genres { get; set; }
public string homepage { get; set; }
public int id { get; set; }
public string imdb_id { get; set; }
public string original_title { get; set; }
public string original_name { get; set; }
public string overview { get; set; }
public double popularity { get; set; }
public string poster_path { get; set; }
public List<ProductionCompany> production_companies { get; set; }
public List<ProductionCountry> production_countries { get; set; }
public string release_date { get; set; }
public int revenue { get; set; }
public int runtime { get; set; }
public List<SpokenLanguage> spoken_languages { get; set; }
public string status { get; set; }
public string tagline { get; set; }
public string title { get; set; }
public string name { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public Casts casts { get; set; }
public Releases releases { get; set; }
public Images images { get; set; }
public Keywords keywords { get; set; }
public Trailers trailers { get; set; }
public string GetOriginalTitle()
{
return original_name ?? original_title;
}
public string GetTitle()
{
return name ?? title ?? GetOriginalTitle();
}
}
public int Order => 1;
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)

View File

@ -11,23 +11,21 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Tmdb.Models.Search;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Movies
namespace MediaBrowser.Providers.Tmdb.Movies
{
public class MovieDbSearch
public class TmdbSearch
{
private static readonly CultureInfo EnUs = new CultureInfo("en-US");
private const string Search3 = MovieDbProvider.BaseMovieDbUrl + @"3/search/{3}?api_key={1}&query={0}&language={2}";
internal static string ApiKey = "4219e299c89411838049ab0dab19ebd5";
internal static string AcceptHeader = "application/json,image/*";
private const string Search3 = TmdbUtils.BaseTmdbApiUrl + @"3/search/{3}?api_key={1}&query={0}&language={2}";
private readonly ILogger _logger;
private readonly IJsonSerializer _json;
private readonly ILibraryManager _libraryManager;
public MovieDbSearch(ILogger logger, IJsonSerializer json, ILibraryManager libraryManager)
public TmdbSearch(ILogger logger, IJsonSerializer json, ILibraryManager libraryManager)
{
_logger = logger;
_json = json;
@ -59,7 +57,7 @@ namespace MediaBrowser.Providers.Movies
return new List<RemoteSearchResult>();
}
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
@ -152,43 +150,43 @@ namespace MediaBrowser.Providers.Movies
throw new ArgumentException("name");
}
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, type);
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), TmdbUtils.ApiKey, language, type);
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url3,
CancellationToken = cancellationToken,
AcceptHeader = AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
var searchResults = await _json.DeserializeFromStreamAsync<TmdbMovieSearchResults>(json).ConfigureAwait(false);
var searchResults = await _json.DeserializeFromStreamAsync<TmdbSearchResult<MovieResult>>(json).ConfigureAwait(false);
var results = searchResults.results ?? new List<TmdbMovieSearchResult>();
var results = searchResults.Results ?? new List<MovieResult>();
return results
.Select(i =>
{
var remoteResult = new RemoteSearchResult
{
SearchProviderName = MovieDbProvider.Current.Name,
Name = i.title ?? i.name ?? i.original_title,
ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path
SearchProviderName = TmdbMovieProvider.Current.Name,
Name = i.Title ?? i.Name ?? i.Original_Title,
ImageUrl = string.IsNullOrWhiteSpace(i.Poster_Path) ? null : baseImageUrl + i.Poster_Path
};
if (!string.IsNullOrWhiteSpace(i.release_date))
if (!string.IsNullOrWhiteSpace(i.Release_Date))
{
// These dates are always in this exact format
if (DateTime.TryParseExact(i.release_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out var r))
if (DateTime.TryParseExact(i.Release_Date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out var r))
{
remoteResult.PremiereDate = r.ToUniversalTime();
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
}
}
remoteResult.SetProviderId(MetadataProviders.Tmdb, i.id.ToString(EnUs));
remoteResult.SetProviderId(MetadataProviders.Tmdb, i.Id.ToString(EnUs));
return remoteResult;
@ -205,43 +203,43 @@ namespace MediaBrowser.Providers.Movies
throw new ArgumentException("name");
}
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, "tv");
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), TmdbUtils.ApiKey, language, "tv");
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url3,
CancellationToken = cancellationToken,
AcceptHeader = AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
var searchResults = await _json.DeserializeFromStreamAsync<TmdbTvSearchResults>(json).ConfigureAwait(false);
var searchResults = await _json.DeserializeFromStreamAsync<TmdbSearchResult<TvResult>>(json).ConfigureAwait(false);
var results = searchResults.results ?? new List<TvResult>();
var results = searchResults.Results ?? new List<TvResult>();
return results
.Select(i =>
{
var remoteResult = new RemoteSearchResult
{
SearchProviderName = MovieDbProvider.Current.Name,
Name = i.name ?? i.original_name,
ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path
SearchProviderName = TmdbMovieProvider.Current.Name,
Name = i.Name ?? i.Original_Name,
ImageUrl = string.IsNullOrWhiteSpace(i.Poster_Path) ? null : baseImageUrl + i.Poster_Path
};
if (!string.IsNullOrWhiteSpace(i.first_air_date))
if (!string.IsNullOrWhiteSpace(i.First_Air_Date))
{
// These dates are always in this exact format
if (DateTime.TryParseExact(i.first_air_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out var r))
if (DateTime.TryParseExact(i.First_Air_Date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out var r))
{
remoteResult.PremiereDate = r.ToUniversalTime();
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
}
}
remoteResult.SetProviderId(MetadataProviders.Tmdb, i.id.ToString(EnUs));
remoteResult.SetProviderId(MetadataProviders.Tmdb, i.Id.ToString(EnUs));
return remoteResult;
@ -250,145 +248,5 @@ namespace MediaBrowser.Providers.Movies
}
}
}
/// <summary>
/// Class TmdbMovieSearchResult
/// </summary>
public class TmdbMovieSearchResult
{
/// <summary>
/// Gets or sets a value indicating whether this <see cref="TmdbMovieSearchResult" /> is adult.
/// </summary>
/// <value><c>true</c> if adult; otherwise, <c>false</c>.</value>
public bool adult { get; set; }
/// <summary>
/// Gets or sets the backdrop_path.
/// </summary>
/// <value>The backdrop_path.</value>
public string backdrop_path { get; set; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public int id { get; set; }
/// <summary>
/// Gets or sets the original_title.
/// </summary>
/// <value>The original_title.</value>
public string original_title { get; set; }
/// <summary>
/// Gets or sets the original_name.
/// </summary>
/// <value>The original_name.</value>
public string original_name { get; set; }
/// <summary>
/// Gets or sets the release_date.
/// </summary>
/// <value>The release_date.</value>
public string release_date { get; set; }
/// <summary>
/// Gets or sets the poster_path.
/// </summary>
/// <value>The poster_path.</value>
public string poster_path { get; set; }
/// <summary>
/// Gets or sets the popularity.
/// </summary>
/// <value>The popularity.</value>
public double popularity { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public string title { get; set; }
/// <summary>
/// Gets or sets the vote_average.
/// </summary>
/// <value>The vote_average.</value>
public double vote_average { get; set; }
/// <summary>
/// For collection search results
/// </summary>
public string name { get; set; }
/// <summary>
/// Gets or sets the vote_count.
/// </summary>
/// <value>The vote_count.</value>
public int vote_count { get; set; }
}
/// <summary>
/// Class TmdbMovieSearchResults
/// </summary>
private class TmdbMovieSearchResults
{
/// <summary>
/// Gets or sets the page.
/// </summary>
/// <value>The page.</value>
public int page { get; set; }
/// <summary>
/// Gets or sets the results.
/// </summary>
/// <value>The results.</value>
public List<TmdbMovieSearchResult> results { get; set; }
/// <summary>
/// Gets or sets the total_pages.
/// </summary>
/// <value>The total_pages.</value>
public int total_pages { get; set; }
/// <summary>
/// Gets or sets the total_results.
/// </summary>
/// <value>The total_results.</value>
public int total_results { get; set; }
}
public class TvResult
{
public string backdrop_path { get; set; }
public string first_air_date { get; set; }
public int id { get; set; }
public string original_name { get; set; }
public string poster_path { get; set; }
public double popularity { get; set; }
public string name { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
}
/// <summary>
/// Class TmdbTvSearchResults
/// </summary>
private class TmdbTvSearchResults
{
/// <summary>
/// Gets or sets the page.
/// </summary>
/// <value>The page.</value>
public int page { get; set; }
/// <summary>
/// Gets or sets the results.
/// </summary>
/// <value>The results.</value>
public List<TvResult> results { get; set; }
/// <summary>
/// Gets or sets the total_pages.
/// </summary>
/// <value>The total_pages.</value>
public int total_pages { get; set; }
/// <summary>
/// Gets or sets the total_results.
/// </summary>
/// <value>The total_results.</value>
public int total_results { get; set; }
}
public class ExternalIdLookupResult
{
public List<object> movie_results { get; set; }
public List<object> person_results { get; set; }
public List<TvResult> tv_results { get; set; }
}
}
}

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace MediaBrowser.Providers.Movies
namespace MediaBrowser.Providers.Tmdb.Movies
{
internal class TmdbImageSettings
{

View File

@ -7,14 +7,15 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Providers;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Movies;
namespace MediaBrowser.Providers.Music
namespace MediaBrowser.Providers.Tmdb.Music
{
public class MovieDbMusicVideoProvider : IRemoteMetadataProvider<MusicVideo, MusicVideoInfo>
public class TmdbMusicVideoProvider : IRemoteMetadataProvider<MusicVideo, MusicVideoInfo>
{
public Task<MetadataResult<MusicVideo>> GetMetadata(MusicVideoInfo info, CancellationToken cancellationToken)
{
return MovieDbProvider.Current.GetItemMetadata<MusicVideo>(info, cancellationToken);
return TmdbMovieProvider.Current.GetItemMetadata<MusicVideo>(info, cancellationToken);
}
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MusicVideoInfo searchInfo, CancellationToken cancellationToken)
@ -22,7 +23,7 @@ namespace MediaBrowser.Providers.Music
return Task.FromResult((IEnumerable<RemoteSearchResult>)new List<RemoteSearchResult>());
}
public string Name => MovieDbProvider.Current.Name;
public string Name => TmdbMovieProvider.Current.Name;
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{

View File

@ -0,0 +1,24 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Tmdb.People
{
public class TmdbPersonExternalId : IExternalId
{
/// <inheritdoc />
public string Name => TmdbUtils.ProviderName;
/// <inheritdoc />
public string Key => MetadataProviders.Tmdb.ToString();
/// <inheritdoc />
public string UrlFormatString => TmdbUtils.BaseTmdbUrl + "person/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Person;
}
}
}

View File

@ -11,16 +11,19 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.General;
using MediaBrowser.Providers.Tmdb.Models.People;
using MediaBrowser.Providers.Tmdb.Movies;
namespace MediaBrowser.Providers.People
namespace MediaBrowser.Providers.Tmdb.People
{
public class MovieDbPersonImageProvider : IRemoteImageProvider, IHasOrder
public class TmdbPersonImageProvider : IRemoteImageProvider, IHasOrder
{
private readonly IServerConfigurationManager _config;
private readonly IJsonSerializer _jsonSerializer;
private readonly IHttpClient _httpClient;
public MovieDbPersonImageProvider(IServerConfigurationManager config, IJsonSerializer jsonSerializer, IHttpClient httpClient)
public TmdbPersonImageProvider(IServerConfigurationManager config, IJsonSerializer jsonSerializer, IHttpClient httpClient)
{
_config = config;
_jsonSerializer = jsonSerializer;
@ -29,7 +32,7 @@ namespace MediaBrowser.Providers.People
public string Name => ProviderName;
public static string ProviderName => "TheMovieDb";
public static string ProviderName => TmdbUtils.ProviderName;
public bool Supports(BaseItem item)
{
@ -51,15 +54,15 @@ namespace MediaBrowser.Providers.People
if (!string.IsNullOrEmpty(id))
{
await MovieDbPersonProvider.Current.EnsurePersonInfo(id, cancellationToken).ConfigureAwait(false);
await TmdbPersonProvider.Current.EnsurePersonInfo(id, cancellationToken).ConfigureAwait(false);
var dataFilePath = MovieDbPersonProvider.GetPersonDataFilePath(_config.ApplicationPaths, id);
var dataFilePath = TmdbPersonProvider.GetPersonDataFilePath(_config.ApplicationPaths, id);
var result = _jsonSerializer.DeserializeFromFile<MovieDbPersonProvider.PersonResult>(dataFilePath);
var result = _jsonSerializer.DeserializeFromFile<PersonResult>(dataFilePath);
var images = result.images ?? new MovieDbPersonProvider.Images();
var images = result.Images ?? new PersonImages();
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
@ -69,20 +72,20 @@ namespace MediaBrowser.Providers.People
return new List<RemoteImageInfo>();
}
private IEnumerable<RemoteImageInfo> GetImages(MovieDbPersonProvider.Images images, string preferredLanguage, string baseImageUrl)
private IEnumerable<RemoteImageInfo> GetImages(PersonImages images, string preferredLanguage, string baseImageUrl)
{
var list = new List<RemoteImageInfo>();
if (images.profiles != null)
if (images.Profiles != null)
{
list.AddRange(images.profiles.Select(i => new RemoteImageInfo
list.AddRange(images.Profiles.Select(i => new RemoteImageInfo
{
ProviderName = Name,
Type = ImageType.Primary,
Width = i.width,
Height = i.height,
Width = i.Width,
Height = i.Height,
Language = GetLanguage(i),
Url = baseImageUrl + i.file_path
Url = baseImageUrl + i.File_Path
}));
}
@ -113,9 +116,9 @@ namespace MediaBrowser.Providers.People
.ThenByDescending(i => i.VoteCount ?? 0);
}
private string GetLanguage(MovieDbPersonProvider.Profile profile)
private string GetLanguage(Profile profile)
{
return profile.iso_639_1 == null ? null : profile.iso_639_1.ToString();
return profile.Iso_639_1?.ToString();
}
public int Order => 0;

View File

@ -17,16 +17,19 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.General;
using MediaBrowser.Providers.Tmdb.Models.People;
using MediaBrowser.Providers.Tmdb.Models.Search;
using MediaBrowser.Providers.Tmdb.Movies;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.People
namespace MediaBrowser.Providers.Tmdb.People
{
public class MovieDbPersonProvider : IRemoteMetadataProvider<Person, PersonLookupInfo>
public class TmdbPersonProvider : IRemoteMetadataProvider<Person, PersonLookupInfo>
{
const string DataFileName = "info.json";
internal static MovieDbPersonProvider Current { get; private set; }
internal static TmdbPersonProvider Current { get; private set; }
private readonly IJsonSerializer _jsonSerializer;
private readonly IFileSystem _fileSystem;
@ -34,7 +37,7 @@ namespace MediaBrowser.Providers.People
private readonly IHttpClient _httpClient;
private readonly ILogger _logger;
public MovieDbPersonProvider(IFileSystem fileSystem, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger)
public TmdbPersonProvider(IFileSystem fileSystem, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger)
{
_fileSystem = fileSystem;
_configurationManager = configurationManager;
@ -44,13 +47,13 @@ namespace MediaBrowser.Providers.People
Current = this;
}
public string Name => "TheMovieDb";
public string Name => TmdbUtils.ProviderName;
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
{
var tmdbId = searchInfo.GetProviderId(MetadataProviders.Tmdb);
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
@ -61,19 +64,19 @@ namespace MediaBrowser.Providers.People
var dataFilePath = GetPersonDataFilePath(_configurationManager.ApplicationPaths, tmdbId);
var info = _jsonSerializer.DeserializeFromFile<PersonResult>(dataFilePath);
var images = (info.images ?? new Images()).profiles ?? new List<Profile>();
var images = (info.Images ?? new PersonImages()).Profiles ?? new List<Profile>();
var result = new RemoteSearchResult
{
Name = info.name,
Name = info.Name,
SearchProviderName = Name,
ImageUrl = images.Count == 0 ? null : (tmdbImageUrl + images[0].file_path)
ImageUrl = images.Count == 0 ? null : (tmdbImageUrl + images[0].File_Path)
};
result.SetProviderId(MetadataProviders.Tmdb, info.id.ToString(_usCulture));
result.SetProviderId(MetadataProviders.Imdb, info.imdb_id);
result.SetProviderId(MetadataProviders.Tmdb, info.Id.ToString(_usCulture));
result.SetProviderId(MetadataProviders.Imdb, info.Imdb_Id);
return new[] { result };
}
@ -84,20 +87,20 @@ namespace MediaBrowser.Providers.People
return new List<RemoteSearchResult>();
}
var url = string.Format(MovieDbProvider.BaseMovieDbUrl + @"3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), MovieDbProvider.ApiKey);
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), TmdbUtils.ApiKey);
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbProvider.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
var result = await _jsonSerializer.DeserializeFromStreamAsync<PersonSearchResults>(json).ConfigureAwait(false) ??
new PersonSearchResults();
var result = await _jsonSerializer.DeserializeFromStreamAsync<TmdbSearchResult<PersonSearchResult>>(json).ConfigureAwait(false) ??
new TmdbSearchResult<PersonSearchResult>();
return result.Results.Select(i => GetSearchResult(i, tmdbImageUrl));
}
@ -112,7 +115,7 @@ namespace MediaBrowser.Providers.People
Name = i.Name,
ImageUrl = string.IsNullOrEmpty(i.Profile_Path) ? null : (baseImageUrl + i.Profile_Path)
ImageUrl = string.IsNullOrEmpty(i.Profile_Path) ? null : baseImageUrl + i.Profile_Path
};
result.SetProviderId(MetadataProviders.Tmdb, i.Id.ToString(_usCulture));
@ -161,27 +164,27 @@ namespace MediaBrowser.Providers.People
//item.HomePageUrl = info.homepage;
if (!string.IsNullOrWhiteSpace(info.place_of_birth))
if (!string.IsNullOrWhiteSpace(info.Place_Of_Birth))
{
item.ProductionLocations = new string[] { info.place_of_birth };
item.ProductionLocations = new string[] { info.Place_Of_Birth };
}
item.Overview = info.biography;
item.Overview = info.Biography;
if (DateTime.TryParseExact(info.birthday, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out var date))
if (DateTime.TryParseExact(info.Birthday, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out var date))
{
item.PremiereDate = date.ToUniversalTime();
}
if (DateTime.TryParseExact(info.deathday, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out date))
if (DateTime.TryParseExact(info.Deathday, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out date))
{
item.EndDate = date.ToUniversalTime();
}
item.SetProviderId(MetadataProviders.Tmdb, info.id.ToString(_usCulture));
item.SetProviderId(MetadataProviders.Tmdb, info.Id.ToString(_usCulture));
if (!string.IsNullOrEmpty(info.imdb_id))
if (!string.IsNullOrEmpty(info.Imdb_Id))
{
item.SetProviderId(MetadataProviders.Imdb, info.imdb_id);
item.SetProviderId(MetadataProviders.Imdb, info.Imdb_Id);
}
result.HasMetadata = true;
@ -217,13 +220,13 @@ namespace MediaBrowser.Providers.People
return;
}
var url = string.Format(MovieDbProvider.BaseMovieDbUrl + @"3/person/{1}?api_key={0}&append_to_response=credits,images,external_ids", MovieDbProvider.ApiKey, id);
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/person/{1}?api_key={0}&append_to_response=credits,images,external_ids", TmdbUtils.ApiKey, id);
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbProvider.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
@ -256,133 +259,6 @@ namespace MediaBrowser.Providers.People
return Path.Combine(appPaths.CachePath, "tmdb-people");
}
#region Result Objects
/// <summary>
/// Class PersonSearchResult
/// </summary>
public class PersonSearchResult
{
/// <summary>
/// Gets or sets a value indicating whether this <see cref="PersonSearchResult" /> is adult.
/// </summary>
/// <value><c>true</c> if adult; otherwise, <c>false</c>.</value>
public bool Adult { get; set; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public int Id { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the profile_ path.
/// </summary>
/// <value>The profile_ path.</value>
public string Profile_Path { get; set; }
}
/// <summary>
/// Class PersonSearchResults
/// </summary>
public class PersonSearchResults
{
/// <summary>
/// Gets or sets the page.
/// </summary>
/// <value>The page.</value>
public int Page { get; set; }
/// <summary>
/// Gets or sets the results.
/// </summary>
/// <value>The results.</value>
public List<PersonSearchResult> Results { get; set; }
/// <summary>
/// Gets or sets the total_ pages.
/// </summary>
/// <value>The total_ pages.</value>
public int Total_Pages { get; set; }
/// <summary>
/// Gets or sets the total_ results.
/// </summary>
/// <value>The total_ results.</value>
public int Total_Results { get; set; }
}
public class Cast
{
public int id { get; set; }
public string title { get; set; }
public string character { get; set; }
public string original_title { get; set; }
public string poster_path { get; set; }
public string release_date { get; set; }
public bool adult { get; set; }
}
public class Crew
{
public int id { get; set; }
public string title { get; set; }
public string original_title { get; set; }
public string department { get; set; }
public string job { get; set; }
public string poster_path { get; set; }
public string release_date { get; set; }
public bool adult { get; set; }
}
public class Credits
{
public List<Cast> cast { get; set; }
public List<Crew> crew { get; set; }
}
public class Profile
{
public string file_path { get; set; }
public int width { get; set; }
public int height { get; set; }
public object iso_639_1 { get; set; }
public double aspect_ratio { get; set; }
}
public class Images
{
public List<Profile> profiles { get; set; }
}
public class ExternalIds
{
public string imdb_id { get; set; }
public string freebase_mid { get; set; }
public string freebase_id { get; set; }
public int tvrage_id { get; set; }
}
public class PersonResult
{
public bool adult { get; set; }
public List<object> also_known_as { get; set; }
public string biography { get; set; }
public string birthday { get; set; }
public string deathday { get; set; }
public string homepage { get; set; }
public int id { get; set; }
public string imdb_id { get; set; }
public string name { get; set; }
public string place_of_birth { get; set; }
public double popularity { get; set; }
public string profile_path { get; set; }
public Credits credits { get; set; }
public Images images { get; set; }
public ExternalIds external_ids { get; set; }
}
#endregion
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions

View File

@ -14,16 +14,18 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.General;
using MediaBrowser.Providers.Tmdb.Movies;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.TV.TheMovieDb
namespace MediaBrowser.Providers.Tmdb.TV
{
public class MovieDbEpisodeImageProvider :
MovieDbProviderBase,
public class TmdbEpisodeImageProvider :
TmdbEpisodeProviderBase,
IRemoteImageProvider,
IHasOrder
{
public MovieDbEpisodeImageProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
public TmdbEpisodeImageProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
: base(httpClient, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
{ }
@ -62,18 +64,18 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
var response = await GetEpisodeInfo(seriesId, seasonNumber.Value, episodeNumber.Value,
language, cancellationToken).ConfigureAwait(false);
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
list.AddRange(GetPosters(response.images).Select(i => new RemoteImageInfo
list.AddRange(GetPosters(response.Images).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
Url = tmdbImageUrl + i.File_Path,
CommunityRating = i.Vote_Average,
VoteCount = i.Vote_Count,
Width = i.Width,
Height = i.Height,
Language = TmdbMovieProvider.AdjustImageLanguage(i.Iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score
@ -106,9 +108,9 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
}
private IEnumerable<Still> GetPosters(Images images)
private IEnumerable<Still> GetPosters(StillImages images)
{
return images.stills ?? new List<Still>();
return images.Stills ?? new List<Still>();
}
@ -117,12 +119,13 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
return GetResponse(url, cancellationToken);
}
public string Name => "TheMovieDb";
public string Name => TmdbUtils.ProviderName;
public bool Supports(BaseItem item)
{
return item is Controller.Entities.TV.Episode;
}
// After TheTvDb
public int Order => 1;
}

View File

@ -18,14 +18,14 @@ using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.TV.TheMovieDb
namespace MediaBrowser.Providers.Tmdb.TV
{
public class MovieDbEpisodeProvider :
MovieDbProviderBase,
public class TmdbEpisodeProvider :
TmdbEpisodeProviderBase,
IRemoteMetadataProvider<Episode, EpisodeInfo>,
IHasOrder
{
public MovieDbEpisodeProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
public TmdbEpisodeProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
: base(httpClient, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
{ }
@ -93,7 +93,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
result.HasMetadata = true;
result.QueriedById = true;
if (!string.IsNullOrEmpty(response.overview))
if (!string.IsNullOrEmpty(response.Overview))
{
// if overview is non-empty, we can assume that localized data was returned
result.ResultLanguage = info.MetadataLanguage;
@ -107,30 +107,29 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
item.ParentIndexNumber = info.ParentIndexNumber;
item.IndexNumberEnd = info.IndexNumberEnd;
if (response.external_ids.tvdb_id > 0)
if (response.External_Ids.Tvdb_Id > 0)
{
item.SetProviderId(MetadataProviders.Tvdb, response.external_ids.tvdb_id.ToString(CultureInfo.InvariantCulture));
item.SetProviderId(MetadataProviders.Tvdb, response.External_Ids.Tvdb_Id.ToString(CultureInfo.InvariantCulture));
}
item.PremiereDate = response.air_date;
item.PremiereDate = response.Air_Date;
item.ProductionYear = result.Item.PremiereDate.Value.Year;
item.Name = response.name;
item.Overview = response.overview;
item.Name = response.Name;
item.Overview = response.Overview;
item.CommunityRating = (float)response.vote_average;
//item.VoteCount = response.vote_count;
item.CommunityRating = (float)response.Vote_Average;
if (response.videos != null && response.videos.results != null)
if (response.Videos?.Results != null)
{
foreach (var video in response.videos.results)
foreach (var video in response.Videos.Results)
{
if (video.type.Equals("trailer", System.StringComparison.OrdinalIgnoreCase)
|| video.type.Equals("clip", System.StringComparison.OrdinalIgnoreCase))
if (video.Type.Equals("trailer", System.StringComparison.OrdinalIgnoreCase)
|| video.Type.Equals("clip", System.StringComparison.OrdinalIgnoreCase))
{
if (video.site.Equals("youtube", System.StringComparison.OrdinalIgnoreCase))
if (video.Site.Equals("youtube", System.StringComparison.OrdinalIgnoreCase))
{
var videoUrl = string.Format("http://www.youtube.com/watch?v={0}", video.key);
var videoUrl = string.Format("http://www.youtube.com/watch?v={0}", video.Key);
item.AddTrailerUrl(videoUrl);
}
}
@ -139,54 +138,50 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
result.ResetPeople();
var credits = response.credits;
var credits = response.Credits;
if (credits != null)
{
//Actors, Directors, Writers - all in People
//actors come from cast
if (credits.cast != null)
if (credits.Cast != null)
{
foreach (var actor in credits.cast.OrderBy(a => a.order))
foreach (var actor in credits.Cast.OrderBy(a => a.Order))
{
result.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order });
result.AddPerson(new PersonInfo { Name = actor.Name.Trim(), Role = actor.Character, Type = PersonType.Actor, SortOrder = actor.Order });
}
}
// guest stars
if (credits.guest_stars != null)
if (credits.Guest_Stars != null)
{
foreach (var guest in credits.guest_stars.OrderBy(a => a.order))
foreach (var guest in credits.Guest_Stars.OrderBy(a => a.Order))
{
result.AddPerson(new PersonInfo { Name = guest.name.Trim(), Role = guest.character, Type = PersonType.GuestStar, SortOrder = guest.order });
result.AddPerson(new PersonInfo { Name = guest.Name.Trim(), Role = guest.Character, Type = PersonType.GuestStar, SortOrder = guest.Order });
}
}
//and the rest from crew
if (credits.crew != null)
if (credits.Crew != null)
{
var keepTypes = new[]
{
PersonType.Director,
//PersonType.Writer,
//PersonType.Producer
PersonType.Writer,
PersonType.Producer
};
foreach (var person in credits.crew)
foreach (var person in credits.Crew)
{
// Normalize this
var type = person.department;
if (string.Equals(type, "writing", StringComparison.OrdinalIgnoreCase))
{
type = PersonType.Writer;
}
var type = TmdbUtils.MapCrewToPersonType(person);
if (!keepTypes.Contains(type ?? string.Empty, StringComparer.OrdinalIgnoreCase) &&
!keepTypes.Contains(person.job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
if (!keepTypes.Contains(type, StringComparer.OrdinalIgnoreCase) &&
!keepTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
{
continue;
}
result.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = type });
result.AddPerson(new PersonInfo { Name = person.Name.Trim(), Role = person.Job, Type = type });
}
}
}
@ -211,6 +206,6 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
// After TheTvDb
public int Order => 1;
public string Name => "TheMovieDb";
public string Name => TmdbUtils.ProviderName;
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
@ -10,13 +9,15 @@ using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.TV;
using MediaBrowser.Providers.Tmdb.Movies;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.TV.TheMovieDb
namespace MediaBrowser.Providers.Tmdb.TV
{
public abstract class MovieDbProviderBase
public abstract class TmdbEpisodeProviderBase
{
private const string EpisodeUrlPattern = MovieDbProvider.BaseMovieDbUrl + @"3/tv/{0}/season/{1}/episode/{2}?api_key={3}&append_to_response=images,external_ids,credits,videos";
private const string EpisodeUrlPattern = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}/season/{1}/episode/{2}?api_key={3}&append_to_response=images,external_ids,credits,videos";
private readonly IHttpClient _httpClient;
private readonly IServerConfigurationManager _configurationManager;
private readonly IJsonSerializer _jsonSerializer;
@ -24,7 +25,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
private readonly ILocalizationManager _localization;
private readonly ILogger _logger;
public MovieDbProviderBase(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
protected TmdbEpisodeProviderBase(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
{
_httpClient = httpClient;
_configurationManager = configurationManager;
@ -36,7 +37,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
protected ILogger Logger => _logger;
protected async Task<RootObject> GetEpisodeInfo(string seriesTmdbId, int season, int episodeNumber, string preferredMetadataLanguage,
protected async Task<EpisodeResult> GetEpisodeInfo(string seriesTmdbId, int season, int episodeNumber, string preferredMetadataLanguage,
CancellationToken cancellationToken)
{
await EnsureEpisodeInfo(seriesTmdbId, season, episodeNumber, preferredMetadataLanguage, cancellationToken)
@ -44,7 +45,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
var dataFilePath = GetDataFilePath(seriesTmdbId, season, episodeNumber, preferredMetadataLanguage);
return _jsonSerializer.DeserializeFromFile<RootObject>(dataFilePath);
return _jsonSerializer.DeserializeFromFile<EpisodeResult>(dataFilePath);
}
internal Task EnsureEpisodeInfo(string tmdbId, int seasonNumber, int episodeNumber, string language, CancellationToken cancellationToken)
@ -85,7 +86,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
throw new ArgumentNullException(nameof(preferredLanguage));
}
var path = MovieDbSeriesProvider.GetSeriesDataPath(_configurationManager.ApplicationPaths, tmdbId);
var path = TmdbSeriesProvider.GetSeriesDataPath(_configurationManager.ApplicationPaths, tmdbId);
var filename = string.Format("season-{0}-episode-{1}-{2}.json",
seasonNumber.ToString(CultureInfo.InvariantCulture),
@ -105,32 +106,32 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
}
internal async Task<RootObject> FetchMainResult(string urlPattern, string id, int seasonNumber, int episodeNumber, string language, CancellationToken cancellationToken)
internal async Task<EpisodeResult> FetchMainResult(string urlPattern, string id, int seasonNumber, int episodeNumber, string language, CancellationToken cancellationToken)
{
var url = string.Format(urlPattern, id, seasonNumber.ToString(CultureInfo.InvariantCulture), episodeNumber, MovieDbProvider.ApiKey);
var url = string.Format(urlPattern, id, seasonNumber.ToString(CultureInfo.InvariantCulture), episodeNumber, TmdbUtils.ApiKey);
if (!string.IsNullOrEmpty(language))
{
url += string.Format("&language={0}", language);
}
var includeImageLanguageParam = MovieDbProvider.GetImageLanguagesParam(language);
var includeImageLanguageParam = TmdbMovieProvider.GetImageLanguagesParam(language);
// Get images in english and with no language
url += "&include_image_language=" + includeImageLanguageParam;
cancellationToken.ThrowIfCancellationRequested();
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbProvider.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
return await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(json).ConfigureAwait(false);
return await _jsonSerializer.DeserializeFromStreamAsync<EpisodeResult>(json).ConfigureAwait(false);
}
}
}
@ -143,103 +144,5 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
Url = url
});
}
public class Still
{
public double aspect_ratio { get; set; }
public string file_path { get; set; }
public int height { get; set; }
public string id { get; set; }
public string iso_639_1 { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public int width { get; set; }
}
public class Images
{
public List<Still> stills { get; set; }
}
public class ExternalIds
{
public string imdb_id { get; set; }
public object freebase_id { get; set; }
public string freebase_mid { get; set; }
public int tvdb_id { get; set; }
public int tvrage_id { get; set; }
}
public class Cast
{
public string character { get; set; }
public string credit_id { get; set; }
public int id { get; set; }
public string name { get; set; }
public string profile_path { get; set; }
public int order { get; set; }
}
public class Crew
{
public int id { get; set; }
public string credit_id { get; set; }
public string name { get; set; }
public string department { get; set; }
public string job { get; set; }
public string profile_path { get; set; }
}
public class GuestStar
{
public int id { get; set; }
public string name { get; set; }
public string credit_id { get; set; }
public string character { get; set; }
public int order { get; set; }
public string profile_path { get; set; }
}
public class Credits
{
public List<Cast> cast { get; set; }
public List<Crew> crew { get; set; }
public List<GuestStar> guest_stars { get; set; }
}
public class Videos
{
public List<Video> results { get; set; }
}
public class Video
{
public string id { get; set; }
public string iso_639_1 { get; set; }
public string iso_3166_1 { get; set; }
public string key { get; set; }
public string name { get; set; }
public string site { get; set; }
public string size { get; set; }
public string type { get; set; }
}
public class RootObject
{
public DateTime air_date { get; set; }
public int episode_number { get; set; }
public string name { get; set; }
public string overview { get; set; }
public int id { get; set; }
public object production_code { get; set; }
public int season_number { get; set; }
public string still_path { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public Images images { get; set; }
public ExternalIds external_ids { get; set; }
public Credits credits { get; set; }
public Videos videos { get; set; }
}
}
}

View File

@ -7,7 +7,6 @@ using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
@ -16,13 +15,16 @@ using MediaBrowser.Model.Net;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.TV;
using MediaBrowser.Providers.Tmdb.Movies;
using Microsoft.Extensions.Logging;
using Season = MediaBrowser.Controller.Entities.TV.Season;
namespace MediaBrowser.Providers.TV.TheMovieDb
namespace MediaBrowser.Providers.Tmdb.TV
{
public class MovieDbSeasonProvider : IRemoteMetadataProvider<Season, SeasonInfo>
public class TmdbSeasonProvider : IRemoteMetadataProvider<Season, SeasonInfo>
{
private const string GetTvInfo3 = MovieDbProvider.BaseMovieDbUrl + @"3/tv/{0}/season/{1}?api_key={2}&append_to_response=images,keywords,external_ids,credits,videos";
private const string GetTvInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}/season/{1}?api_key={2}&append_to_response=images,keywords,external_ids,credits,videos";
private readonly IHttpClient _httpClient;
private readonly IServerConfigurationManager _configurationManager;
private readonly IJsonSerializer _jsonSerializer;
@ -30,7 +32,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
private readonly ILocalizationManager _localization;
private readonly ILogger _logger;
public MovieDbSeasonProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, ILoggerFactory loggerFactory)
public TmdbSeasonProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, ILoggerFactory loggerFactory)
{
_httpClient = httpClient;
_configurationManager = configurationManager;
@ -65,31 +67,31 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
result.Item.IndexNumber = seasonNumber;
result.Item.Overview = seasonInfo.overview;
result.Item.Overview = seasonInfo.Overview;
if (seasonInfo.external_ids.tvdb_id > 0)
if (seasonInfo.External_Ids.Tvdb_Id > 0)
{
result.Item.SetProviderId(MetadataProviders.Tvdb, seasonInfo.external_ids.tvdb_id.ToString(CultureInfo.InvariantCulture));
result.Item.SetProviderId(MetadataProviders.Tvdb, seasonInfo.External_Ids.Tvdb_Id.ToString(CultureInfo.InvariantCulture));
}
var credits = seasonInfo.credits;
var credits = seasonInfo.Credits;
if (credits != null)
{
//Actors, Directors, Writers - all in People
//actors come from cast
if (credits.cast != null)
if (credits.Cast != null)
{
//foreach (var actor in credits.cast.OrderBy(a => a.order)) result.Item.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order });
}
//and the rest from crew
if (credits.crew != null)
if (credits.Crew != null)
{
//foreach (var person in credits.crew) result.Item.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department });
}
}
result.Item.PremiereDate = seasonInfo.air_date;
result.Item.PremiereDate = seasonInfo.Air_Date;
result.Item.ProductionYear = result.Item.PremiereDate.Value.Year;
}
catch (HttpException ex)
@ -108,7 +110,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
return result;
}
public string Name => "TheMovieDb";
public string Name => TmdbUtils.ProviderName;
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeasonInfo searchInfo, CancellationToken cancellationToken)
{
@ -124,7 +126,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
});
}
private async Task<RootObject> GetSeasonInfo(string seriesTmdbId, int season, string preferredMetadataLanguage,
private async Task<SeasonResult> GetSeasonInfo(string seriesTmdbId, int season, string preferredMetadataLanguage,
CancellationToken cancellationToken)
{
await EnsureSeasonInfo(seriesTmdbId, season, preferredMetadataLanguage, cancellationToken)
@ -132,7 +134,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
var dataFilePath = GetDataFilePath(seriesTmdbId, season, preferredMetadataLanguage);
return _jsonSerializer.DeserializeFromFile<RootObject>(dataFilePath);
return _jsonSerializer.DeserializeFromFile<SeasonResult>(dataFilePath);
}
internal Task EnsureSeasonInfo(string tmdbId, int seasonNumber, string language, CancellationToken cancellationToken)
@ -173,7 +175,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
throw new ArgumentNullException(nameof(preferredLanguage));
}
var path = MovieDbSeriesProvider.GetSeriesDataPath(_configurationManager.ApplicationPaths, tmdbId);
var path = TmdbSeriesProvider.GetSeriesDataPath(_configurationManager.ApplicationPaths, tmdbId);
var filename = string.Format("season-{0}-{1}.json",
seasonNumber.ToString(CultureInfo.InvariantCulture),
@ -192,117 +194,34 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
}
internal async Task<RootObject> FetchMainResult(string id, int seasonNumber, string language, CancellationToken cancellationToken)
internal async Task<SeasonResult> FetchMainResult(string id, int seasonNumber, string language, CancellationToken cancellationToken)
{
var url = string.Format(GetTvInfo3, id, seasonNumber.ToString(CultureInfo.InvariantCulture), MovieDbProvider.ApiKey);
var url = string.Format(GetTvInfo3, id, seasonNumber.ToString(CultureInfo.InvariantCulture), TmdbUtils.ApiKey);
if (!string.IsNullOrEmpty(language))
{
url += string.Format("&language={0}", MovieDbProvider.NormalizeLanguage(language));
url += string.Format("&language={0}", TmdbMovieProvider.NormalizeLanguage(language));
}
var includeImageLanguageParam = MovieDbProvider.GetImageLanguagesParam(language);
var includeImageLanguageParam = TmdbMovieProvider.GetImageLanguagesParam(language);
// Get images in english and with no language
url += "&include_image_language=" + includeImageLanguageParam;
cancellationToken.ThrowIfCancellationRequested();
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbProvider.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
return await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(json).ConfigureAwait(false);
return await _jsonSerializer.DeserializeFromStreamAsync<SeasonResult>(json).ConfigureAwait(false);
}
}
}
public class Episode
{
public string air_date { get; set; }
public int episode_number { get; set; }
public int id { get; set; }
public string name { get; set; }
public string overview { get; set; }
public string still_path { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
}
public class Cast
{
public string character { get; set; }
public string credit_id { get; set; }
public int id { get; set; }
public string name { get; set; }
public string profile_path { get; set; }
public int order { get; set; }
}
public class Crew
{
public string credit_id { get; set; }
public string department { get; set; }
public int id { get; set; }
public string name { get; set; }
public string job { get; set; }
public string profile_path { get; set; }
}
public class Credits
{
public List<Cast> cast { get; set; }
public List<Crew> crew { get; set; }
}
public class Poster
{
public double aspect_ratio { get; set; }
public string file_path { get; set; }
public int height { get; set; }
public string id { get; set; }
public string iso_639_1 { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public int width { get; set; }
}
public class Images
{
public List<Poster> posters { get; set; }
}
public class ExternalIds
{
public string freebase_id { get; set; }
public string freebase_mid { get; set; }
public int tvdb_id { get; set; }
public object tvrage_id { get; set; }
}
public class Videos
{
public List<object> results { get; set; }
}
public class RootObject
{
public DateTime air_date { get; set; }
public List<Episode> episodes { get; set; }
public string name { get; set; }
public string overview { get; set; }
public int id { get; set; }
public string poster_path { get; set; }
public int season_number { get; set; }
public Credits credits { get; set; }
public Images images { get; set; }
public ExternalIds external_ids { get; set; }
public Videos videos { get; set; }
}
}
}

View File

@ -0,0 +1,24 @@
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Tmdb.TV
{
public class TmdbSeriesExternalId : IExternalId
{
/// <inheritdoc />
public string Name => TmdbUtils.ProviderName;
/// <inheritdoc />
public string Key => MetadataProviders.Tmdb.ToString();
/// <inheritdoc />
public string UrlFormatString => TmdbUtils.BaseTmdbUrl + "tv/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
}
}

View File

@ -13,16 +13,19 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.General;
using MediaBrowser.Providers.Tmdb.Models.TV;
using MediaBrowser.Providers.Tmdb.Movies;
namespace MediaBrowser.Providers.TV.TheMovieDb
namespace MediaBrowser.Providers.Tmdb.TV
{
public class MovieDbSeriesImageProvider : IRemoteImageProvider, IHasOrder
public class TmdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
{
private readonly IJsonSerializer _jsonSerializer;
private readonly IHttpClient _httpClient;
private readonly IFileSystem _fileSystem;
public MovieDbSeriesImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem)
public TmdbSeriesImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem)
{
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
@ -31,7 +34,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
public string Name => ProviderName;
public static string ProviderName => "TheMovieDb";
public static string ProviderName => TmdbUtils.ProviderName;
public bool Supports(BaseItem item)
{
@ -58,7 +61,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
return list;
}
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
@ -66,12 +69,12 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
Url = tmdbImageUrl + i.File_Path,
CommunityRating = i.Vote_Average,
VoteCount = i.Vote_Count,
Width = i.Width,
Height = i.Height,
Language = TmdbMovieProvider.AdjustImageLanguage(i.Iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score
@ -79,11 +82,11 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
list.AddRange(GetBackdrops(results).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Url = tmdbImageUrl + i.File_Path,
CommunityRating = i.Vote_Average,
VoteCount = i.Vote_Count,
Width = i.Width,
Height = i.Height,
ProviderName = Name,
Type = ImageType.Backdrop,
RatingType = RatingType.Score
@ -118,22 +121,21 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
/// Gets the posters.
/// </summary>
/// <param name="images">The images.</param>
private IEnumerable<MovieDbSeriesProvider.Poster> GetPosters(MovieDbSeriesProvider.Images images)
private IEnumerable<Poster> GetPosters(Images images)
{
return images.posters ?? new List<MovieDbSeriesProvider.Poster>();
return images.Posters ?? new List<Poster>();
}
/// <summary>
/// Gets the backdrops.
/// </summary>
/// <param name="images">The images.</param>
private IEnumerable<MovieDbSeriesProvider.Backdrop> GetBackdrops(MovieDbSeriesProvider.Images images)
private IEnumerable<Backdrop> GetBackdrops(Images images)
{
var eligibleBackdrops = images.backdrops == null ? new List<MovieDbSeriesProvider.Backdrop>() :
images.backdrops;
var eligibleBackdrops = images.Backdrops ?? new List<Backdrop>();
return eligibleBackdrops.OrderByDescending(i => i.vote_average)
.ThenByDescending(i => i.vote_count);
return eligibleBackdrops.OrderByDescending(i => i.Vote_Average)
.ThenByDescending(i => i.Vote_Count);
}
/// <summary>
@ -144,7 +146,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MovieImages}.</returns>
private async Task<MovieDbSeriesProvider.Images> FetchImages(BaseItem item, string language, IJsonSerializer jsonSerializer,
private async Task<Images> FetchImages(BaseItem item, string language, IJsonSerializer jsonSerializer,
CancellationToken cancellationToken)
{
var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);
@ -154,9 +156,9 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
return null;
}
await MovieDbSeriesProvider.Current.EnsureSeriesInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
await TmdbSeriesProvider.Current.EnsureSeriesInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
var path = MovieDbSeriesProvider.Current.GetDataFilePath(tmdbId, language);
var path = TmdbSeriesProvider.Current.GetDataFilePath(tmdbId, language);
if (!string.IsNullOrEmpty(path))
{
@ -164,7 +166,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbSeriesProvider.RootObject>(path).images;
return jsonSerializer.DeserializeFromFile<SeriesResult>(path).Images;
}
}

View File

@ -18,16 +18,19 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Models.Search;
using MediaBrowser.Providers.Tmdb.Models.TV;
using MediaBrowser.Providers.Tmdb.Movies;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.TV.TheMovieDb
namespace MediaBrowser.Providers.Tmdb.TV
{
public class MovieDbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
public class TmdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
{
private const string GetTvInfo3 = MovieDbProvider.BaseMovieDbUrl + @"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 MovieDbSeriesProvider Current { get; private set; }
internal static TmdbSeriesProvider Current { get; private set; }
private readonly IJsonSerializer _jsonSerializer;
private readonly IFileSystem _fileSystem;
@ -37,7 +40,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
private readonly IHttpClient _httpClient;
private readonly ILibraryManager _libraryManager;
public MovieDbSeriesProvider(IJsonSerializer jsonSerializer, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, IHttpClient httpClient, ILibraryManager libraryManager)
public TmdbSeriesProvider(IJsonSerializer jsonSerializer, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, IHttpClient httpClient, ILibraryManager libraryManager)
{
_jsonSerializer = jsonSerializer;
_fileSystem = fileSystem;
@ -49,7 +52,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
Current = this;
}
public string Name => "TheMovieDb";
public string Name => TmdbUtils.ProviderName;
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
{
@ -63,24 +66,24 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
var dataFilePath = GetDataFilePath(tmdbId, searchInfo.MetadataLanguage);
var obj = _jsonSerializer.DeserializeFromFile<RootObject>(dataFilePath);
var obj = _jsonSerializer.DeserializeFromFile<SeriesResult>(dataFilePath);
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
var remoteResult = new RemoteSearchResult
{
Name = obj.name,
Name = obj.Name,
SearchProviderName = Name,
ImageUrl = string.IsNullOrWhiteSpace(obj.poster_path) ? null : tmdbImageUrl + obj.poster_path
ImageUrl = string.IsNullOrWhiteSpace(obj.Poster_Path) ? null : tmdbImageUrl + obj.Poster_Path
};
remoteResult.SetProviderId(MetadataProviders.Tmdb, obj.id.ToString(_usCulture));
remoteResult.SetProviderId(MetadataProviders.Imdb, obj.external_ids.imdb_id);
remoteResult.SetProviderId(MetadataProviders.Tmdb, obj.Id.ToString(_usCulture));
remoteResult.SetProviderId(MetadataProviders.Imdb, obj.External_Ids.Imdb_Id);
if (obj.external_ids.tvdb_id > 0)
if (obj.External_Ids.Tvdb_Id > 0)
{
remoteResult.SetProviderId(MetadataProviders.Tvdb, obj.external_ids.tvdb_id.ToString(_usCulture));
remoteResult.SetProviderId(MetadataProviders.Tvdb, obj.External_Ids.Tvdb_Id.ToString(_usCulture));
}
return new[] { remoteResult };
@ -110,7 +113,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
}
}
return await new MovieDbSearch(_logger, _jsonSerializer, _libraryManager).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
return await new TmdbSearch(_logger, _jsonSerializer, _libraryManager).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
}
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
@ -153,7 +156,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
if (string.IsNullOrEmpty(tmdbId))
{
result.QueriedById = false;
var searchResults = await new MovieDbSearch(_logger, _jsonSerializer, _libraryManager).GetSearchResults(info, cancellationToken).ConfigureAwait(false);
var searchResults = await new TmdbSearch(_logger, _jsonSerializer, _libraryManager).GetSearchResults(info, cancellationToken).ConfigureAwait(false);
var searchResult = searchResults.FirstOrDefault();
@ -177,14 +180,14 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
private async Task<MetadataResult<Series>> FetchMovieData(string tmdbId, string language, string preferredCountryCode, CancellationToken cancellationToken)
{
RootObject seriesInfo = await FetchMainResult(tmdbId, language, cancellationToken).ConfigureAwait(false);
SeriesResult seriesInfo = await FetchMainResult(tmdbId, language, cancellationToken).ConfigureAwait(false);
if (seriesInfo == null)
{
return null;
}
tmdbId = seriesInfo.id.ToString(_usCulture);
tmdbId = seriesInfo.Id.ToString(_usCulture);
string dataFilePath = GetDataFilePath(tmdbId, language);
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
@ -196,102 +199,102 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
result.Item = new Series();
result.ResultLanguage = seriesInfo.ResultLanguage;
var settings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var settings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
ProcessMainInfo(result, seriesInfo, preferredCountryCode, settings);
return result;
}
private void ProcessMainInfo(MetadataResult<Series> seriesResult, RootObject seriesInfo, string preferredCountryCode, TmdbSettingsResult settings)
private void ProcessMainInfo(MetadataResult<Series> seriesResult, SeriesResult seriesInfo, string preferredCountryCode, TmdbSettingsResult settings)
{
var series = seriesResult.Item;
series.Name = seriesInfo.name;
series.SetProviderId(MetadataProviders.Tmdb, seriesInfo.id.ToString(_usCulture));
series.Name = seriesInfo.Name;
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))
{
series.CommunityRating = rating;
}
series.Overview = seriesInfo.overview;
series.Overview = seriesInfo.Overview;
if (seriesInfo.networks != null)
if (seriesInfo.Networks != null)
{
series.Studios = seriesInfo.networks.Select(i => i.name).ToArray();
series.Studios = seriesInfo.Networks.Select(i => i.Name).ToArray();
}
if (seriesInfo.genres != null)
if (seriesInfo.Genres != null)
{
series.Genres = seriesInfo.genres.Select(i => i.name).ToArray();
series.Genres = seriesInfo.Genres.Select(i => i.Name).ToArray();
}
//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();
if (string.Equals(seriesInfo.status, "Ended", StringComparison.OrdinalIgnoreCase))
if (string.Equals(seriesInfo.Status, "Ended", StringComparison.OrdinalIgnoreCase))
{
series.Status = SeriesStatus.Ended;
series.EndDate = seriesInfo.last_air_date;
series.EndDate = seriesInfo.Last_Air_Date;
}
else
{
series.Status = SeriesStatus.Continuing;
}
series.PremiereDate = seriesInfo.first_air_date;
series.PremiereDate = seriesInfo.First_Air_Date;
var ids = seriesInfo.external_ids;
var ids = seriesInfo.External_Ids;
if (ids != null)
{
if (!string.IsNullOrWhiteSpace(ids.imdb_id))
if (!string.IsNullOrWhiteSpace(ids.Imdb_Id))
{
series.SetProviderId(MetadataProviders.Imdb, ids.imdb_id);
series.SetProviderId(MetadataProviders.Imdb, ids.Imdb_Id);
}
if (ids.tvrage_id > 0)
if (ids.Tvrage_Id > 0)
{
series.SetProviderId(MetadataProviders.TvRage, ids.tvrage_id.ToString(_usCulture));
series.SetProviderId(MetadataProviders.TvRage, ids.Tvrage_Id.ToString(_usCulture));
}
if (ids.tvdb_id > 0)
if (ids.Tvdb_Id > 0)
{
series.SetProviderId(MetadataProviders.Tvdb, ids.tvdb_id.ToString(_usCulture));
series.SetProviderId(MetadataProviders.Tvdb, ids.Tvdb_Id.ToString(_usCulture));
}
}
var contentRatings = (seriesInfo.content_ratings ?? new ContentRatings()).results ?? new List<ContentRating>();
var contentRatings = (seriesInfo.Content_Ratings ?? new ContentRatings()).Results ?? new List<ContentRating>();
var ourRelease = contentRatings.FirstOrDefault(c => string.Equals(c.iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
var usRelease = contentRatings.FirstOrDefault(c => string.Equals(c.iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));
var ourRelease = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
var usRelease = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));
var minimumRelease = contentRatings.FirstOrDefault();
if (ourRelease != null)
{
series.OfficialRating = ourRelease.rating;
series.OfficialRating = ourRelease.Rating;
}
else if (usRelease != null)
{
series.OfficialRating = usRelease.rating;
series.OfficialRating = usRelease.Rating;
}
else if (minimumRelease != null)
{
series.OfficialRating = minimumRelease.rating;
series.OfficialRating = minimumRelease.Rating;
}
if (seriesInfo.videos != null && seriesInfo.videos.results != null)
if (seriesInfo.Videos != null && seriesInfo.Videos.Results != null)
{
foreach (var video in seriesInfo.videos.results)
foreach (var video in seriesInfo.Videos.Results)
{
if ((video.type.Equals("trailer", StringComparison.OrdinalIgnoreCase)
|| video.type.Equals("clip", StringComparison.OrdinalIgnoreCase))
&& video.site.Equals("youtube", StringComparison.OrdinalIgnoreCase))
if ((video.Type.Equals("trailer", StringComparison.OrdinalIgnoreCase)
|| video.Type.Equals("clip", StringComparison.OrdinalIgnoreCase))
&& video.Site.Equals("youtube", StringComparison.OrdinalIgnoreCase))
{
series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.key}");
series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.Key}");
}
}
}
@ -299,26 +302,26 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
seriesResult.ResetPeople();
var tmdbImageUrl = settings.images.GetImageUrl("original");
if (seriesInfo.credits != null && seriesInfo.credits.cast != null)
if (seriesInfo.Credits != null && seriesInfo.Credits.Cast != null)
{
foreach (var actor in seriesInfo.credits.cast.OrderBy(a => a.order))
foreach (var actor in seriesInfo.Credits.Cast.OrderBy(a => a.Order))
{
var personInfo = new PersonInfo
{
Name = actor.name.Trim(),
Role = actor.character,
Name = actor.Name.Trim(),
Role = actor.Character,
Type = PersonType.Actor,
SortOrder = actor.order
SortOrder = actor.Order
};
if (!string.IsNullOrWhiteSpace(actor.profile_path))
if (!string.IsNullOrWhiteSpace(actor.Profile_Path))
{
personInfo.ImageUrl = tmdbImageUrl + actor.profile_path;
personInfo.ImageUrl = tmdbImageUrl + actor.Profile_Path;
}
if (actor.id > 0)
if (actor.Id > 0)
{
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.id.ToString(CultureInfo.InvariantCulture));
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture));
}
seriesResult.AddPerson(personInfo);
@ -342,7 +345,7 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
internal async Task DownloadSeriesInfo(string id, string preferredMetadataLanguage, CancellationToken cancellationToken)
{
RootObject mainResult = await FetchMainResult(id, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
SeriesResult mainResult = await FetchMainResult(id, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
if (mainResult == null)
{
@ -356,31 +359,31 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
}
internal async Task<RootObject> FetchMainResult(string id, string language, CancellationToken cancellationToken)
internal async Task<SeriesResult> FetchMainResult(string id, string language, CancellationToken cancellationToken)
{
var url = string.Format(GetTvInfo3, id, MovieDbProvider.ApiKey);
var url = string.Format(GetTvInfo3, id, TmdbUtils.ApiKey);
if (!string.IsNullOrEmpty(language))
{
url += "&language=" + MovieDbProvider.NormalizeLanguage(language)
+ "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language); // Get images in english and with no language
url += "&language=" + TmdbMovieProvider.NormalizeLanguage(language)
+ "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language); // Get images in english and with no language
}
cancellationToken.ThrowIfCancellationRequested();
RootObject mainResult;
SeriesResult mainResult;
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbProvider.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
mainResult = await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(json).ConfigureAwait(false);
mainResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(json).ConfigureAwait(false);
if (!string.IsNullOrEmpty(language))
{
@ -393,33 +396,33 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
// If the language preference isn't english, then have the overview fallback to english if it's blank
if (mainResult != null &&
string.IsNullOrEmpty(mainResult.overview) &&
string.IsNullOrEmpty(mainResult.Overview) &&
!string.IsNullOrEmpty(language) &&
!string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
{
_logger.LogInformation("MovieDbSeriesProvider couldn't find meta for language {Language}. Trying English...", language);
url = string.Format(GetTvInfo3, id, MovieDbProvider.ApiKey) + "&language=en";
url = string.Format(GetTvInfo3, id, TmdbUtils.ApiKey) + "&language=en";
if (!string.IsNullOrEmpty(language))
{
// Get images in english and with no language
url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language);
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
}
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbProvider.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<RootObject>(json).ConfigureAwait(false);
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(json).ConfigureAwait(false);
mainResult.overview = englishResult.overview;
mainResult.Overview = englishResult.Overview;
mainResult.ResultLanguage = "en";
}
}
@ -467,40 +470,40 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
private async Task<RemoteSearchResult> FindByExternalId(string id, string externalSource, CancellationToken cancellationToken)
{
var url = string.Format(MovieDbProvider.BaseMovieDbUrl + @"3/find/{0}?api_key={1}&external_source={2}",
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/find/{0}?api_key={1}&external_source={2}",
id,
MovieDbProvider.ApiKey,
TmdbUtils.ApiKey,
externalSource);
using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = MovieDbProvider.AcceptHeader
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
using (var json = response.Content)
{
var result = await _jsonSerializer.DeserializeFromStreamAsync<MovieDbSearch.ExternalIdLookupResult>(json).ConfigureAwait(false);
var result = await _jsonSerializer.DeserializeFromStreamAsync<ExternalIdLookupResult>(json).ConfigureAwait(false);
if (result != null && result.tv_results != null)
if (result != null && result.Tv_Results != null)
{
var tv = result.tv_results.FirstOrDefault();
var tv = result.Tv_Results.FirstOrDefault();
if (tv != null)
{
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
var remoteResult = new RemoteSearchResult
{
Name = tv.name,
Name = tv.Name,
SearchProviderName = Name,
ImageUrl = string.IsNullOrWhiteSpace(tv.poster_path) ? null : tmdbImageUrl + tv.poster_path
ImageUrl = string.IsNullOrWhiteSpace(tv.Poster_Path) ? null : tmdbImageUrl + tv.Poster_Path
};
remoteResult.SetProviderId(MetadataProviders.Tmdb, tv.id.ToString(_usCulture));
remoteResult.SetProviderId(MetadataProviders.Tmdb, tv.Id.ToString(_usCulture));
return remoteResult;
}
@ -511,163 +514,6 @@ namespace MediaBrowser.Providers.TV.TheMovieDb
return null;
}
public class CreatedBy
{
public int id { get; set; }
public string name { get; set; }
public string profile_path { get; set; }
}
public class Genre
{
public int id { get; set; }
public string name { get; set; }
}
public class Network
{
public int id { get; set; }
public string name { get; set; }
}
public class Season
{
public string air_date { get; set; }
public int episode_count { get; set; }
public int id { get; set; }
public string poster_path { get; set; }
public int season_number { get; set; }
}
public class Cast
{
public string character { get; set; }
public string credit_id { get; set; }
public int id { get; set; }
public string name { get; set; }
public string profile_path { get; set; }
public int order { get; set; }
}
public class Crew
{
public string credit_id { get; set; }
public string department { get; set; }
public int id { get; set; }
public string name { get; set; }
public string job { get; set; }
public string profile_path { get; set; }
}
public class Credits
{
public List<Cast> cast { get; set; }
public List<Crew> crew { get; set; }
}
public class Backdrop
{
public double aspect_ratio { get; set; }
public string file_path { get; set; }
public int height { get; set; }
public string iso_639_1 { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public int width { get; set; }
}
public class Poster
{
public double aspect_ratio { get; set; }
public string file_path { get; set; }
public int height { get; set; }
public string iso_639_1 { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public int width { get; set; }
}
public class Images
{
public List<Backdrop> backdrops { get; set; }
public List<Poster> posters { get; set; }
}
public class Keywords
{
public List<object> results { get; set; }
}
public class ExternalIds
{
public string imdb_id { get; set; }
public string freebase_id { get; set; }
public string freebase_mid { get; set; }
public int tvdb_id { get; set; }
public int tvrage_id { get; set; }
}
public class Videos
{
public List<Video> results { get; set; }
}
public class Video
{
public string id { get; set; }
public string iso_639_1 { get; set; }
public string iso_3166_1 { get; set; }
public string key { get; set; }
public string name { get; set; }
public string site { get; set; }
public string size { get; set; }
public string type { get; set; }
}
public class ContentRating
{
public string iso_3166_1 { get; set; }
public string rating { get; set; }
}
public class ContentRatings
{
public List<ContentRating> results { get; set; }
}
public class RootObject
{
public string backdrop_path { get; set; }
public List<CreatedBy> created_by { get; set; }
public List<int> episode_run_time { get; set; }
public DateTime first_air_date { get; set; }
public List<Genre> genres { get; set; }
public string homepage { get; set; }
public int id { get; set; }
public bool in_production { get; set; }
public List<string> languages { get; set; }
public DateTime last_air_date { get; set; }
public string name { get; set; }
public List<Network> networks { get; set; }
public int number_of_episodes { get; set; }
public int number_of_seasons { get; set; }
public string original_name { get; set; }
public List<string> origin_country { get; set; }
public string overview { get; set; }
public string popularity { get; set; }
public string poster_path { get; set; }
public List<Season> seasons { get; set; }
public string status { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
public Credits credits { get; set; }
public Images images { get; set; }
public Keywords keywords { get; set; }
public ExternalIds external_ids { get; set; }
public Videos videos { get; set; }
public ContentRatings content_ratings { get; set; }
public string ResultLanguage { get; set; }
}
// After TheTVDB
public int Order => 1;

View File

@ -0,0 +1,31 @@
using System;
using MediaBrowser.Model.Entities;
using MediaBrowser.Providers.Tmdb.Models.General;
namespace MediaBrowser.Providers.Tmdb
{
public static class TmdbUtils
{
public const string BaseTmdbUrl = "https://www.themoviedb.org/";
public const string BaseTmdbApiUrl = "https://api.themoviedb.org/";
public const string ProviderName = "TheMovieDb";
public const string ApiKey = "4219e299c89411838049ab0dab19ebd5";
public const string AcceptHeader = "application/json,image/*";
public static string MapCrewToPersonType(Crew crew)
{
if (crew.Department.Equals("production", StringComparison.InvariantCultureIgnoreCase)
&& crew.Job.IndexOf("producer", StringComparison.InvariantCultureIgnoreCase) != -1)
{
return PersonType.Producer;
}
if (crew.Department.Equals("writing", StringComparison.InvariantCultureIgnoreCase))
{
return PersonType.Writer;
}
return null;
}
}
}

View File

@ -5,29 +5,31 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Providers;
using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.Tmdb.Movies;
namespace MediaBrowser.Providers.Movies
namespace MediaBrowser.Providers.Tmdb.Trailers
{
public class MovieDbTrailerProvider : IHasOrder, IRemoteMetadataProvider<Trailer, TrailerInfo>
public class TmdbTrailerProvider : IHasOrder, IRemoteMetadataProvider<Trailer, TrailerInfo>
{
private readonly IHttpClient _httpClient;
public MovieDbTrailerProvider(IHttpClient httpClient)
public TmdbTrailerProvider(IHttpClient httpClient)
{
_httpClient = httpClient;
}
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken)
{
return MovieDbProvider.Current.GetMovieSearchResults(searchInfo, cancellationToken);
return TmdbMovieProvider.Current.GetMovieSearchResults(searchInfo, cancellationToken);
}
public Task<MetadataResult<Trailer>> GetMetadata(TrailerInfo info, CancellationToken cancellationToken)
{
return MovieDbProvider.Current.GetItemMetadata<Trailer>(info, cancellationToken);
return TmdbMovieProvider.Current.GetItemMetadata<Trailer>(info, cancellationToken);
}
public string Name => MovieDbProvider.Current.Name;
public string Name => TmdbMovieProvider.Current.Name;
public int Order => 0;