mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 01:37:07 +00:00
Added job for updating XEM mappings
XEM mappings will also be updated when a new series is imported
This commit is contained in:
parent
7b5d57d224
commit
5cd9438939
4 changed files with 109 additions and 32 deletions
|
@ -137,6 +137,7 @@ namespace NzbDrone.Core
|
|||
Kernel.Bind<IJob>().To<RefreshEpisodeMetadata>().InSingletonScope();
|
||||
Kernel.Bind<IJob>().To<CleanupRecycleBinJob>().InSingletonScope();
|
||||
Kernel.Bind<IJob>().To<EmptyRecycleBinJob>().InSingletonScope();
|
||||
Kernel.Bind<IJob>().To<XemUpdateJob>().InSingletonScope();
|
||||
|
||||
Kernel.Get<JobProvider>().Initialize();
|
||||
Kernel.Get<WebTimer>().StartTimer(30);
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace NzbDrone.Core.Jobs
|
|||
private readonly DiskScanJob _diskScanJob;
|
||||
private readonly BannerDownloadJob _bannerDownloadJob;
|
||||
private readonly SeasonProvider _seasonProvider;
|
||||
private readonly XemUpdateJob _xemUpdateJob;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
@ -30,7 +31,8 @@ namespace NzbDrone.Core.Jobs
|
|||
[Inject]
|
||||
public ImportNewSeriesJob(SeriesProvider seriesProvider, EpisodeProvider episodeProvider,
|
||||
MediaFileProvider mediaFileProvider, UpdateInfoJob updateInfoJob,
|
||||
DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob,SeasonProvider seasonProvider)
|
||||
DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob,
|
||||
SeasonProvider seasonProvider, XemUpdateJob xemUpdateJob)
|
||||
{
|
||||
_seriesProvider = seriesProvider;
|
||||
_episodeProvider = episodeProvider;
|
||||
|
@ -39,6 +41,7 @@ namespace NzbDrone.Core.Jobs
|
|||
_diskScanJob = diskScanJob;
|
||||
_bannerDownloadJob = bannerDownloadJob;
|
||||
_seasonProvider = seasonProvider;
|
||||
_xemUpdateJob = xemUpdateJob;
|
||||
}
|
||||
|
||||
public string Name
|
||||
|
@ -81,6 +84,9 @@ namespace NzbDrone.Core.Jobs
|
|||
//Download the banner for the new series
|
||||
_bannerDownloadJob.Start(notification, updatedSeries.SeriesId, 0);
|
||||
|
||||
//Get Scene Numbering if applicable
|
||||
_xemUpdateJob.Start(notification, updatedSeries.SeriesId, 0);
|
||||
|
||||
notification.CurrentMessage = String.Format("{0} was successfully imported", updatedSeries.Title);
|
||||
}
|
||||
|
||||
|
|
52
NzbDrone.Core/Jobs/XemUpdateJob.cs
Normal file
52
NzbDrone.Core/Jobs/XemUpdateJob.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Ninject;
|
||||
using NzbDrone.Core.Helpers;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
public class XemUpdateJob : IJob
|
||||
{
|
||||
private readonly XemProvider _xemProvider;
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[Inject]
|
||||
public XemUpdateJob(XemProvider xemProvider)
|
||||
{
|
||||
_xemProvider = xemProvider;
|
||||
}
|
||||
|
||||
public XemUpdateJob()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "XEM Update"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromHours(12); }
|
||||
}
|
||||
|
||||
public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
||||
{
|
||||
if (targetId == 0)
|
||||
{
|
||||
_logger.Trace("Starting XEM Update for all series");
|
||||
_xemProvider.UpdateMappings();
|
||||
}
|
||||
_logger.Trace("Starting XEM Update for series: {0}", targetId);
|
||||
_xemProvider.UpdateMappings(targetId);
|
||||
_logger.Trace("XEM Update complete");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -40,37 +40,7 @@ namespace NzbDrone.Core.Providers
|
|||
|
||||
foreach(var ser in wantedSeries)
|
||||
{
|
||||
_logger.Trace("Updating scene numbering mapping for: {0}", ser.Title);
|
||||
try
|
||||
{
|
||||
var episodesToUpdate = new List<Episode>();
|
||||
var mappings = _xemCommunicationProvider.GetSceneTvdbMappings(ser.SeriesId);
|
||||
|
||||
if (mappings == null)
|
||||
{
|
||||
_logger.Trace("Mappings for: {0} are null, skipping", ser.Title);
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach(var mapping in mappings)
|
||||
{
|
||||
_logger.Trace("Setting scene numbering mappings for {0} S{1:00}E{2:00}", ser.Title, mapping.Tvdb.Season, mapping.Tvdb.Episode);
|
||||
|
||||
var episode = _episodeProvider.GetEpisode(ser.SeriesId, mapping.Tvdb.Season, mapping.Tvdb.Episode);
|
||||
episode.AbsoluteEpisodeNumber = mapping.Scene.Absolute;
|
||||
episode.SceneSeasonNumber = mapping.Scene.Season;
|
||||
episode.SceneEpisodeNumber = mapping.Scene.Episode;
|
||||
episodesToUpdate.Add(episode);
|
||||
}
|
||||
|
||||
_logger.Trace("Committing scene numbering mappings to database for: {0}", ser.Title);
|
||||
_episodeProvider.UpdateEpisodes(episodesToUpdate);
|
||||
}
|
||||
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.WarnException("Error updating scene numbering mappings for: " + ser, ex);
|
||||
}
|
||||
PerformUpdate(ser);
|
||||
}
|
||||
|
||||
_logger.Trace("Completed scene numbering update");
|
||||
|
@ -82,5 +52,53 @@ namespace NzbDrone.Core.Providers
|
|||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void UpdateMappings(int seriesId)
|
||||
{
|
||||
var series = _seriesProvider.GetSeries(seriesId);
|
||||
|
||||
if (series == null)
|
||||
{
|
||||
_logger.Trace("Series could not be found: {0}", seriesId);
|
||||
return;
|
||||
}
|
||||
|
||||
PerformUpdate(series);
|
||||
}
|
||||
|
||||
public virtual void PerformUpdate(Series series)
|
||||
{
|
||||
_logger.Trace("Updating scene numbering mapping for: {0}", series.Title);
|
||||
try
|
||||
{
|
||||
var episodesToUpdate = new List<Episode>();
|
||||
var mappings = _xemCommunicationProvider.GetSceneTvdbMappings(series.SeriesId);
|
||||
|
||||
if (mappings == null)
|
||||
{
|
||||
_logger.Trace("Mappings for: {0} are null, skipping", series.Title);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var mapping in mappings)
|
||||
{
|
||||
_logger.Trace("Setting scene numbering mappings for {0} S{1:00}E{2:00}", series.Title, mapping.Tvdb.Season, mapping.Tvdb.Episode);
|
||||
|
||||
var episode = _episodeProvider.GetEpisode(series.SeriesId, mapping.Tvdb.Season, mapping.Tvdb.Episode);
|
||||
episode.AbsoluteEpisodeNumber = mapping.Scene.Absolute;
|
||||
episode.SceneSeasonNumber = mapping.Scene.Season;
|
||||
episode.SceneEpisodeNumber = mapping.Scene.Episode;
|
||||
episodesToUpdate.Add(episode);
|
||||
}
|
||||
|
||||
_logger.Trace("Committing scene numbering mappings to database for: {0}", series.Title);
|
||||
_episodeProvider.UpdateEpisodes(episodesToUpdate);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException("Error updating scene numbering mappings for: " + series, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue