New: Option to disable rescanning of series folder after RefreshSeriesInfo

Closes #1592
pull/2789/head
Mark McDowall 6 years ago committed by Taloth Saldono
parent 7e79ccd710
commit 3b9ed49d0f

@ -215,6 +215,13 @@ namespace NzbDrone.Core.Configuration
set { SetValue("ExtraFileExtensions", value); } set { SetValue("ExtraFileExtensions", value); }
} }
public RescanAfterRefreshType RescanAfterRefresh
{
get { return GetValueEnum("RescanAfterRefresh", RescanAfterRefreshType.Always); }
set { SetValue("RescanAfterRefresh", value); }
}
public bool SetPermissionsLinux public bool SetPermissionsLinux
{ {
get { return GetValueBoolean("SetPermissionsLinux", false); } get { return GetValueBoolean("SetPermissionsLinux", false); }

@ -33,6 +33,7 @@ namespace NzbDrone.Core.Configuration
bool EnableMediaInfo { get; set; } bool EnableMediaInfo { get; set; }
bool ImportExtraFiles { get; set; } bool ImportExtraFiles { get; set; }
string ExtraFileExtensions { get; set; } string ExtraFileExtensions { get; set; }
RescanAfterRefreshType RescanAfterRefresh { get; set; }
//Permissions (Media Management) //Permissions (Media Management)
bool SetPermissionsLinux { get; set; } bool SetPermissionsLinux { get; set; }

@ -0,0 +1,9 @@
namespace NzbDrone.Core.Configuration
{
public enum RescanAfterRefreshType
{
Always,
AfterManual,
Never
}
}

@ -30,7 +30,6 @@ namespace NzbDrone.Core.MediaFiles
public class DiskScanService : public class DiskScanService :
IDiskScanService, IDiskScanService,
IHandle<SeriesUpdatedEvent>,
IExecute<RescanSeriesCommand> IExecute<RescanSeriesCommand>
{ {
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
@ -210,11 +209,6 @@ namespace NzbDrone.Core.MediaFiles
} }
} }
public void Handle(SeriesUpdatedEvent message)
{
Scan(message.Series);
}
public void Execute(RescanSeriesCommand message) public void Execute(RescanSeriesCommand message)
{ {
if (message.SeriesId.HasValue) if (message.SeriesId.HasValue)

@ -133,6 +133,7 @@
<Compile Include="Configuration\Events\ConfigSavedEvent.cs" /> <Compile Include="Configuration\Events\ConfigSavedEvent.cs" />
<Compile Include="Configuration\IConfigService.cs" /> <Compile Include="Configuration\IConfigService.cs" />
<Compile Include="Configuration\InvalidConfigFileException.cs" /> <Compile Include="Configuration\InvalidConfigFileException.cs" />
<Compile Include="Configuration\RescanAfterRefreshType.cs" />
<Compile Include="Configuration\ResetApiKeyCommand.cs" /> <Compile Include="Configuration\ResetApiKeyCommand.cs" />
<Compile Include="Datastore\Migration\130_episode_last_searched_time.cs" /> <Compile Include="Datastore\Migration\130_episode_last_searched_time.cs" />
<Compile Include="Datastore\Migration\129_add_relative_original_path_to_episode_file.cs" /> <Compile Include="Datastore\Migration\129_add_relative_original_path_to_episode_file.cs" />

@ -1,22 +1,24 @@
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.Tv.Commands namespace NzbDrone.Core.Tv.Commands
{ {
public class RefreshSeriesCommand : Command public class RefreshSeriesCommand : Command
{ {
public int? SeriesId { get; set; } public int? SeriesId { get; set; }
public bool IsNewSeries { get; set; }
public RefreshSeriesCommand() public RefreshSeriesCommand()
{ {
} }
public RefreshSeriesCommand(int? seriesId) public RefreshSeriesCommand(int? seriesId, bool isNewSeries = false)
{ {
SeriesId = seriesId; SeriesId = seriesId;
IsNewSeries = isNewSeries;
} }
public override bool SendUpdatesToClient => true; public override bool SendUpdatesToClient => true;
public override bool UpdateScheduledTask => !SeriesId.HasValue; public override bool UpdateScheduledTask => !SeriesId.HasValue;
} }
} }

@ -5,6 +5,7 @@ using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DataAugmentation.DailySeries; using NzbDrone.Core.DataAugmentation.DailySeries;
using NzbDrone.Core.Exceptions; using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
@ -25,6 +26,7 @@ namespace NzbDrone.Core.Tv
private readonly IDailySeriesService _dailySeriesService; private readonly IDailySeriesService _dailySeriesService;
private readonly IDiskScanService _diskScanService; private readonly IDiskScanService _diskScanService;
private readonly ICheckIfSeriesShouldBeRefreshed _checkIfSeriesShouldBeRefreshed; private readonly ICheckIfSeriesShouldBeRefreshed _checkIfSeriesShouldBeRefreshed;
private readonly IConfigService _configService;
private readonly Logger _logger; private readonly Logger _logger;
public RefreshSeriesService(IProvideSeriesInfo seriesInfo, public RefreshSeriesService(IProvideSeriesInfo seriesInfo,
@ -34,6 +36,7 @@ namespace NzbDrone.Core.Tv
IDailySeriesService dailySeriesService, IDailySeriesService dailySeriesService,
IDiskScanService diskScanService, IDiskScanService diskScanService,
ICheckIfSeriesShouldBeRefreshed checkIfSeriesShouldBeRefreshed, ICheckIfSeriesShouldBeRefreshed checkIfSeriesShouldBeRefreshed,
IConfigService configService,
Logger logger) Logger logger)
{ {
_seriesInfo = seriesInfo; _seriesInfo = seriesInfo;
@ -43,6 +46,7 @@ namespace NzbDrone.Core.Tv
_dailySeriesService = dailySeriesService; _dailySeriesService = dailySeriesService;
_diskScanService = diskScanService; _diskScanService = diskScanService;
_checkIfSeriesShouldBeRefreshed = checkIfSeriesShouldBeRefreshed; _checkIfSeriesShouldBeRefreshed = checkIfSeriesShouldBeRefreshed;
_configService = configService;
_logger = logger; _logger = logger;
} }
@ -50,17 +54,7 @@ namespace NzbDrone.Core.Tv
{ {
_logger.ProgressInfo("Updating {0}", series.Title); _logger.ProgressInfo("Updating {0}", series.Title);
Tuple<Series, List<Episode>> tuple; var tuple = _seriesInfo.GetSeriesInfo(series.TvdbId);
try
{
tuple = _seriesInfo.GetSeriesInfo(series.TvdbId);
}
catch (SeriesNotFoundException)
{
_logger.Error("Series '{0}' (tvdbid {1}) was not found, it may have been removed from TheTVDB.", series.Title, series.TvdbId);
return;
}
var seriesInfo = tuple.Item1; var seriesInfo = tuple.Item1;
@ -144,8 +138,32 @@ namespace NzbDrone.Core.Tv
return seasons; return seasons;
} }
private void RescanSeries(Series series) private void RescanSeries(Series series, bool isNew, CommandTrigger trigger)
{ {
var rescanAfterRefresh = _configService.RescanAfterRefresh;
var shouldRescan = true;
if (isNew)
{
_logger.Trace("Forcing refresh of {0}. Reason: New series", series);
shouldRescan = true;
}
else if (rescanAfterRefresh == RescanAfterRefreshType.Never)
{
_logger.Trace("Skipping refresh of {0}. Reason: never recan after refresh", series);
shouldRescan = false;
}
else if (rescanAfterRefresh == RescanAfterRefreshType.AfterManual && trigger != CommandTrigger.Manual)
{
_logger.Trace("Skipping refresh of {0}. Reason: not after automatic scans", series);
shouldRescan = false;
}
if (!shouldRescan)
{
return;
}
try try
{ {
_diskScanService.Scan(series); _diskScanService.Scan(series);
@ -158,7 +176,9 @@ namespace NzbDrone.Core.Tv
public void Execute(RefreshSeriesCommand message) public void Execute(RefreshSeriesCommand message)
{ {
_eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(message.Trigger == CommandTrigger.Manual)); var trigger = message.Trigger;
var isNew = message.IsNewSeries;
_eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(trigger == CommandTrigger.Manual));
if (message.SeriesId.HasValue) if (message.SeriesId.HasValue)
{ {
@ -167,11 +187,16 @@ namespace NzbDrone.Core.Tv
try try
{ {
RefreshSeriesInfo(series); RefreshSeriesInfo(series);
RescanSeries(series, isNew, trigger);
}
catch (SeriesNotFoundException)
{
_logger.Error("Series '{0}' (tvdbid {1}) was not found, it may have been removed from TheTVDB.", series.Title, series.TvdbId);
} }
catch (Exception e) catch (Exception e)
{ {
_logger.Error(e, "Couldn't refresh info for {0}", series); _logger.Error(e, "Couldn't refresh info for {0}", series);
RescanSeries(series); RescanSeries(series, isNew, trigger);
throw; throw;
} }
} }
@ -181,23 +206,29 @@ namespace NzbDrone.Core.Tv
foreach (var series in allSeries) foreach (var series in allSeries)
{ {
if (message.Trigger == CommandTrigger.Manual || _checkIfSeriesShouldBeRefreshed.ShouldRefresh(series)) if (trigger == CommandTrigger.Manual || _checkIfSeriesShouldBeRefreshed.ShouldRefresh(series))
{ {
try try
{ {
RefreshSeriesInfo(series); RefreshSeriesInfo(series);
} }
catch (SeriesNotFoundException)
{
_logger.Error("Series '{0}' (tvdbid {1}) was not found, it may have been removed from TheTVDB.", series.Title, series.TvdbId);
continue;
}
catch (Exception e) catch (Exception e)
{ {
_logger.Error(e, "Couldn't refresh info for {0}", series); _logger.Error(e, "Couldn't refresh info for {0}", series);
RescanSeries(series);
} }
RescanSeries(series, false, trigger);
} }
else else
{ {
_logger.Info("Skipping refresh of series: {0}", series.Title); _logger.Info("Skipping refresh of series: {0}", series.Title);
RescanSeries(series); RescanSeries(series, false, trigger);
} }
} }
} }

@ -1,4 +1,4 @@
using System.Linq; using System.Linq;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tv.Commands; using NzbDrone.Core.Tv.Commands;
@ -18,12 +18,12 @@ namespace NzbDrone.Core.Tv
public void Handle(SeriesAddedEvent message) public void Handle(SeriesAddedEvent message)
{ {
_commandQueueManager.Push(new RefreshSeriesCommand(message.Series.Id)); _commandQueueManager.Push(new RefreshSeriesCommand(message.Series.Id, true));
} }
public void Handle(SeriesImportedEvent message) public void Handle(SeriesImportedEvent message)
{ {
_commandQueueManager.PushMany(message.SeriesIds.Select(s => new RefreshSeriesCommand(s)).ToList()); _commandQueueManager.PushMany(message.SeriesIds.Select(s => new RefreshSeriesCommand(s, true)).ToList());
} }
} }
} }

