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
This commit is contained in:
kay.one 2012-02-24 18:01:53 -08:00
parent 4e49ceb640
commit 3b18c9f621
12 changed files with 55 additions and 129 deletions

View File

@ -113,7 +113,6 @@ namespace NzbDrone.Core
Kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
Kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
Kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
Kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
Kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
Kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
Kernel.Bind<IJob>().To<SeasonSearchJob>().InSingletonScope();

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -286,7 +286,6 @@
<Compile Include="Model\Xbmc\VersionResult.cs" />
<Compile Include="Jobs\UpdateSceneMappingsJob.cs" />
<Compile Include="Jobs\PostDownloadScanJob.cs" />
<Compile Include="Jobs\RenameEpisodeJob.cs" />
<Compile Include="Jobs\EpisodeSearchJob.cs" />
<Compile Include="Jobs\DeleteSeriesJob.cs" />
<Compile Include="Jobs\DiskScanJob.cs" />

View File

@ -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<Episode>(@"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<Episode>(@"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<int> GetSeasons(int seriesId)
{
return _database.Fetch<Int32>("SELECT DISTINCT SeasonNumber FROM Episodes WHERE SeriesId=@0", seriesId).OrderBy(c => c).ToList();

View File

@ -158,7 +158,7 @@
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>1542</DevelopmentServerPort>
<DevelopmentServerPort>62182</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:1542/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>

View File

@ -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);

View File

@ -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

View File

@ -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; }

View File

@ -27,7 +27,6 @@
<img src='../../Content/Images/@(Model.Ignored ? "ignored" : "notIgnored").png' class='ignoreEpisode ignoreEpisode_@(Model.SeasonNumber)@(Model.Ignored ? " ignored" : " ") gridImage' id='@Model.EpisodeId' title='Click to toggle episode ignore status' />
<img src='../../Content/Images/@(Model.Status).png' alt='@Model.Status' title='@Model.Status' class='gridImage status-@Model.Status statusImage' />
@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)
</td>
</tr>
<tr class="detail-row@(ViewData["AltRow"] == null || !(bool)ViewData["AltRow"] ? "" : " alt-row")">