parent
d8f3d7d3ea
commit
7be4840f02
|
@ -40,31 +40,41 @@ namespace NzbDrone.Core.ImportLists
|
||||||
|
|
||||||
private void SyncAll()
|
private void SyncAll()
|
||||||
{
|
{
|
||||||
|
if (_importListFactory.AutomaticAddEnabled().Empty())
|
||||||
|
{
|
||||||
|
_logger.Debug("No import lists with automatic add enabled");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_logger.ProgressInfo("Starting Import List Sync");
|
_logger.ProgressInfo("Starting Import List Sync");
|
||||||
|
|
||||||
var rssReleases = _listFetcherAndParser.Fetch();
|
var listItems = _listFetcherAndParser.Fetch().ToList();
|
||||||
|
|
||||||
var reports = rssReleases.ToList();
|
ProcessListItems(listItems);
|
||||||
|
|
||||||
ProcessReports(reports);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SyncList(ImportListDefinition definition)
|
private void SyncList(ImportListDefinition definition)
|
||||||
{
|
{
|
||||||
_logger.ProgressInfo(string.Format("Starting Import List Refresh for List {0}", definition.Name));
|
_logger.ProgressInfo(string.Format("Starting Import List Refresh for List {0}", definition.Name));
|
||||||
|
|
||||||
var rssReleases = _listFetcherAndParser.FetchSingleList(definition);
|
var listItems = _listFetcherAndParser.FetchSingleList(definition).ToList();
|
||||||
|
|
||||||
var reports = rssReleases.ToList();
|
ProcessListItems(listItems);
|
||||||
|
|
||||||
ProcessReports(reports);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessReports(List<ImportListItemInfo> reports)
|
private void ProcessListItems(List<ImportListItemInfo> items)
|
||||||
{
|
{
|
||||||
var seriesToAdd = new List<Series>();
|
var seriesToAdd = new List<Series>();
|
||||||
|
|
||||||
_logger.ProgressInfo("Processing {0} list items", reports.Count);
|
if (items.Count == 0)
|
||||||
|
{
|
||||||
|
_logger.ProgressInfo("No list items to process");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.ProgressInfo("Processing {0} list items", items.Count);
|
||||||
|
|
||||||
var reportNumber = 1;
|
var reportNumber = 1;
|
||||||
|
|
||||||
|
@ -72,79 +82,79 @@ namespace NzbDrone.Core.ImportLists
|
||||||
var importLists = _importListFactory.All();
|
var importLists = _importListFactory.All();
|
||||||
var existingTvdbIds = _seriesService.AllSeriesTvdbIds();
|
var existingTvdbIds = _seriesService.AllSeriesTvdbIds();
|
||||||
|
|
||||||
foreach (var report in reports)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
_logger.ProgressTrace("Processing list item {0}/{1}", reportNumber, reports.Count);
|
_logger.ProgressTrace("Processing list item {0}/{1}", reportNumber, items.Count);
|
||||||
|
|
||||||
reportNumber++;
|
reportNumber++;
|
||||||
|
|
||||||
var importList = importLists.Single(x => x.Id == report.ImportListId);
|
var importList = importLists.Single(x => x.Id == item.ImportListId);
|
||||||
|
|
||||||
// Map by IMDbId if we have it
|
// Map by IMDbId if we have it
|
||||||
if (report.TvdbId <= 0 && report.ImdbId.IsNotNullOrWhiteSpace())
|
if (item.TvdbId <= 0 && item.ImdbId.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
var mappedSeries = _seriesSearchService.SearchForNewSeriesByImdbId(report.ImdbId)
|
var mappedSeries = _seriesSearchService.SearchForNewSeriesByImdbId(item.ImdbId)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (mappedSeries != null)
|
if (mappedSeries != null)
|
||||||
{
|
{
|
||||||
report.TvdbId = mappedSeries.TvdbId;
|
item.TvdbId = mappedSeries.TvdbId;
|
||||||
report.Title = mappedSeries?.Title;
|
item.Title = mappedSeries?.Title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map by AniListId if we have it
|
// Map by AniListId if we have it
|
||||||
if (report.TvdbId <= 0 && report.AniListId > 0)
|
if (item.TvdbId <= 0 && item.AniListId > 0)
|
||||||
{
|
{
|
||||||
var mappedSeries = _seriesSearchService.SearchForNewSeriesByAniListId(report.AniListId)
|
var mappedSeries = _seriesSearchService.SearchForNewSeriesByAniListId(item.AniListId)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (mappedSeries != null)
|
if (mappedSeries != null)
|
||||||
{
|
{
|
||||||
report.TvdbId = mappedSeries.TvdbId;
|
item.TvdbId = mappedSeries.TvdbId;
|
||||||
report.Title = mappedSeries.Title;
|
item.Title = mappedSeries.Title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map TVDb if we only have a series name
|
// Map TVDb if we only have a series name
|
||||||
if (report.TvdbId <= 0 && report.Title.IsNotNullOrWhiteSpace())
|
if (item.TvdbId <= 0 && item.Title.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
var mappedSeries = _seriesSearchService.SearchForNewSeries(report.Title)
|
var mappedSeries = _seriesSearchService.SearchForNewSeries(item.Title)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (mappedSeries != null)
|
if (mappedSeries != null)
|
||||||
{
|
{
|
||||||
report.TvdbId = mappedSeries.TvdbId;
|
item.TvdbId = mappedSeries.TvdbId;
|
||||||
report.Title = mappedSeries?.Title;
|
item.Title = mappedSeries?.Title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if series excluded
|
// Check to see if series excluded
|
||||||
var excludedSeries = listExclusions.Where(s => s.TvdbId == report.TvdbId).SingleOrDefault();
|
var excludedSeries = listExclusions.Where(s => s.TvdbId == item.TvdbId).SingleOrDefault();
|
||||||
|
|
||||||
if (excludedSeries != null)
|
if (excludedSeries != null)
|
||||||
{
|
{
|
||||||
_logger.Debug("{0} [{1}] Rejected due to list exclusion", report.TvdbId, report.Title);
|
_logger.Debug("{0} [{1}] Rejected due to list exclusion", item.TvdbId, item.Title);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Break if Series Exists in DB
|
// Break if Series Exists in DB
|
||||||
if (existingTvdbIds.Any(x => x == report.TvdbId))
|
if (existingTvdbIds.Any(x => x == item.TvdbId))
|
||||||
{
|
{
|
||||||
_logger.Debug("{0} [{1}] Rejected, Series Exists in DB", report.TvdbId, report.Title);
|
_logger.Debug("{0} [{1}] Rejected, Series Exists in DB", item.TvdbId, item.Title);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append Series if not already in DB or already on add list
|
// Append Series if not already in DB or already on add list
|
||||||
if (seriesToAdd.All(s => s.TvdbId != report.TvdbId))
|
if (seriesToAdd.All(s => s.TvdbId != item.TvdbId))
|
||||||
{
|
{
|
||||||
var monitored = importList.ShouldMonitor != MonitorTypes.None;
|
var monitored = importList.ShouldMonitor != MonitorTypes.None;
|
||||||
|
|
||||||
seriesToAdd.Add(new Series
|
seriesToAdd.Add(new Series
|
||||||
{
|
{
|
||||||
TvdbId = report.TvdbId,
|
TvdbId = item.TvdbId,
|
||||||
Title = report.Title,
|
Title = item.Title,
|
||||||
Year = report.Year,
|
Year = item.Year,
|
||||||
Monitored = monitored,
|
Monitored = monitored,
|
||||||
RootFolderPath = importList.RootFolderPath,
|
RootFolderPath = importList.RootFolderPath,
|
||||||
QualityProfileId = importList.QualityProfileId,
|
QualityProfileId = importList.QualityProfileId,
|
||||||
|
@ -162,7 +172,7 @@ namespace NzbDrone.Core.ImportLists
|
||||||
|
|
||||||
_addSeriesService.AddSeries(seriesToAdd, true);
|
_addSeriesService.AddSeries(seriesToAdd, true);
|
||||||
|
|
||||||
var message = string.Format("Import List Sync Completed. Items found: {0}, Series added: {1}", reports.Count, seriesToAdd.Count);
|
var message = string.Format("Import List Sync Completed. Items found: {0}, Series added: {1}", items.Count, seriesToAdd.Count);
|
||||||
|
|
||||||
_logger.ProgressInfo(message);
|
_logger.ProgressInfo(message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue