Implementing collection search

This commit is contained in:
Zoe Roux 2021-07-26 00:06:19 +02:00
parent 17103548c5
commit 3262343c4a
2 changed files with 33 additions and 0 deletions

View File

@ -104,6 +104,23 @@ namespace Kyoo.TheMovieDb
};
}
/// <summary>
/// Convert a <see cref="SearchCollection"/> into a <see cref="Collection"/>.
/// </summary>
/// <param name="collection">The collection to convert.</param>
/// <param name="provider">The provider representing TheMovieDb.</param>
/// <returns>The converted collection as a <see cref="Collection"/>.</returns>
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}"
};
}
/// <summary>
/// Convert a <see cref="SearchMovie"/> into a <see cref="Show"/>.
/// </summary>

View File

@ -81,11 +81,27 @@ namespace Kyoo.TheMovieDb
public async Task<ICollection<T>> Search<T>(string query)
where T : class, IResource
{
if (typeof(T) == typeof(Collection))
return (await _SearchCollections(query) as ICollection<T>)!;
if (typeof(T) == typeof(Show))
return (await _SearchShows(query) as ICollection<T>)!;
return ArraySegment<T>.Empty;
}
/// <summary>
/// Search for a collection using it's name as a query.
/// </summary>
/// <param name="query">The query to search for</param>
/// <returns>A collection containing metadata from TheMovieDb</returns>
private async Task<ICollection<Collection>> _SearchCollections(string query)
{
TMDbClient client = new(_apiKey.Value.ApiKey);
return (await client.SearchCollectionAsync(query))
.Results
.Select(x => x.ToCollection(Provider))
.ToArray();
}
/// <summary>
/// Search for a show using it's name as a query.
/// </summary>