mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
MovieDB: Implementing person search
This commit is contained in:
parent
8152787f47
commit
a4933e0a27
@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Kyoo.Models;
|
||||
using TMDbLib.Objects.General;
|
||||
using TMDbLib.Objects.Search;
|
||||
using TvCast = TMDbLib.Objects.TvShows.Cast;
|
||||
using MovieCast = TMDbLib.Objects.Movies.Cast;
|
||||
|
||||
@ -115,5 +116,35 @@ namespace Kyoo.TheMovieDb
|
||||
Role = crew.Job
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a <see cref="SearchPerson"/> to a <see cref="People"/>.
|
||||
/// </summary>
|
||||
/// <param name="person">An internal TheMovieDB person.</param>
|
||||
/// <param name="provider">The provider that represent TheMovieDB inside Kyoo.</param>
|
||||
/// <returns>A <see cref="People"/> representing the person.</returns>
|
||||
public static People ToPeople(this SearchPerson person, Provider provider)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Slug = Utility.ToSlug(person.Name),
|
||||
Name = person.Name,
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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}"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -161,8 +161,8 @@ namespace Kyoo.TheMovieDb
|
||||
return (await _SearchCollections(query) as ICollection<T>)!;
|
||||
if (typeof(T) == typeof(Show))
|
||||
return (await _SearchShows(query) as ICollection<T>)!;
|
||||
// if (typeof(T) == typeof(People))
|
||||
// return (await _SearchPeople(query) as ICollection<T>)!;
|
||||
if (typeof(T) == typeof(People))
|
||||
return (await _SearchPeople(query) as ICollection<T>)!;
|
||||
// if (typeof(T) == typeof(Studio))
|
||||
// return (await _SearchStudios(query) as ICollection<T>)!;
|
||||
return ArraySegment<T>.Empty;
|
||||
@ -204,5 +204,19 @@ namespace Kyoo.TheMovieDb
|
||||
.Where(x => x != null)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search for people using there name as a query.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to search for</param>
|
||||
/// <returns>A list of people containing metadata from TheMovieDb</returns>
|
||||
private async Task<ICollection<People>> _SearchPeople(string query)
|
||||
{
|
||||
TMDbClient client = new(_apiKey.Value.ApiKey);
|
||||
return (await client.SearchPersonAsync(query))
|
||||
.Results
|
||||
.Select(x => x.ToPeople(Provider))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user