mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Implementing collection search
This commit is contained in:
parent
17103548c5
commit
3262343c4a
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user