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:
parent
4ca828db81
commit
e5b6f63e6e
@ -43,55 +43,65 @@ public TimeSpan DefaultInterval
|
||||
|
||||
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
||||
{
|
||||
List<Series> seriesToRename;
|
||||
|
||||
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);
|
||||
return;
|
||||
seriesToRename = _seriesProvider.GetAllSeries().ToList();
|
||||
}
|
||||
|
||||
var newEpisodeFiles = new List<EpisodeFile>();
|
||||
var oldEpisodeFiles = new List<EpisodeFile>();
|
||||
|
||||
foreach (var episodeFile in episodeFiles)
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var oldFile = new EpisodeFile(episodeFile);
|
||||
var newFile = _diskScanProvider.MoveEpisodeFile(episodeFile);
|
||||
seriesToRename = new List<Series>{ _seriesProvider.GetSeries(targetId) };
|
||||
}
|
||||
|
||||
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);
|
||||
oldEpisodeFiles.Add(oldFile);
|
||||
var oldFile = new EpisodeFile(episodeFile);
|
||||
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)
|
||||
{
|
||||
Logger.WarnException("An error has occurred while renaming file", e);
|
||||
}
|
||||
//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);
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
return JsonNotificationResult.Queued("Series rename");
|
||||
}
|
||||
|
||||
public JsonResult RenameAllSeries()
|
||||
{
|
||||
_jobProvider.QueueJob(typeof(RenameSeriesJob));
|
||||
return JsonNotificationResult.Queued("Series rename");
|
||||
}
|
||||
}
|
||||
}
|
@ -72,7 +72,7 @@
|
||||
<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("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>
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@
|
||||
{
|
||||
<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("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>
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user