Skip to content

Commit

Permalink
Merge pull request #1178 from smcpeck/master
Browse files Browse the repository at this point in the history
FEATURE: Search movies by actor
  • Loading branch information
tidusjar authored Feb 24, 2017
2 parents 3d62640 + 99e48f3 commit e420d03
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 136 deletions.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ V 1.XX.XX

Stable/Early Access Preview/development

#### Media Sever:

Plex/Emby

#### Media Server Version:

<!-- If appropriate --->

#### Operating System:

(Place text here)
Expand Down
1 change: 0 additions & 1 deletion Ombi.Api/RadarrApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public RadarrAddMovie AddMovie(int tmdbId, string title, int year, int qualityId
request.AddHeader("X-Api-Key", apiKey);
request.AddJsonBody(options);

RadarrAddMovie result;
try
{
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
Expand Down
51 changes: 51 additions & 0 deletions Ombi.Api/TheMovieDbApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
using TMDbLib.Objects.Movies;
using TMDbLib.Objects.Search;
using Movie = TMDbLib.Objects.Movies.Movie;
using TMDbLib.Objects.People;
using System.Linq;

namespace Ombi.Api
{
Expand Down Expand Up @@ -69,6 +71,11 @@ public async Task<List<MovieResult>> GetUpcomingMovies()
return movies?.Results ?? new List<MovieResult>();
}

private async Task<Movie> GetMovie(int id)
{
return await Client.GetMovie(id);
}

public TmdbMovieDetails GetMovieInformationWithVideos(int tmdbId)
{
var request = new RestRequest { Resource = "movie/{movieId}", Method = Method.GET };
Expand Down Expand Up @@ -100,5 +107,49 @@ public async Task<Movie> GetMovieInformation(string imdbId)
var movies = await Client.GetMovie(imdbId);
return movies ?? new Movie();
}

public async Task<List<Movie>> SearchPerson(string searchTerm)
{
return await SearchPerson(searchTerm, null);
}

public async Task<List<Movie>> SearchPerson(string searchTerm, Func<int, string, string, Task<bool>> alreadyAvailable)
{
SearchContainer<SearchPerson> result = await Client.SearchPerson(searchTerm);

var people = result?.Results ?? new List<SearchPerson>();
var person = (people.Count != 0 ? people[0] : null);
var movies = new List<Movie>();
var counter = 0;
try
{
if (person != null)
{
var credits = await Client.GetPersonMovieCredits(person.Id);

// grab results from both cast and crew, prefer items in cast. we can handle directors like this.
List<Movie> movieResults = (from MovieRole role in credits.Cast select new Movie() { Id = role.Id, Title = role.Title, ReleaseDate = role.ReleaseDate }).ToList();
movieResults.AddRange((from MovieJob job in credits.Crew select new Movie() { Id = job.Id, Title = job.Title, ReleaseDate = job.ReleaseDate }).ToList());

//only get the first 10 movies and delay a bit between each request so we don't overload the API
foreach (var m in movieResults)
{
if (counter == 10)
break;
if (alreadyAvailable == null || !(await alreadyAvailable(m.Id, m.Title, m.ReleaseDate.Value.Year.ToString())))
{
movies.Add(await GetMovie(m.Id));
counter++;
}
await Task.Delay(50);
}
}
}
catch (Exception e)
{
Log.Log(LogLevel.Error, e);
}
return movies;
}
}
}
1 change: 1 addition & 0 deletions Ombi.Core/SettingModels/PlexRequestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public PlexRequestSettings()
public int Port { get; set; }
public string BaseUrl { get; set; }
public bool SearchForMovies { get; set; }
public bool SearchForActors { get; set; }
public bool SearchForTvShows { get; set; }
public bool SearchForMusic { get; set; }
[Obsolete("Use the user management settings")]
Expand Down
1 change: 1 addition & 0 deletions Ombi.Core/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void CreateDefaultSettingsPage(string baseUrl)
{
SearchForMovies = true,
SearchForTvShows = true,
SearchForActors = true,
BaseUrl = baseUrl ?? string.Empty,
CollectAnalyticData = true,
};
Expand Down
1 change: 1 addition & 0 deletions Ombi.Core/StatusChecker/StatusChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public async Task<Issue> ReportBug(string title, string body, string oauthToken)

public async Task<Uri> OAuth(string url, ISession session)
{
await Task.Yield();

var csrf = StringCipher.Encrypt(Guid.NewGuid().ToString("N"), "CSRF");
session[SessionKeys.CSRF] = csrf;
Expand Down
12 changes: 6 additions & 6 deletions Ombi.Services/Interfaces/IAvailabilityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public interface IAvailabilityChecker
void Start();
void CheckAndUpdateAll();
IEnumerable<PlexContent> GetPlexMovies(IEnumerable<PlexContent> content);
bool IsMovieAvailable(PlexContent[] plexMovies, string title, string year, string providerId = null);
bool IsMovieAvailable(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null);
IEnumerable<PlexContent> GetPlexTvShows(IEnumerable<PlexContent> content);
bool IsTvShowAvailable(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
bool IsTvShowAvailable(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null, int[] seasons = null);
IEnumerable<PlexContent> GetPlexAlbums(IEnumerable<PlexContent> content);
bool IsAlbumAvailable(PlexContent[] plexAlbums, string title, string year, string artist);
bool IsAlbumAvailable(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist);
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
PlexContent GetAlbum(PlexContent[] plexAlbums, string title, string year, string artist);
PlexContent GetMovie(PlexContent[] plexMovies, string title, string year, string providerId = null);
PlexContent GetTvShow(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
PlexContent GetAlbum(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist);
PlexContent GetMovie(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null);
PlexContent GetTvShow(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null, int[] seasons = null);
/// <summary>
/// Gets the episode's stored in the cache.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions Ombi.Services/Jobs/EmbyAvailabilityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public IEnumerable<EmbyContent> GetEmbyMovies(IEnumerable<EmbyContent> content)
return content.Where(x => x.Type == EmbyMediaType.Movie);
}

public bool IsMovieAvailable(EmbyContent[] embyMovies, string title, string year, string providerId)
public bool IsMovieAvailable(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId)
{
var movie = GetMovie(embyMovies, title, year, providerId);
return movie != null;
}

public EmbyContent GetMovie(EmbyContent[] embyMovies, string title, string year, string providerId)
public EmbyContent GetMovie(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId)
{
if (embyMovies.Length == 0)
if (embyMovies.Count() == 0)
{
return null;
}
Expand Down Expand Up @@ -200,14 +200,14 @@ public IEnumerable<EmbyContent> GetEmbyTvShows(IEnumerable<EmbyContent> content)
return content.Where(x => x.Type == EmbyMediaType.Series);
}

public bool IsTvShowAvailable(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null)
public bool IsTvShowAvailable(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null)
{
var show = GetTvShow(embyShows, title, year, providerId, seasons);
return show != null;
}


public EmbyContent GetTvShow(EmbyContent[] embyShows, string title, string year, string providerId,
public EmbyContent GetTvShow(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId,
int[] seasons = null)
{
foreach (var show in embyShows)
Expand Down
8 changes: 4 additions & 4 deletions Ombi.Services/Jobs/Interfaces/IEmbyAvailabilityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public interface IEmbyAvailabilityChecker
IEnumerable<EmbyContent> GetEmbyTvShows(IEnumerable<EmbyContent> content);
Task<IEnumerable<EmbyEpisodes>> GetEpisodes();
Task<IEnumerable<EmbyEpisodes>> GetEpisodes(int theTvDbId);
EmbyContent GetMovie(EmbyContent[] embyMovies, string title, string year, string providerId);
EmbyContent GetTvShow(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null);
EmbyContent GetMovie(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId);
EmbyContent GetTvShow(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null);
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
bool IsMovieAvailable(EmbyContent[] embyMovies, string title, string year, string providerId);
bool IsTvShowAvailable(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null);
bool IsMovieAvailable(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId);
bool IsTvShowAvailable(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null);
void Start();
}
}
14 changes: 7 additions & 7 deletions Ombi.Services/Jobs/PlexAvailabilityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ public IEnumerable<PlexContent> GetPlexMovies(IEnumerable<PlexContent> content)
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Movie);
}

public bool IsMovieAvailable(PlexContent[] plexMovies, string title, string year, string providerId = null)
public bool IsMovieAvailable(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null)
{
var movie = GetMovie(plexMovies, title, year, providerId);
return movie != null;
}

public PlexContent GetMovie(PlexContent[] plexMovies, string title, string year, string providerId = null)
public PlexContent GetMovie(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null)
{
if (plexMovies.Length == 0)
if (plexMovies.Count() == 0)
{
return null;
}
Expand Down Expand Up @@ -236,14 +236,14 @@ public IEnumerable<PlexContent> GetPlexTvShows(IEnumerable<PlexContent> content)
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Show);
}

public bool IsTvShowAvailable(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null)
public bool IsTvShowAvailable(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null, int[] seasons = null)
{
var show = GetTvShow(plexShows, title, year, providerId, seasons);
return show != null;
}


public PlexContent GetTvShow(PlexContent[] plexShows, string title, string year, string providerId = null,
public PlexContent GetTvShow(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null,
int[] seasons = null)
{
var advanced = !string.IsNullOrEmpty(providerId);
Expand Down Expand Up @@ -345,14 +345,14 @@ public IEnumerable<PlexContent> GetPlexAlbums(IEnumerable<PlexContent> content)
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Artist);
}

public bool IsAlbumAvailable(PlexContent[] plexAlbums, string title, string year, string artist)
public bool IsAlbumAvailable(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist)
{
return plexAlbums.Any(x =>
x.Title.Contains(title) &&
x.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase));
}

