From 3b18c9f621a66ce13140d477c92f75af69b74e31 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Fri, 24 Feb 2012 18:01:53 -0800 Subject: [PATCH] Removed single episode rename button Fix: while renaming series/seasons a single failure no longer stops the whole process Fix: much better notification during batch rename --- NzbDrone.Core/CentralDispatch.cs | 1 - NzbDrone.Core/Jobs/DeleteSeriesJob.cs | 18 ++---- NzbDrone.Core/Jobs/RenameEpisodeJob.cs | 56 ------------------- NzbDrone.Core/Jobs/RenameSeasonJob.cs | 25 ++++++--- NzbDrone.Core/Jobs/RenameSeriesJob.cs | 24 ++++++-- NzbDrone.Core/NzbDrone.Core.csproj | 1 - NzbDrone.Core/Providers/EpisodeProvider.cs | 45 ++++----------- .../NzbDrone.Services.Service.csproj | 2 +- NzbDrone.Web/Controllers/EpisodeController.cs | 9 +-- NzbDrone.Web/Controllers/SeriesController.cs | 1 - NzbDrone.Web/Models/EpisodeModel.cs | 1 - NzbDrone.Web/Views/Series/Episode.cshtml | 1 - 12 files changed, 55 insertions(+), 129 deletions(-) delete mode 100644 NzbDrone.Core/Jobs/RenameEpisodeJob.cs diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 46b103de6..7d21015ef 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -113,7 +113,6 @@ namespace NzbDrone.Core Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); - Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); diff --git a/NzbDrone.Core/Jobs/DeleteSeriesJob.cs b/NzbDrone.Core/Jobs/DeleteSeriesJob.cs index a30aa83ea..b02108ab0 100644 --- a/NzbDrone.Core/Jobs/DeleteSeriesJob.cs +++ b/NzbDrone.Core/Jobs/DeleteSeriesJob.cs @@ -36,23 +36,15 @@ namespace NzbDrone.Core.Jobs private void DeleteSeries(ProgressNotification notification, int seriesId) { - Logger.Warn("Deleting Series [{0}]", seriesId); + Logger.Trace("Deleting Series [{0}]", seriesId); - try - { - var title = _seriesProvider.GetSeries(seriesId).Title; + var title = _seriesProvider.GetSeries(seriesId).Title; - notification.CurrentMessage = String.Format("Deleting '{0}' from database", title); + notification.CurrentMessage = String.Format("Deleting '{0}' from database", title); - _seriesProvider.DeleteSeries(seriesId); + _seriesProvider.DeleteSeries(seriesId); - notification.CurrentMessage = String.Format("Successfully deleted '{0}' from database", title); - } - catch (Exception e) - { - Logger.ErrorException("An error has occurred while deleting series: " + seriesId, e); - throw; - } + notification.CurrentMessage = String.Format("Successfully deleted '{0}' from database", title); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/RenameEpisodeJob.cs b/NzbDrone.Core/Jobs/RenameEpisodeJob.cs deleted file mode 100644 index 8fbf1b72f..000000000 --- a/NzbDrone.Core/Jobs/RenameEpisodeJob.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Linq; -using System; -using Ninject; -using NLog; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -namespace NzbDrone.Core.Jobs -{ - public class RenameEpisodeJob : IJob - { - private readonly DiskScanProvider _diskScanProvider; - private readonly MediaFileProvider _mediaFileProvider; - private readonly ExternalNotificationProvider _externalNotificationProvider; - private readonly SeriesProvider _seriesProvider; - - - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - [Inject] - public RenameEpisodeJob(DiskScanProvider diskScanProvider, MediaFileProvider mediaFileProvider, - ExternalNotificationProvider externalNotificationProvider, SeriesProvider seriesProvider) - { - _diskScanProvider = diskScanProvider; - _mediaFileProvider = mediaFileProvider; - _externalNotificationProvider = externalNotificationProvider; - _seriesProvider = seriesProvider; - } - - public string Name - { - get { return "Rename Episode"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromTicks(0); } - } - - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) - { - if (targetId <= 0) - throw new ArgumentOutOfRangeException("targetId"); - - var episode = _mediaFileProvider.GetEpisodeFile(targetId); - _diskScanProvider.MoveEpisodeFile(episode); - - //Start AfterRename - var series = _seriesProvider.GetSeries(episode.SeriesId); - var message = String.Format("Renamed: Series {0}, Season: {1}", series.Title, secondaryTargetId); - _externalNotificationProvider.AfterRename(message, series); - - notification.CurrentMessage = String.Format("Episode rename completed for: {0} ", targetId); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/RenameSeasonJob.cs b/NzbDrone.Core/Jobs/RenameSeasonJob.cs index 002b6366d..39fc70ebb 100644 --- a/NzbDrone.Core/Jobs/RenameSeasonJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeasonJob.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Jobs private readonly ExternalNotificationProvider _externalNotificationProvider; private readonly SeriesProvider _seriesProvider; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); [Inject] public RenameSeasonJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, @@ -44,26 +44,37 @@ namespace NzbDrone.Core.Jobs if (secondaryTargetId <= 0) throw new ArgumentOutOfRangeException("secondaryTargetId"); - Logger.Debug("Getting episodes from database for series: {0} and season: {1}", targetId, secondaryTargetId); + var series = _seriesProvider.GetSeries(targetId); + + notification.CurrentMessage = String.Format("Renaming episodes for {0} Season {1}", series.Title, secondaryTargetId); + + logger.Debug("Getting episodes from database for series: {0} and season: {1}", targetId, secondaryTargetId); var episodeFiles = _mediaFileProvider.GetSeasonFiles(targetId, secondaryTargetId); - if (episodeFiles == null || episodeFiles.Count == 0) + if (episodeFiles == null || !episodeFiles.Any()) { - Logger.Warn("No episodes in database found for series: {0} and season: {1}.", targetId, secondaryTargetId); + logger.Warn("No episodes in database found for series: {0} and season: {1}.", targetId, secondaryTargetId); return; } foreach (var episodeFile in episodeFiles) { - _diskScanProvider.MoveEpisodeFile(episodeFile); + try + { + _diskScanProvider.MoveEpisodeFile(episodeFile); + } + catch (Exception exception) + { + logger.WarnException("An error has occurred while renaming file", exception); + } } //Start AfterRename - var series = _seriesProvider.GetSeries(targetId); + var message = String.Format("Renamed: Series {0}, Season: {1}", series.Title, secondaryTargetId); _externalNotificationProvider.AfterRename(message, series); - notification.CurrentMessage = String.Format("Season rename completed for Series: {0} Season: {1}", targetId, secondaryTargetId); + notification.CurrentMessage = String.Format("Rename completed for {0} Season {1}", series.Title, secondaryTargetId); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/RenameSeriesJob.cs b/NzbDrone.Core/Jobs/RenameSeriesJob.cs index 42bef481f..e11f744ff 100644 --- a/NzbDrone.Core/Jobs/RenameSeriesJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeriesJob.cs @@ -41,26 +41,38 @@ namespace NzbDrone.Core.Jobs if (targetId <= 0) throw new ArgumentOutOfRangeException("targetId"); - Logger.Debug("Getting episodes from database for series: {0}", targetId); - var episodeFiles = _mediaFileProvider.GetSeriesFiles(targetId); + var series = _seriesProvider.GetSeries(targetId); + + notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title); + + Logger.Debug("Getting episodes from database for series: {0}", series.SeriesId); + var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.SeriesId); if (episodeFiles == null || episodeFiles.Count == 0) { - Logger.Warn("No episodes in database found for series: {0}", targetId); + Logger.Warn("No episodes in database found for series: {0}", series.SeriesId); return; } foreach (var episodeFile in episodeFiles) { - _diskScanProvider.MoveEpisodeFile(episodeFile); + try + { + _diskScanProvider.MoveEpisodeFile(episodeFile); + } + catch(Exception e) + { + Logger.WarnException("An error has occurred while renaming file", e); + } + } //Start AfterRename - var series = _seriesProvider.GetSeries(targetId); + var message = String.Format("Renamed: Series {0}", series.Title); _externalNotificationProvider.AfterRename(message, series); - notification.CurrentMessage = String.Format("Series rename completed for Series: {0}", targetId); + notification.CurrentMessage = String.Format("Rename completed for {0}", series.Title); } } } \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 3790eed2d..5428703b6 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -286,7 +286,6 @@ - diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index df0886a6b..7fb0e9768 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -271,7 +271,7 @@ namespace NzbDrone.Core.Providers public virtual void RefreshEpisodeInfo(Series series) { - logger.Info("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); + logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); int successCount = 0; int failCount = 0; var tvDbSeriesInfo = _tvDbProvider.GetSeries(series.SeriesId, true); @@ -347,10 +347,16 @@ namespace NzbDrone.Core.Providers _database.InsertMany(newList); _database.UpdateMany(updateList); - logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", - tvDbSeriesInfo.SeriesName, successCount, failCount); - - //DeleteEpisodesNotInTvdb + if (failCount != 0) + { + logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", + tvDbSeriesInfo.SeriesName, successCount, failCount); + } + else + { + logger.Info("Finished episode refresh for series: {0}.", tvDbSeriesInfo.SeriesName); + } + DeleteEpisodesNotInTvdb(series, tvDbSeriesInfo); } @@ -359,35 +365,6 @@ namespace NzbDrone.Core.Providers _database.Update(episode); } - public virtual bool IsIgnored(int seriesId, int seasonNumber) - { - var episodes = _database.Fetch(@"SELECT * FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber); - - if (episodes == null || episodes.Count == 0) - { - if (seasonNumber == 0) - return true; - - //Don't check for a previous season if season is 1 - if (seasonNumber == 1) - return false; - - //else - var lastSeasonsEpisodes = _database.Fetch(@"SELECT * FROM Episodes - WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber - 1); - - if (lastSeasonsEpisodes != null && lastSeasonsEpisodes.Any() && lastSeasonsEpisodes.Count == lastSeasonsEpisodes.Count(e => e.Ignored)) - return true; - - return false; - } - - if (episodes.Count == episodes.Count(e => e.Ignored)) - return true; - - return false; - } - public virtual IList GetSeasons(int seriesId) { return _database.Fetch("SELECT DISTINCT SeasonNumber FROM Episodes WHERE SeriesId=@0", seriesId).OrderBy(c => c).ToList(); diff --git a/NzbDrone.Services/NzbDrone.Services.Service/NzbDrone.Services.Service.csproj b/NzbDrone.Services/NzbDrone.Services.Service/NzbDrone.Services.Service.csproj index b63666b39..cfb8153fc 100644 --- a/NzbDrone.Services/NzbDrone.Services.Service/NzbDrone.Services.Service.csproj +++ b/NzbDrone.Services/NzbDrone.Services.Service/NzbDrone.Services.Service.csproj @@ -158,7 +158,7 @@ False True - 1542 + 62182 / http://localhost:1542/ False diff --git a/NzbDrone.Web/Controllers/EpisodeController.cs b/NzbDrone.Web/Controllers/EpisodeController.cs index 8b27a5e6a..11eb0c52e 100644 --- a/NzbDrone.Web/Controllers/EpisodeController.cs +++ b/NzbDrone.Web/Controllers/EpisodeController.cs @@ -1,4 +1,5 @@ -using System.Web.Mvc; +using System; +using System.Web.Mvc; using NzbDrone.Core.Jobs; using NzbDrone.Web.Models; @@ -33,12 +34,6 @@ namespace NzbDrone.Web.Controllers return JsonNotificationResult.Info("Queued"); } - public JsonResult Rename(int episodeFileId) - { - _jobProvider.QueueJob(typeof(RenameEpisodeJob), episodeFileId); - return JsonNotificationResult.Info("Queued"); - } - public JsonResult RenameSeason(int seriesId, int seasonNumber) { _jobProvider.QueueJob(typeof(RenameSeasonJob), seriesId, seasonNumber); diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 72eca3389..b0244ffb8 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -237,7 +237,6 @@ namespace NzbDrone.Web.Controllers Overview = e.Overview, AirDate = airDate, Path = episodePath, - EpisodeFileId = episodeFileId, Status = e.Status.ToString(), Quality = episodeQuality, Ignored = e.Ignored diff --git a/NzbDrone.Web/Models/EpisodeModel.cs b/NzbDrone.Web/Models/EpisodeModel.cs index 867066f99..b89f6c6ac 100644 --- a/NzbDrone.Web/Models/EpisodeModel.cs +++ b/NzbDrone.Web/Models/EpisodeModel.cs @@ -7,7 +7,6 @@ namespace NzbDrone.Web.Models { public string Title { get; set; } public int EpisodeId { get; set; } - public int EpisodeFileId { get; set; } public int EpisodeNumber { get; set; } public int SeasonNumber { get; set; } public string Overview { get; set; } diff --git a/NzbDrone.Web/Views/Series/Episode.cshtml b/NzbDrone.Web/Views/Series/Episode.cshtml index f26d0b906..9cd2a7127 100644 --- a/NzbDrone.Web/Views/Series/Episode.cshtml +++ b/NzbDrone.Web/Views/Series/Episode.cshtml @@ -27,7 +27,6 @@ @Model.Status @Ajax.ImageActionLink("../../Content/Images/Search.png", new { Alt = "Search", Title = "Search for episode", @class = "gridImage" }, "Search", "Episode", new { episodeId = Model.EpisodeId }, null, null) - @Ajax.ImageActionLink("../../Content/Images/Rename.png", new { Alt = "Rename", Title = "Rename episode", @class = "gridImage" }, "Rename", "Episode", new { episodeFileId = Model.EpisodeFileId }, null, null)