Fixed: Clean Library being to agressive when lists are having failures.

Fixes #2455
pull/2/head
Leonardo Galli 7 years ago
parent 74e0db2829
commit 95ca863697

@ -34,19 +34,21 @@ namespace NzbDrone.Core.NetImport
_httpClient = httpClient;
}
public override IList<Movie> Fetch()
public override NetImportFetchResult Fetch()
{
var generator = GetRequestGenerator();
return FetchMovies(generator.GetMovies());
}
protected virtual IList<Movie> FetchMovies(NetImportPageableRequestChain pageableRequestChain, bool isRecent = false)
protected virtual NetImportFetchResult FetchMovies(NetImportPageableRequestChain pageableRequestChain, bool isRecent = false)
{
var movies = new List<Movie>();
var url = string.Empty;
var parser = GetParser();
var anyFailure = false;
try
{
for (int i = 0; i < pageableRequestChain.Tiers; i++)
@ -73,6 +75,7 @@ namespace NzbDrone.Core.NetImport
}
catch (WebException webException)
{
anyFailure = true;
if (webException.Message.Contains("502") || webException.Message.Contains("503") ||
webException.Message.Contains("timed out"))
{
@ -85,6 +88,7 @@ namespace NzbDrone.Core.NetImport
}
catch (HttpException httpException)
{
anyFailure = true;
if ((int)httpException.Response.StatusCode == 429)
{
_logger.Warn("API Request Limit reached for {0}", this);
@ -96,11 +100,12 @@ namespace NzbDrone.Core.NetImport
}
catch (Exception feedEx)
{
anyFailure = true;
feedEx.Data.Add("FeedUrl", url);
_logger.Error(feedEx, "An error occurred while processing feed. " + url);
}
return movies;
return new NetImportFetchResult {Movies = movies, AnyFailure = anyFailure};
}
protected virtual IList<Movie> FetchPage(NetImportRequest request, IParseNetImportResponse parser)

@ -9,6 +9,6 @@ namespace NzbDrone.Core.NetImport
bool Enabled { get; }
bool EnableAuto { get; }
IList<Movie> Fetch();
NetImportFetchResult Fetch();
}
}

@ -9,6 +9,12 @@ using NzbDrone.Core.Tv;
namespace NzbDrone.Core.NetImport
{
public class NetImportFetchResult
{
public IList<Movie> Movies { get; set; }
public bool AnyFailure { get; set; }
}
public abstract class NetImportBase<TSettings> : INetImport
where TSettings : IProviderConfig, new()
{
@ -20,7 +26,7 @@ namespace NzbDrone.Core.NetImport
public abstract bool Enabled { get; }
public abstract bool EnableAuto { get; }
public abstract IList<Movie> Fetch();
public abstract NetImportFetchResult Fetch();
public NetImportBase(IConfigService configService, IParsingService parsingService, Logger logger)
{

@ -54,21 +54,22 @@ namespace NzbDrone.Core.NetImport
}
public List<Movie> Fetch(int listId, bool onlyEnableAuto = false)
public NetImportFetchResult Fetch(int listId, bool onlyEnableAuto = false)
{
return MovieListSearch(listId, onlyEnableAuto);
}
public List<Movie> FetchAndFilter(int listId, bool onlyEnableAuto)
{
var movies = MovieListSearch(listId, onlyEnableAuto);
var movies = MovieListSearch(listId, onlyEnableAuto).Movies;
return _movieService.FilterExistingMovies(movies);
return _movieService.FilterExistingMovies(movies.ToList());
}
public List<Movie> MovieListSearch(int listId, bool onlyEnableAuto = false)
public NetImportFetchResult MovieListSearch(int listId, bool onlyEnableAuto = false)
{
var movies = new List<Movie>();
var anyFailure = false;
var importLists = _netImportFactory.GetAvailableProviders();
@ -81,24 +82,31 @@ namespace NzbDrone.Core.NetImport
foreach (var list in lists)
{
movies.AddRange(list.Fetch());
var result = list.Fetch();
movies.AddRange(result.Movies);
anyFailure |= result.AnyFailure;
}
_logger.Debug("Found {0} movies from list(s) {1}", movies.Count, string.Join(", ", lists.Select(l => l.Definition.Name)));
return movies.DistinctBy(x => {
if (x.TmdbId != 0)
{
return x.TmdbId.ToString();
}
return new NetImportFetchResult
{
Movies = movies.DistinctBy(x =>
{
if (x.TmdbId != 0)
{
return x.TmdbId.ToString();
}
if (x.ImdbId.IsNotNullOrWhiteSpace())
{
return x.ImdbId;
}
if (x.ImdbId.IsNotNullOrWhiteSpace())
{
return x.ImdbId;
}
return x.Title;
}).ToList();
return x.Title;
}).ToList(),
AnyFailure = anyFailure
};
}
@ -112,9 +120,13 @@ namespace NzbDrone.Core.NetImport
return;
}
var listedMovies = Fetch(0, true);
var result = Fetch(0, true);
var listedMovies = result.Movies.ToList();
CleanLibrary(listedMovies);
if (!result.AnyFailure)
{
CleanLibrary(listedMovies);
}
listedMovies = listedMovies.Where(x => !_movieService.MovieExists(x)).ToList();
if (listedMovies.Any())

Loading…
Cancel
Save