public PlexContent GetAlbum(PlexContent[] plexAlbums, string title, string year, string artist)
public PlexContent GetAlbum(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist)
{
return plexAlbums.FirstOrDefault(x =>
x.Title.Contains(title) &&
Expand Down
36 changes: 35 additions & 1 deletion Ombi.UI/Content/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
//if ($tvl.mixItUp('isLoaded')) $tvl.mixItUp('destroy');
//$tvl.mixItUp(mixItUpConfig(activeState)); // init or reinit
}
if (target === "#MoviesTab") {
if (target === "#MoviesTab" || target === "#ActorsTab") {
if (target === "#ActorsTab") {
actorLoad();
}
$('#approveMovies,#deleteMovies').show();
if ($tvl.mixItUp('isLoaded')) {
activeState = $tvl.mixItUp('getState');
Expand Down Expand Up @@ -733,6 +736,37 @@ function initLoad() {

}


function actorLoad() {
var $ml = $('#actorMovieList');
if ($ml.mixItUp('isLoaded')) {
activeState = $ml.mixItUp('getState');
$ml.mixItUp('destroy');
}
$ml.html("");

var $newOnly = $('#searchNewOnly').val();
var url = createBaseUrl(base, '/requests/actor' + (!!$newOnly ? '/new' : ''));
$.ajax(url).success(function (results) {
if (results.length > 0) {
results.forEach(function (result) {
var context = buildRequestContext(result, "movie");
var html = searchTemplate(context);
$ml.append(html);
});


$('.customTooltip').tooltipster({
contentCloning: true
});
}
else {
$ml.html(noResultsHtml.format("movie"));
}
$ml.mixItUp(mixItUpConfig());
});
};

function movieLoad() {
var $ml = $('#movieList');
if ($ml.mixItUp('isLoaded')) {
Expand Down
48 changes: 38 additions & 10 deletions Ombi.UI/Content/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ $(function () {

});

// Type in actor search
$("#actorSearchContent").on("input", function () {
triggerActorSearch();
});

// if they toggle the checkbox, we want to refresh our search
$("#actorsSearchNew").click(function () {
triggerActorSearch();
});

function triggerActorSearch()
{
if (searchTimer) {
clearTimeout(searchTimer);
}
searchTimer = setTimeout(function () {
moviesFromActor();
}.bind(this), 800);
}

$('#moviesComingSoon').on('click', function (e) {
e.preventDefault();
moviesComingSoon();
Expand Down Expand Up @@ -300,7 +320,7 @@ $(function () {
function movieSearch() {
var query = $("#movieSearchContent").val();
var url = createBaseUrl(base, '/search/movie/');
query ? getMovies(url + query) : resetMovies();
query ? getMovies(url + query) : resetMovies("#movieList");
}

function moviesComingSoon() {
Expand All @@ -313,6 +333,13 @@ $(function () {
getMovies(url);
}

function moviesFromActor() {
var query = $("#actorSearchContent").val();
var $newOnly = $('#actorsSearchNew')[0].checked;
var url = createBaseUrl(base, '/search/actor/' + (!!$newOnly ? 'new/' : ''));
query ? getMovies(url + query, "#actorMovieList", "#actorSearchButton") : resetMovies("#actorMovieList");
}

function popularShows() {
var url = createBaseUrl(base, '/search/tv/popular');
getTvShows(url, true);
Expand All @@ -330,30 +357,31 @@ $(function () {
getTvShows(url, true);
}

function getMovies(url) {
resetMovies();

$('#movieSearchButton').attr("class", "fa fa-spinner fa-spin");
function getMovies(url, target, button) {
target = target || "#movieList";
button = button || "#movieSearchButton";
resetMovies(target);
$(button).attr("class", "fa fa-spinner fa-spin");
$.ajax(url).success(function (results) {
if (results.length > 0) {
results.forEach(function (result) {
var context = buildMovieContext(result);

var html = searchTemplate(context);
$("#movieList").append(html);
$(target).append(html);

checkNetflix(context.title, context.id);
});
}
else {
$("#movieList").html(noResultsHtml);
$(target).html(noResultsHtml);
}
$('#movieSearchButton').attr("class", "fa fa-search");
$(button).attr("class", "fa fa-search");
});
};

function resetMovies() {
$("#movieList").html("");
function resetMovies(target) {
$(target).html("");
}

function tvSearch() {
Expand Down
2 changes: 2 additions & 0 deletions Ombi.UI/Modules/Admin/ScheduledJobsRunnerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public ScheduledJobsRunnerModule(ISettingsService<PlexRequestSettings> settingsS

private async Task<Response> ScheduleRun(string key)
{
await Task.Yield();

if (key.Equals(JobNames.PlexCacher, StringComparison.CurrentCultureIgnoreCase))
{
PlexContentCacher.CacheContent();
Expand Down
Loading

0 comments on commit e420d03

Please sign in to comment.