diff --git a/Kyoo.TheMovieDb/Convertors.cs b/Kyoo.TheMovieDb/Convertors.cs index 02497549..cb5b4412 100644 --- a/Kyoo.TheMovieDb/Convertors.cs +++ b/Kyoo.TheMovieDb/Convertors.cs @@ -103,6 +103,23 @@ namespace Kyoo.TheMovieDb } }; } + + + /// + /// Convert a into a . + /// + /// The collection to convert. + /// The provider representing TheMovieDb. + /// The converted collection as a . + public static Collection ToCollection(this SearchCollection collection, Provider provider) + { + return new() + { + Slug = Utility.ToSlug(collection.Name), + Name = collection.Name, + Poster = $"https://image.tmdb.org/t/p/original{collection.PosterPath}" + }; + } /// /// Convert a into a . diff --git a/Kyoo.TheMovieDb/ProviderTmdb.cs b/Kyoo.TheMovieDb/ProviderTmdb.cs index aedfeea6..b613e5f3 100644 --- a/Kyoo.TheMovieDb/ProviderTmdb.cs +++ b/Kyoo.TheMovieDb/ProviderTmdb.cs @@ -81,11 +81,27 @@ namespace Kyoo.TheMovieDb public async Task> Search(string query) where T : class, IResource { + if (typeof(T) == typeof(Collection)) + return (await _SearchCollections(query) as ICollection)!; if (typeof(T) == typeof(Show)) return (await _SearchShows(query) as ICollection)!; return ArraySegment.Empty; } + /// + /// Search for a collection using it's name as a query. + /// + /// The query to search for + /// A collection containing metadata from TheMovieDb + private async Task> _SearchCollections(string query) + { + TMDbClient client = new(_apiKey.Value.ApiKey); + return (await client.SearchCollectionAsync(query)) + .Results + .Select(x => x.ToCollection(Provider)) + .ToArray(); + } + /// /// Search for a show using it's name as a query. ///