@ -1,4 +1,4 @@
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tv.Commands; using NzbDrone.Core.Tv.Commands;
using NzbDrone.Core.Tv.Events; using NzbDrone.Core.Tv.Events;
@ -18,7 +18,7 @@ namespace NzbDrone.Core.Tv
{ {
if (message.Series.SeriesType != message.OldSeries.SeriesType) if (message.Series.SeriesType != message.OldSeries.SeriesType)
{ {
_commandQueueManager.Push(new RefreshSeriesCommand(message.Series.Id)); _commandQueueManager.Push(new RefreshSeriesCommand(message.Series.Id, false));
} }
} }
} }

@ -12,6 +12,7 @@ namespace Sonarr.Api.V3.Config
public bool CreateEmptySeriesFolders { get; set; } public bool CreateEmptySeriesFolders { get; set; }
public bool DeleteEmptyFolders { get; set; } public bool DeleteEmptyFolders { get; set; }
public FileDateType FileDate { get; set; } public FileDateType FileDate { get; set; }
public RescanAfterRefreshType RescanAfterRefresh { get; set; }
public bool SetPermissionsLinux { get; set; } public bool SetPermissionsLinux { get; set; }
public string FileChmod { get; set; } public string FileChmod { get; set; }
@ -38,6 +39,7 @@ namespace Sonarr.Api.V3.Config
CreateEmptySeriesFolders = model.CreateEmptySeriesFolders, CreateEmptySeriesFolders = model.CreateEmptySeriesFolders,
DeleteEmptyFolders = model.DeleteEmptyFolders, DeleteEmptyFolders = model.DeleteEmptyFolders,
FileDate = model.FileDate, FileDate = model.FileDate,
RescanAfterRefresh = model.RescanAfterRefresh,
SetPermissionsLinux = model.SetPermissionsLinux, SetPermissionsLinux = model.SetPermissionsLinux,
FileChmod = model.FileChmod, FileChmod = model.FileChmod,

Loading…
Cancel
Save