reset existing xem info during update
This commit is contained in:
parent
b43c4e04f8
commit
575dc03e35
|
@ -67,6 +67,14 @@ namespace NzbDrone.Common.Cache
|
||||||
_store.TryRemove(key, out value);
|
_store.TryRemove(key, out value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _store.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public T Get(string key, Func<T> function, TimeSpan? lifeTime = null)
|
public T Get(string key, Func<T> function, TimeSpan? lifeTime = null)
|
||||||
{
|
{
|
||||||
Ensure.That(key, () => key).IsNotNullOrWhiteSpace();
|
Ensure.That(key, () => key).IsNotNullOrWhiteSpace();
|
||||||
|
|
|
@ -6,6 +6,8 @@ namespace NzbDrone.Common.Cache
|
||||||
public interface ICached
|
public interface ICached
|
||||||
{
|
{
|
||||||
void Clear();
|
void Clear();
|
||||||
|
void Remove(string key);
|
||||||
|
int Count { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ICached<T> : ICached
|
public interface ICached<T> : ICached
|
||||||
|
@ -13,7 +15,6 @@ namespace NzbDrone.Common.Cache
|
||||||
void Set(string key, T value, TimeSpan? lifetime = null);
|
void Set(string key, T value, TimeSpan? lifetime = null);
|
||||||
T Get(string key, Func<T> function, TimeSpan? lifeTime = null);
|
T Get(string key, Func<T> function, TimeSpan? lifeTime = null);
|
||||||
T Find(string key);
|
T Find(string key);
|
||||||
void Remove(string key);
|
|
||||||
|
|
||||||
ICollection<T> Values { get; }
|
ICollection<T> Values { get; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.DataAugmentation.Xem
|
|
||||||
{
|
|
||||||
public class UpdateXemMappingsCommand : Command
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Cache;
|
using NzbDrone.Common.Cache;
|
||||||
using NzbDrone.Core.Lifecycle;
|
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
using NzbDrone.Core.Tv.Events;
|
using NzbDrone.Core.Tv.Events;
|
||||||
|
|
||||||
namespace NzbDrone.Core.DataAugmentation.Xem
|
namespace NzbDrone.Core.DataAugmentation.Xem
|
||||||
{
|
{
|
||||||
public class XemService : IExecute<UpdateXemMappingsCommand>, IHandle<SeriesUpdatedEvent>, IHandleAsync<ApplicationStartedEvent>
|
public class XemService : IHandle<SeriesUpdatedEvent>
|
||||||
{
|
{
|
||||||
private readonly IEpisodeService _episodeService;
|
private readonly IEpisodeService _episodeService;
|
||||||
private readonly IXemProxy _xemProxy;
|
private readonly IXemProxy _xemProxy;
|
||||||
|
@ -33,63 +30,28 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Execute(UpdateXemMappingsCommand message)
|
|
||||||
{
|
|
||||||
UpdateMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Handle(SeriesUpdatedEvent message)
|
public void Handle(SeriesUpdatedEvent message)
|
||||||
{
|
{
|
||||||
UpdateMappings(message.Series);
|
if (_cache.Count == 0)
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleAsync(ApplicationStartedEvent message)
|
|
||||||
{
|
|
||||||
GetXemSeriesIds();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateMappings()
|
|
||||||
{
|
|
||||||
_logger.Trace("Starting scene numbering update");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var ids = GetXemSeriesIds();
|
RefreshCache();
|
||||||
var series = _seriesService.GetAllSeries();
|
|
||||||
var wantedSeries = series.Where(s => ids.Contains(s.TvdbId)).ToList();
|
|
||||||
|
|
||||||
foreach (var ser in wantedSeries)
|
|
||||||
{
|
|
||||||
PerformUpdate(ser);
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Trace("Completed scene numbering update");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex)
|
if (!_cache.Find(message.Series.TvdbId.ToString()))
|
||||||
{
|
{
|
||||||
_logger.WarnException("Error updating Scene Mappings", ex);
|
_logger.Trace("Scene numbering is not available for {0} [{1}]", message.Series.Title, message.Series.TvdbId);
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateMappings(Series series)
|
|
||||||
{
|
|
||||||
if (!_cache.Find(series.TvdbId.ToString()))
|
|
||||||
{
|
|
||||||
_logger.Trace("Scene numbering is not available for {0} [{1}]", series.Title, series.TvdbId);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PerformUpdate(series);
|
PerformUpdate(message.Series);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PerformUpdate(Series series)
|
private void PerformUpdate(Series series)
|
||||||
{
|
{
|
||||||
_logger.Trace("Updating scene numbering mapping for: {0}", series);
|
_logger.Trace("Updating scene numbering mapping for: {0}", series);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var episodesToUpdate = new List<Episode>();
|
|
||||||
var mappings = _xemProxy.GetSceneTvdbMappings(series.TvdbId);
|
var mappings = _xemProxy.GetSceneTvdbMappings(series.TvdbId);
|
||||||
|
|
||||||
if (!mappings.Any())
|
if (!mappings.Any())
|
||||||
|
@ -101,6 +63,13 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
||||||
|
|
||||||
var episodes = _episodeService.GetEpisodeBySeries(series.Id);
|
var episodes = _episodeService.GetEpisodeBySeries(series.Id);
|
||||||
|
|
||||||
|
foreach (var episode in episodes)
|
||||||
|
{
|
||||||
|
episode.AbsoluteEpisodeNumber = 0;
|
||||||
|
episode.SceneSeasonNumber = 0;
|
||||||
|
episode.SceneEpisodeNumber = 0;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var mapping in mappings)
|
foreach (var mapping in mappings)
|
||||||
{
|
{
|
||||||
_logger.Trace("Setting scene numbering mappings for {0} S{1:00}E{2:00}", series, mapping.Tvdb.Season, mapping.Tvdb.Episode);
|
_logger.Trace("Setting scene numbering mappings for {0} S{1:00}E{2:00}", series, mapping.Tvdb.Season, mapping.Tvdb.Episode);
|
||||||
|
@ -116,24 +85,21 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
||||||
episode.AbsoluteEpisodeNumber = mapping.Scene.Absolute;
|
episode.AbsoluteEpisodeNumber = mapping.Scene.Absolute;
|
||||||
episode.SceneSeasonNumber = mapping.Scene.Season;
|
episode.SceneSeasonNumber = mapping.Scene.Season;
|
||||||
episode.SceneEpisodeNumber = mapping.Scene.Episode;
|
episode.SceneEpisodeNumber = mapping.Scene.Episode;
|
||||||
episodesToUpdate.Add(episode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Trace("Committing scene numbering mappings to database for: {0}", series);
|
_episodeService.UpdateEpisodes(episodes);
|
||||||
_episodeService.UpdateEpisodes(episodesToUpdate);
|
|
||||||
|
|
||||||
_logger.Trace("Setting UseSceneMapping for {0}", series);
|
|
||||||
series.UseSceneNumbering = true;
|
series.UseSceneNumbering = true;
|
||||||
_seriesService.UpdateSeries(series);
|
_seriesService.UpdateSeries(series);
|
||||||
}
|
|
||||||
|
|
||||||
|
_logger.Debug("XEM mapping updated for {0}", series);
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Error updating scene numbering mappings for: " + series, ex);
|
_logger.ErrorException("Error updating scene numbering mappings for: " + series, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<int> GetXemSeriesIds()
|
private void RefreshCache()
|
||||||
{
|
{
|
||||||
_cache.Clear();
|
_cache.Clear();
|
||||||
|
|
||||||
|
@ -141,10 +107,8 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
||||||
|
|
||||||
foreach (var id in ids)
|
foreach (var id in ids)
|
||||||
{
|
{
|
||||||
_cache.Set(id.ToString(), true);
|
_cache.Set(id.ToString(), true, TimeSpan.FromHours(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ids;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ namespace NzbDrone.Core.Jobs
|
||||||
var defaultTasks = new[]
|
var defaultTasks = new[]
|
||||||
{
|
{
|
||||||
new ScheduledTask{ Interval = _configService.RssSyncInterval, TypeName = typeof(RssSyncCommand).FullName},
|
new ScheduledTask{ Interval = _configService.RssSyncInterval, TypeName = typeof(RssSyncCommand).FullName},
|
||||||
new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappingsCommand).FullName},
|
|
||||||
new ScheduledTask{ Interval = 12*60, TypeName = typeof(RefreshSeriesCommand).FullName},
|
new ScheduledTask{ Interval = 12*60, TypeName = typeof(RefreshSeriesCommand).FullName},
|
||||||
new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).FullName},
|
new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).FullName},
|
||||||
new ScheduledTask{ Interval = 60, TypeName = typeof(ApplicationUpdateCommand).FullName},
|
new ScheduledTask{ Interval = 60, TypeName = typeof(ApplicationUpdateCommand).FullName},
|
||||||
|
|
|
@ -139,7 +139,6 @@
|
||||||
<Compile Include="DataAugmentation\Xem\Model\XemResult.cs" />
|
<Compile Include="DataAugmentation\Xem\Model\XemResult.cs" />
|
||||||
<Compile Include="DataAugmentation\Xem\Model\XemSceneTvdbMapping.cs" />
|
<Compile Include="DataAugmentation\Xem\Model\XemSceneTvdbMapping.cs" />
|
||||||
<Compile Include="DataAugmentation\Xem\Model\XemValues.cs" />
|
<Compile Include="DataAugmentation\Xem\Model\XemValues.cs" />
|
||||||
<Compile Include="DataAugmentation\Xem\UpdateXemMappingsCommand.cs" />
|
|
||||||
<Compile Include="DataAugmentation\Xem\XemProxy.cs" />
|
<Compile Include="DataAugmentation\Xem\XemProxy.cs" />
|
||||||
<Compile Include="DataAugmentation\Xem\XemService.cs" />
|
<Compile Include="DataAugmentation\Xem\XemService.cs" />
|
||||||
<Compile Include="Datastore\ConnectionStringFactory.cs" />
|
<Compile Include="Datastore\ConnectionStringFactory.cs" />
|
||||||
|
|
Loading…
Reference in New Issue