diff --git a/Kyoo.Common/Models/Resources/Episode.cs b/Kyoo.Common/Models/Resources/Episode.cs
index ad2b79bb..990ce5b6 100644
--- a/Kyoo.Common/Models/Resources/Episode.cs
+++ b/Kyoo.Common/Models/Resources/Episode.cs
@@ -85,7 +85,7 @@ namespace Kyoo.Models
public int? SeasonNumber { get; set; }
///
- /// The number of this episode is it's season.
+ /// The number of this episode in it's season.
///
public int? EpisodeNumber { get; set; }
diff --git a/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs b/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs
index 01a119fb..27460cf0 100644
--- a/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs
+++ b/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Kyoo.Models;
using TMDbLib.Objects.General;
+using TMDbLib.Objects.People;
using TMDbLib.Objects.Search;
using TvCast = TMDbLib.Objects.TvShows.Cast;
using MovieCast = TMDbLib.Objects.Movies.Cast;
@@ -117,6 +118,36 @@ namespace Kyoo.TheMovieDb
};
}
+ ///
+ /// Convert a to a .
+ ///
+ /// An internal TheMovieDB person.
+ /// The provider that represent TheMovieDB inside Kyoo.
+ /// A representing the person.
+ public static People ToPeople(this Person person, Provider provider)
+ {
+ return new()
+ {
+ Slug = Utility.ToSlug(person.Name),
+ Name = person.Name,
+ Images = new Dictionary
+ {
+ [Thumbnails.Poster] = person.ProfilePath != null
+ ? $"https://image.tmdb.org/t/p/original{person.ProfilePath}"
+ : null
+ },
+ ExternalIDs = new[]
+ {
+ new MetadataID
+ {
+ Provider = provider,
+ DataID = person.Id.ToString(),
+ Link = $"https://www.themoviedb.org/person/{person.Id}"
+ }
+ }
+ };
+ }
+
///
/// Convert a to a .
///
diff --git a/Kyoo.TheMovieDb/Convertors/StudioConvertors.cs b/Kyoo.TheMovieDb/Convertors/StudioConvertors.cs
new file mode 100644
index 00000000..c8947981
--- /dev/null
+++ b/Kyoo.TheMovieDb/Convertors/StudioConvertors.cs
@@ -0,0 +1,60 @@
+using Kyoo.Models;
+using TMDbLib.Objects.Companies;
+using TMDbLib.Objects.Search;
+
+namespace Kyoo.TheMovieDb
+{
+ ///
+ /// A class containing extensions methods to convert from TMDB's types to Kyoo's types.
+ ///
+ public static partial class Convertors
+ {
+ ///
+ /// Convert a into a .
+ ///
+ /// The company to convert.
+ /// The provider representing TheMovieDb.
+ /// The converted company as a .
+ public static Studio ToStudio(this Company company, Provider provider)
+ {
+ return new()
+ {
+ Slug = Utility.ToSlug(company.Name),
+ Name = company.Name,
+ ExternalIDs = new []
+ {
+ new MetadataID
+ {
+ Provider = provider,
+ Link = $"https://www.themoviedb.org/company/{company.Id}",
+ DataID = company.Id.ToString()
+ }
+ }
+ };
+ }
+
+ ///
+ /// Convert a into a .
+ ///
+ /// The company to convert.
+ /// The provider representing TheMovieDb.
+ /// The converted company as a .
+ public static Studio ToStudio(this SearchCompany company, Provider provider)
+ {
+ return new()
+ {
+ Slug = Utility.ToSlug(company.Name),
+ Name = company.Name,
+ ExternalIDs = new[]
+ {
+ new MetadataID
+ {
+ Provider = provider,
+ Link = $"https://www.themoviedb.org/company/{company.Id}",
+ DataID = company.Id.ToString()
+ }
+ }
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/Kyoo.TheMovieDb/ProviderTmdb.cs b/Kyoo.TheMovieDb/ProviderTmdb.cs
index 3be0793b..f47b2ef8 100644
--- a/Kyoo.TheMovieDb/ProviderTmdb.cs
+++ b/Kyoo.TheMovieDb/ProviderTmdb.cs
@@ -63,6 +63,8 @@ namespace Kyoo.TheMovieDb
Show show => _GetShow(show) as Task,
Season season => _GetSeason(season) as Task,
Episode episode => _GetEpisode(episode) as Task,
+ People person => _GetPerson(person) as Task,
+ Studio studio => _GetStudio(studio) as Task,
_ => null
};
}
@@ -70,7 +72,7 @@ namespace Kyoo.TheMovieDb
///
/// Get a collection using it's id, if the id is not present in the collection, fallback to a name search.
///
- /// The show to collection for
+ /// The collection to search for
/// A collection containing metadata from TheMovieDb
private async Task _GetCollection(Collection collection)
{
@@ -153,6 +155,42 @@ namespace Kyoo.TheMovieDb
.ToEpisode(id, Provider);
}
+ ///
+ /// Get a person using it's id, if the id is not present in the person, fallback to a name search.
+ ///
+ /// The person to search for
+ /// A person containing metadata from TheMovieDb
+ private async Task _GetPerson(People person)
+ {
+ if (!person.TryGetID(Provider.Slug, out int id))
+ {
+ People found = (await _SearchPeople(person.Name ?? person.Slug)).FirstOrDefault();
+ if (found?.TryGetID(Provider.Slug, out id) != true)
+ return found;
+ }
+
+ TMDbClient client = new(_apiKey.Value.ApiKey);
+ return (await client.GetPersonAsync(id)).ToPeople(Provider);
+ }
+
+ ///
+ /// Get a studio using it's id, if the id is not present in the studio, fallback to a name search.
+ ///
+ /// The studio to search for
+ /// A studio containing metadata from TheMovieDb
+ private async Task _GetStudio(Studio studio)
+ {
+ if (!studio.TryGetID(Provider.Slug, out int id))
+ {
+ Studio found = (await _SearchStudios(studio.Name ?? studio.Slug)).FirstOrDefault();
+ if (found?.TryGetID(Provider.Slug, out id) != true)
+ return found;
+ }
+
+ TMDbClient client = new(_apiKey.Value.ApiKey);
+ return (await client.GetCompanyAsync(id)).ToStudio(Provider);
+ }
+
///
public async Task> Search(string query)
where T : class, IResource
@@ -163,8 +201,8 @@ namespace Kyoo.TheMovieDb
return (await _SearchShows(query) as ICollection)!;
if (typeof(T) == typeof(People))
return (await _SearchPeople(query) as ICollection)!;
- // if (typeof(T) == typeof(Studio))
- // return (await _SearchStudios(query) as ICollection)!;
+ if (typeof(T) == typeof(Studio))
+ return (await _SearchStudios(query) as ICollection)!;
return ArraySegment.Empty;
}
@@ -218,5 +256,19 @@ namespace Kyoo.TheMovieDb
.Select(x => x.ToPeople(Provider))
.ToArray();
}
+
+ ///
+ /// Search for studios using there name as a query.
+ ///
+ /// The query to search for
+ /// A list of studios containing metadata from TheMovieDb
+ private async Task> _SearchStudios(string query)
+ {
+ TMDbClient client = new(_apiKey.Value.ApiKey);
+ return (await client.SearchCompanyAsync(query))
+ .Results
+ .Select(x => x.ToStudio(Provider))
+ .ToArray();
+ }
}
}
\ No newline at end of file