mirror of
https://github.com/Radarr/Radarr
synced 2025-02-25 15:43:08 +00:00
Fix netimport search and add NetImportSyncCommand
This commit is contained in:
parent
2b7afd3272
commit
93d6505f85
6 changed files with 114 additions and 21 deletions
|
@ -14,6 +14,7 @@
|
|||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.NetImport;
|
||||
using NzbDrone.Core.Tv.Commands;
|
||||
using NzbDrone.Core.Update.Commands;
|
||||
|
||||
|
@ -64,7 +65,7 @@ public void Handle(ApplicationStartedEvent message)
|
|||
new ScheduledTask{ Interval = 0.25f, TypeName = typeof(CheckForFinishedDownloadCommand).FullName},
|
||||
new ScheduledTask{ Interval = 5, TypeName = typeof(MessagingCleanupCommand).FullName},
|
||||
new ScheduledTask{ Interval = 6*60, TypeName = typeof(ApplicationUpdateCommand).FullName},
|
||||
// new ScheduledTask{ Interval = 3*60, TypeName = typeof(UpdateSceneMappingCommand).FullName},
|
||||
new ScheduledTask{ Interval = 12*60, TypeName = typeof(NetImportSyncCommand).FullName},
|
||||
new ScheduledTask{ Interval = 6*60, TypeName = typeof(CheckHealthCommand).FullName},
|
||||
new ScheduledTask{ Interval = 24*60, TypeName = typeof(RefreshMovieCommand).FullName},
|
||||
new ScheduledTask{ Interval = 24*60, TypeName = typeof(HousekeepingCommand).FullName},
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.NetImport
|
||||
|
@ -13,7 +15,7 @@ public interface IFetchNetImport
|
|||
List<Movie> FetchAndFilter(int listId, bool onlyEnableAuto);
|
||||
}
|
||||
|
||||
public class NetImportSearchService : IFetchNetImport
|
||||
public class NetImportSearchService : IFetchNetImport, IExecute<NetImportSyncCommand>
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
private readonly INetImportFactory _netImportFactory;
|
||||
|
@ -26,39 +28,29 @@ public NetImportSearchService(INetImportFactory netImportFactory, IMovieService
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<Movie> Fetch(int listId, bool onlyEnableAuto)
|
||||
public List<Movie> Fetch(int listId, bool onlyEnableAuto = false)
|
||||
{
|
||||
return MovieListSearch(listId, onlyEnableAuto);
|
||||
}
|
||||
|
||||
public List<Movie> FetchAndFilter(int listId, bool onlyEnableAuto)
|
||||
{
|
||||
var existingMovies = _movieService.GetAllMovies();
|
||||
|
||||
var movies = MovieListSearch(listId, onlyEnableAuto);
|
||||
|
||||
// remove from movies list where existMovies (choose one)
|
||||
// movies.RemoveAll(x => existingMovies.Contains(x));
|
||||
// return movies;
|
||||
//// or
|
||||
// movies.RemoveAll(a => existingMovies.Exists(w => w.TmdbId == a.TmdbId));
|
||||
// return movies;
|
||||
//// or
|
||||
|
||||
return movies.Where(x => !existingMovies.Contains(x)).ToList();
|
||||
return movies.Where(x => !_movieService.MovieExists(x)).ToList();
|
||||
}
|
||||
|
||||
public List<Movie> MovieListSearch(int listId, bool onlyEnableAuto)
|
||||
public List<Movie> MovieListSearch(int listId, bool onlyEnableAuto = false)
|
||||
{
|
||||
var movies = new List<Movie>();
|
||||
|
||||
var importLists = _netImportFactory.GetAvailableProviders();
|
||||
|
||||
var lists = listId == 0 ? importLists.Where(n => ((NetImportDefinition)n.Definition).Enabled == true) : importLists.Where(n => ((NetImportDefinition)n.Definition).Id == listId);
|
||||
var lists = listId == 0 ? importLists : importLists.Where(n => ((NetImportDefinition)n.Definition).Id == listId);
|
||||
|
||||
if (onlyEnableAuto)
|
||||
{
|
||||
lists = importLists.Where(a => a.EnableAuto == true);
|
||||
lists = importLists.Where(a => ((NetImportDefinition)a.Definition).EnableAuto);
|
||||
}
|
||||
|
||||
foreach (var list in lists)
|
||||
|
@ -66,7 +58,16 @@ public List<Movie> MovieListSearch(int listId, bool onlyEnableAuto)
|
|||
movies.AddRange(list.Fetch());
|
||||
}
|
||||
|
||||
_logger.Debug("Found {0} movies from list(s) {1}", movies.Count, string.Join(", ", lists.Select(l => l.Definition.Name)));
|
||||
|
||||
return movies;
|
||||
}
|
||||
|
||||
public void Execute(NetImportSyncCommand message)
|
||||
{
|
||||
var movies = FetchAndFilter(2, false);
|
||||
|
||||
_logger.Debug("Found {0} movies on your lists not in your library", movies.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/NzbDrone.Core/NetImport/NetImportSyncCommand.cs
Normal file
12
src/NzbDrone.Core/NetImport/NetImportSyncCommand.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.NetImport
|
||||
{
|
||||
public class NetImportSyncCommand : Command
|
||||
{
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
|
||||
public int listId = 0;
|
||||
}
|
||||
}
|
|
@ -886,6 +886,7 @@
|
|||
<Compile Include="MetadataSource\IProvideSeriesInfo.cs" />
|
||||
<Compile Include="MetadataSource\ISearchForNewSeries.cs" />
|
||||
<Compile Include="MetadataSource\TmdbConfigurationService.cs" />
|
||||
<Compile Include="NetImport\NetImportSyncCommand.cs" />
|
||||
<Compile Include="Notifications\Join\JoinAuthException.cs" />
|
||||
<Compile Include="Notifications\Join\JoinInvalidDeviceException.cs" />
|
||||
<Compile Include="Notifications\Join\JoinResponseModel.cs" />
|
||||
|
|
|
@ -15,6 +15,7 @@ public interface IMovieRepository : IBasicRepository<Movie>
|
|||
Movie FindByTitle(string cleanTitle);
|
||||
Movie FindByTitle(string cleanTitle, int year);
|
||||
Movie FindByImdbId(string imdbid);
|
||||
Movie FindByTmdbId(int tmdbid);
|
||||
Movie FindByTitleSlug(string slug);
|
||||
List<Movie> MoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored);
|
||||
List<Movie> MoviesWithFiles(int movieId);
|
||||
|
@ -100,9 +101,46 @@ public Movie FindByTitle(string cleanTitle, int year)
|
|||
{
|
||||
cleanTitle = cleanTitle.ToLowerInvariant();
|
||||
|
||||
return Query.Where(s => s.CleanTitle == cleanTitle)
|
||||
.AndWhere(s => s.Year == year)
|
||||
.SingleOrDefault();
|
||||
var cleanRoman = cleanTitle;
|
||||
|
||||
var cleanNum = cleanTitle;
|
||||
|
||||
foreach (KeyValuePair<string, string> entry in romanNumeralsMapper)
|
||||
{
|
||||
string num = entry.Key;
|
||||
string roman = entry.Value.ToLower();
|
||||
|
||||
cleanRoman = cleanRoman.Replace(num, roman);
|
||||
|
||||
cleanNum = cleanNum.Replace(roman, num);
|
||||
}
|
||||
|
||||
var results = Query.Where(s => s.CleanTitle == cleanTitle);
|
||||
|
||||
if (results == null)
|
||||
{
|
||||
results = Query.Where(s => s.CleanTitle == cleanNum).OrWhere(s => s.CleanTitle == cleanRoman);
|
||||
|
||||
if (results == null)
|
||||
{
|
||||
var movies = this.All();
|
||||
|
||||
var listResults = movies.Where(m => m.AlternativeTitles.Any(t => Parser.Parser.CleanSeriesTitle(t.ToLower()) == cleanTitle ||
|
||||
Parser.Parser.CleanSeriesTitle(t.ToLower()) == cleanRoman ||
|
||||
Parser.Parser.CleanSeriesTitle(t.ToLower()) == cleanNum));
|
||||
|
||||
return listResults.Where(m => m.Year == year).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
return results.Where(m => m.Year == year).FirstOrDefault();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return results.Where(m => m.Year == year).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public Movie FindByImdbId(string imdbid)
|
||||
|
@ -122,7 +160,7 @@ public void SetFileId(int fileId, int episodeId)
|
|||
|
||||
public Movie FindByTitleSlug(string slug)
|
||||
{
|
||||
return Query.Where(m => m.TitleSlug == slug).FirstOrDefault();
|
||||
return Query.FirstOrDefault(m => m.TitleSlug == slug);
|
||||
}
|
||||
|
||||
public List<Movie> MoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored)
|
||||
|
@ -161,5 +199,10 @@ public SortBuilder<Movie> GetMoviesWithoutFilesQuery(PagingSpec<Movie> pagingSpe
|
|||
.Skip(pagingSpec.PagingOffset())
|
||||
.Take(pagingSpec.PageSize);
|
||||
}
|
||||
|
||||
public Movie FindByTmdbId(int tmdbid)
|
||||
{
|
||||
return Query.Where(m => m.TmdbId == tmdbid).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ public interface IMovieService
|
|||
Movie FindByTitle(string title, int year);
|
||||
Movie FindByTitleInexact(string title);
|
||||
Movie FindByTitleSlug(string slug);
|
||||
bool MovieExists(Movie movie);
|
||||
Movie GetMovieByFileId(int fileId);
|
||||
List<Movie> GetMoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored);
|
||||
PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec);
|
||||
|
@ -247,5 +248,39 @@ public PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec)
|
|||
|
||||
return movieResult;
|
||||
}
|
||||
|
||||
public bool MovieExists(Movie movie)
|
||||
{
|
||||
Movie result = null;
|
||||
|
||||
if (movie.TmdbId != 0)
|
||||
{
|
||||
result = _movieRepository.FindByTmdbId(movie.TmdbId);
|
||||
if (result != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (movie.ImdbId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
result = _movieRepository.FindByImdbId(movie.ImdbId);
|
||||
if (result != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (movie.Year > 1850)
|
||||
{
|
||||
result = _movieRepository.FindByTitle(movie.Title.CleanSeriesTitle(), movie.Year);
|
||||
if (result != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue