1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

New: Rename all series added to Series Editor

This commit is contained in:
Mark McDowall 2012-07-20 21:46:16 -07:00
parent 4ca828db81
commit e5b6f63e6e
4 changed files with 57 additions and 40 deletions

View File

@ -43,55 +43,65 @@ public TimeSpan DefaultInterval
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
{ {
List<Series> seriesToRename;
if (targetId <= 0) if (targetId <= 0)
throw new ArgumentOutOfRangeException("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}", series.SeriesId); seriesToRename = _seriesProvider.GetAllSeries().ToList();
return;
} }
var newEpisodeFiles = new List<EpisodeFile>(); else
var oldEpisodeFiles = new List<EpisodeFile>();
foreach (var episodeFile in episodeFiles)
{ {
try seriesToRename = new List<Series>{ _seriesProvider.GetSeries(targetId) };
{ }
var oldFile = new EpisodeFile(episodeFile);
var newFile = _diskScanProvider.MoveEpisodeFile(episodeFile);
if (newFile != null) foreach(var series in seriesToRename)
{
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}", series.SeriesId);
return;
}
var newEpisodeFiles = new List<EpisodeFile>();
var oldEpisodeFiles = new List<EpisodeFile>();
foreach (var episodeFile in episodeFiles)
{
try
{ {
newEpisodeFiles.Add(newFile); var oldFile = new EpisodeFile(episodeFile);
oldEpisodeFiles.Add(oldFile); var newFile = _diskScanProvider.MoveEpisodeFile(episodeFile);
if (newFile != null)
{
newEpisodeFiles.Add(newFile);
oldEpisodeFiles.Add(oldFile);
}
}
catch (Exception e)
{
Logger.WarnException("An error has occurred while renaming file", e);
} }
} }
catch(Exception e) //Remove & Create Metadata for episode files
{ _metadataProvider.RemoveForEpisodeFiles(oldEpisodeFiles);
Logger.WarnException("An error has occurred while renaming file", e); _metadataProvider.CreateForEpisodeFiles(newEpisodeFiles);
}
//Start AfterRename
var message = String.Format("Renamed: Series {0}", series.Title);
_externalNotificationProvider.AfterRename(message, series);
notification.CurrentMessage = String.Format("Rename completed for {0}", series.Title);
} }
//Remove & Create Metadata for episode files
_metadataProvider.RemoveForEpisodeFiles(oldEpisodeFiles);
_metadataProvider.CreateForEpisodeFiles(newEpisodeFiles);
//Start AfterRename
var message = String.Format("Renamed: Series {0}", series.Title);
_externalNotificationProvider.AfterRename(message, series);
notification.CurrentMessage = String.Format("Rename completed for {0}", series.Title);
} }
} }
} }

View File

@ -41,10 +41,16 @@ public JsonResult RenameSeason(int seriesId, int seasonNumber)
} }
public JsonResult RenameEpisodes(int seriesId) public JsonResult RenameSeries(int seriesId)
{ {
_jobProvider.QueueJob(typeof(RenameSeriesJob), seriesId); _jobProvider.QueueJob(typeof(RenameSeriesJob), seriesId);
return JsonNotificationResult.Queued("Series rename"); return JsonNotificationResult.Queued("Series rename");
} }
public JsonResult RenameAllSeries()
{
_jobProvider.QueueJob(typeof(RenameSeriesJob));
return JsonNotificationResult.Queued("Series rename");
}
} }
} }

View File

@ -72,7 +72,7 @@
<li><a class="editButton" value="@Model.SeriesId" rel="@Model.Title" title="Edit series">Edit</a></li> <li><a class="editButton" value="@Model.SeriesId" rel="@Model.Title" title="Edit series">Edit</a></li>
<li>@Ajax.ActionLink("Force Refresh", "ForceRefresh", "Command", new { seriesId = Model.SeriesId }, null, new { Title = "Refresh episode and series information and scan for new episodes" })</li> <li>@Ajax.ActionLink("Force Refresh", "ForceRefresh", "Command", new { seriesId = Model.SeriesId }, null, new { Title = "Refresh episode and series information and scan for new episodes" })</li>
<li>@Ajax.ActionLink("Search for missing episodes", "BacklogSeries", "Episode", new { seriesId = Model.SeriesId }, null, new { Title = "Search for episodes missing from this series" })</li> <li>@Ajax.ActionLink("Search for missing episodes", "BacklogSeries", "Episode", new { seriesId = Model.SeriesId }, null, new { Title = "Search for episodes missing from this series" })</li>
<li>@Ajax.ActionLink("Rename Episode Files", "RenameEpisodes", "Episode", new { seriesId = Model.SeriesId }, null, new { Title = "Rename all episode files to match your preferred naming" })</li> <li>@Ajax.ActionLink("Rename Episode Files", "RenameSeries", "Episode", new { seriesId = Model.SeriesId }, null, new { Title = "Rename all episode files to match your preferred naming" })</li>
</ul> </ul>
} }

View File

@ -58,6 +58,7 @@
{ {
<ul class="sub-menu"> <ul class="sub-menu">
<li>@Ajax.ActionLink("Force Refresh", "ForceRefreshAll", "Command", null, null, new { Title = "Refresh episode and series information and scan for new episodes for all series" })</li> <li>@Ajax.ActionLink("Force Refresh", "ForceRefreshAll", "Command", null, null, new { Title = "Refresh episode and series information and scan for new episodes for all series" })</li>
<li>@Ajax.ActionLink("Rename All Series", "RenameAllSeries", "Episode", null, new AjaxOptions { Confirm = "Are you sure you want to rename all series?" }, new { Title = "Rename all series monitored by NzbDrone" })</li>
</ul> </ul>
} }