mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-13 00:32:57 -07:00
!wip added a search by actor methodin the Movie Search Engine
This commit is contained in:
parent
3e4b2a8e9f
commit
ff73e78e2c
6 changed files with 136 additions and 2 deletions
|
@ -19,5 +19,6 @@ namespace Ombi.Core
|
||||||
Task<SearchMovieViewModel> LookupImdbInformation(int theMovieDbId, string langCode = null);
|
Task<SearchMovieViewModel> LookupImdbInformation(int theMovieDbId, string langCode = null);
|
||||||
|
|
||||||
Task<IEnumerable<SearchMovieViewModel>> SimilarMovies(int theMovieDbId, string langCode);
|
Task<IEnumerable<SearchMovieViewModel>> SimilarMovies(int theMovieDbId, string langCode);
|
||||||
|
Task<IEnumerable<SearchMovieViewModel>> SearchActor(string search, string langaugeCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -54,8 +54,6 @@ namespace Ombi.Core.Engine
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Searches the specified movie.
|
/// Searches the specified movie.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="search">The search.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<IEnumerable<SearchMovieViewModel>> Search(string search, int? year, string langaugeCode)
|
public async Task<IEnumerable<SearchMovieViewModel>> Search(string search, int? year, string langaugeCode)
|
||||||
{
|
{
|
||||||
langaugeCode = await DefaultLanguageCode(langaugeCode);
|
langaugeCode = await DefaultLanguageCode(langaugeCode);
|
||||||
|
@ -68,6 +66,33 @@ namespace Ombi.Core.Engine
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<SearchMovieViewModel>> SearchActor(string search, string langaugeCode)
|
||||||
|
{
|
||||||
|
langaugeCode = await DefaultLanguageCode(langaugeCode);
|
||||||
|
var people = await MovieApi.SearchByActor(search, langaugeCode);
|
||||||
|
var person = people?.results?.Count > 0 ? people.results.FirstOrDefault() : null;
|
||||||
|
|
||||||
|
var resultSet = new List<SearchMovieViewModel>();
|
||||||
|
if (person == null)
|
||||||
|
{
|
||||||
|
return resultSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get this person movie credits
|
||||||
|
var credits = await MovieApi.GetActorMovieCredits(person.id, langaugeCode);
|
||||||
|
// Grab results from both cast and crew, prefer items in cast. we can handle directors like this.
|
||||||
|
var movieResults = (from role in credits.cast select new { Id = role.id, Title = role.title, ReleaseDate = role.release_date }).ToList();
|
||||||
|
movieResults.AddRange((from job in credits.crew select new { Id = job.id, Title = job.title, ReleaseDate = job.release_date }).ToList());
|
||||||
|
|
||||||
|
movieResults = movieResults.Take(10).ToList();
|
||||||
|
foreach (var movieResult in movieResults)
|
||||||
|
{
|
||||||
|
resultSet.Add(await LookupImdbInformation(movieResult.Id, langaugeCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultSet;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get similar movies to the id passed in
|
/// Get similar movies to the id passed in
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -19,5 +19,7 @@ namespace Ombi.Api.TheMovieDb
|
||||||
Task<FindResult> Find(string externalId, ExternalSource source);
|
Task<FindResult> Find(string externalId, ExternalSource source);
|
||||||
Task<TvExternals> GetTvExternals(int theMovieDbId);
|
Task<TvExternals> GetTvExternals(int theMovieDbId);
|
||||||
Task<TvInfo> GetTVInfo(string themoviedbid);
|
Task<TvInfo> GetTVInfo(string themoviedbid);
|
||||||
|
Task<TheMovieDbContainer<ActorResult>> SearchByActor(string searchTerm, string langCode);
|
||||||
|
Task<ActorCredits> GetActorMovieCredits(int actorId, string langCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
51
src/Ombi.TheMovieDbApi/Models/ActorCredits.cs
Normal file
51
src/Ombi.TheMovieDbApi/Models/ActorCredits.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
namespace Ombi.Api.TheMovieDb.Models
|
||||||
|
{
|
||||||
|
public class ActorCredits
|
||||||
|
{
|
||||||
|
public Cast[] cast { get; set; }
|
||||||
|
public Crew[] crew { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Cast
|
||||||
|
{
|
||||||
|
public string character { get; set; }
|
||||||
|
public string credit_id { get; set; }
|
||||||
|
public string poster_path { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
public bool video { get; set; }
|
||||||
|
public int vote_count { get; set; }
|
||||||
|
public bool adult { get; set; }
|
||||||
|
public string backdrop_path { get; set; }
|
||||||
|
public int?[] genre_ids { get; set; }
|
||||||
|
public string original_language { get; set; }
|
||||||
|
public string original_title { get; set; }
|
||||||
|
public float popularity { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public float vote_average { get; set; }
|
||||||
|
public string overview { get; set; }
|
||||||
|
public string release_date { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Crew
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public string department { get; set; }
|
||||||
|
public string original_language { get; set; }
|
||||||
|
public string original_title { get; set; }
|
||||||
|
public string job { get; set; }
|
||||||
|
public string overview { get; set; }
|
||||||
|
public int vote_count { get; set; }
|
||||||
|
public bool video { get; set; }
|
||||||
|
public string release_date { get; set; }
|
||||||
|
public float vote_average { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public float popularity { get; set; }
|
||||||
|
public int?[] genre_ids { get; set; }
|
||||||
|
public string backdrop_path { get; set; }
|
||||||
|
public bool adult { get; set; }
|
||||||
|
public string poster_path { get; set; }
|
||||||
|
public string credit_id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
src/Ombi.TheMovieDbApi/Models/ActorSearchResult.cs
Normal file
33
src/Ombi.TheMovieDbApi/Models/ActorSearchResult.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
namespace Ombi.Api.TheMovieDb.Models
|
||||||
|
{
|
||||||
|
|
||||||
|
public class ActorResult
|
||||||
|
{
|
||||||
|
public float popularity { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
public string profile_path { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public Known_For[] known_for { get; set; }
|
||||||
|
public bool adult { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Known_For
|
||||||
|
{
|
||||||
|
public float vote_average { get; set; }
|
||||||
|
public int vote_count { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
public bool video { get; set; }
|
||||||
|
public string media_type { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public float popularity { get; set; }
|
||||||
|
public string poster_path { get; set; }
|
||||||
|
public string original_language { get; set; }
|
||||||
|
public string original_title { get; set; }
|
||||||
|
public int[] genre_ids { get; set; }
|
||||||
|
public string backdrop_path { get; set; }
|
||||||
|
public bool adult { get; set; }
|
||||||
|
public string overview { get; set; }
|
||||||
|
public string release_date { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -43,6 +43,28 @@ namespace Ombi.Api.TheMovieDb
|
||||||
return await Api.Request<FindResult>(request);
|
return await Api.Request<FindResult>(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<TheMovieDbContainer<ActorResult>> SearchByActor(string searchTerm, string langCode)
|
||||||
|
{
|
||||||
|
var request = new Request($"search/person", BaseUri, HttpMethod.Get);
|
||||||
|
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
|
||||||
|
request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm);
|
||||||
|
request.FullUri = request.FullUri.AddQueryParameter("language", langCode);
|
||||||
|
|
||||||
|
var result = await Api.Request<TheMovieDbContainer<ActorResult>>(request);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ActorCredits> GetActorMovieCredits(int actorId, string langCode)
|
||||||
|
{
|
||||||
|
var request = new Request($"search/person", BaseUri, HttpMethod.Get);
|
||||||
|
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
|
||||||
|
request.FullUri = request.FullUri.AddQueryParameter("person_id", actorId.ToString());
|
||||||
|
request.FullUri = request.FullUri.AddQueryParameter("language", langCode);
|
||||||
|
|
||||||
|
var result = await Api.Request<ActorCredits>(request);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<List<TvSearchResult>> SearchTv(string searchTerm)
|
public async Task<List<TvSearchResult>> SearchTv(string searchTerm)
|
||||||
{
|
{
|
||||||
var request = new Request($"search/tv", BaseUri, HttpMethod.Get);
|
var request = new Request($"search/tv", BaseUri, HttpMethod.Get);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue