Renaming fixes, extension will be used now.

Removing EpisodeFile from DB now works.
pull/4/head
markus101 14 years ago
parent a950a13c30
commit 3b749a39a7

@ -109,7 +109,7 @@ namespace NzbDrone.Core.Providers
if (!_diskProvider.FileExists(episodeFile.Path)) if (!_diskProvider.FileExists(episodeFile.Path))
{ {
Logger.Trace("File {0} no longer exists on disk. removing from database.", episodeFile.Path); Logger.Trace("File {0} no longer exists on disk. removing from database.", episodeFile.Path);
_repository.Delete<EpisodeFile>(episodeFile); _repository.Delete<EpisodeFile>(episodeFile.EpisodeFileId);
} }
} }
} }

@ -40,14 +40,12 @@ namespace NzbDrone.Core.Providers
{ {
//Get a list of all episode files/episodes and rename them //Get a list of all episode files/episodes and rename them
var seasonFolder = _configProvider.GetValue("SeasonFolder", "Season %s", true);
foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles()) foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles())
{ {
var series = _seriesProvider.GetSeries(episodeFile.SeriesId); var series = _seriesProvider.GetSeries(episodeFile.SeriesId);
var erm = new EpisodeRenameModel(); var erm = new EpisodeRenameModel();
erm.SeriesName = series.Title; erm.SeriesName = series.Title;
erm.Folder = series.Path + Path.DirectorySeparatorChar + seasonFolder; erm.Folder = series.Path + Path.DirectorySeparatorChar + GetSeasonFolder(episodeFile.Episodes[0].SeasonNumber);
erm.EpisodeFile = episodeFile; erm.EpisodeFile = episodeFile;
_epsToRename.Add(erm); _epsToRename.Add(erm);
StartRename(); StartRename();
@ -59,13 +57,12 @@ namespace NzbDrone.Core.Providers
//Get a list of all applicable episode files/episodes and rename them //Get a list of all applicable episode files/episodes and rename them
var series = _seriesProvider.GetSeries(seriesId); var series = _seriesProvider.GetSeries(seriesId);
var seasonFolder = _configProvider.GetValue("SeasonFolder", "Season %s", true);
foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles().Where(s => s.SeriesId == seriesId)) foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles().Where(s => s.SeriesId == seriesId))
{ {
var erm = new EpisodeRenameModel(); var erm = new EpisodeRenameModel();
erm.SeriesName = series.Title; erm.SeriesName = series.Title;
erm.Folder = series.Path + Path.DirectorySeparatorChar + seasonFolder; erm.Folder = series.Path + Path.DirectorySeparatorChar + GetSeasonFolder(episodeFile.Episodes[0].SeasonNumber);
erm.EpisodeFile = episodeFile; erm.EpisodeFile = episodeFile;
_epsToRename.Add(erm); _epsToRename.Add(erm);
StartRename(); StartRename();
@ -77,13 +74,12 @@ namespace NzbDrone.Core.Providers
//Get a list of all applicable episode files/episodes and rename them //Get a list of all applicable episode files/episodes and rename them
var season = _seasonProvider.GetSeason(seasonId); var season = _seasonProvider.GetSeason(seasonId);
var series = _seriesProvider.GetSeries(season.SeriesId); var series = _seriesProvider.GetSeries(season.SeriesId);
var seasonFolder = _configProvider.GetValue("SeasonFolder", "Season %s", true);
foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles().Where(s => s.Episodes[0].SeasonId == seasonId)) foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles().Where(s => s.Episodes[0].SeasonId == seasonId))
{ {
var erm = new EpisodeRenameModel(); var erm = new EpisodeRenameModel();
erm.SeriesName = series.Title; erm.SeriesName = series.Title;
erm.Folder = series.Path + Path.DirectorySeparatorChar + seasonFolder; erm.Folder = series.Path + Path.DirectorySeparatorChar + GetSeasonFolder(episodeFile.Episodes[0].SeasonNumber);
erm.EpisodeFile = episodeFile; erm.EpisodeFile = episodeFile;
_epsToRename.Add(erm); _epsToRename.Add(erm);
StartRename(); StartRename();
@ -95,13 +91,12 @@ namespace NzbDrone.Core.Providers
//This will properly rename multi-episode files if asked to rename either of the episode //This will properly rename multi-episode files if asked to rename either of the episode
var episode = _episodeProvider.GetEpisode(episodeId); var episode = _episodeProvider.GetEpisode(episodeId);
var series = _seriesProvider.GetSeries(episode.SeriesId); var series = _seriesProvider.GetSeries(episode.SeriesId);
var seasonFolder = _configProvider.GetValue("SeasonFolder", "Season %s", true);
var episodeFile = _mediaFileProvider.GetEpisodeFiles().Where(s => s.Episodes.Contains(episode)).FirstOrDefault(); var episodeFile = _mediaFileProvider.GetEpisodeFiles().Where(s => s.Episodes.Contains(episode)).FirstOrDefault();
var erm = new EpisodeRenameModel(); var erm = new EpisodeRenameModel();
erm.SeriesName = series.Title; erm.SeriesName = series.Title;
erm.Folder = series.Path + Path.DirectorySeparatorChar + seasonFolder; erm.Folder = series.Path + Path.DirectorySeparatorChar + GetSeasonFolder(episodeFile.Episodes[0].SeasonNumber);
erm.EpisodeFile = episodeFile; erm.EpisodeFile = episodeFile;
_epsToRename.Add(erm); _epsToRename.Add(erm);
StartRename(); StartRename();
@ -146,7 +141,8 @@ namespace NzbDrone.Core.Providers
//Update EpisodeFile if successful //Update EpisodeFile if successful
Logger.Debug("Renaming Episode: {0}", Path.GetFileName(erm.EpisodeFile.Path)); Logger.Debug("Renaming Episode: {0}", Path.GetFileName(erm.EpisodeFile.Path));
var newName = GetNewName(erm); var newName = GetNewName(erm);
var newFilename = erm.Folder + Path.DirectorySeparatorChar + newName; var ext = Path.GetExtension(erm.EpisodeFile.Path);
var newFilename = erm.Folder + Path.DirectorySeparatorChar + newName + ext;
if (!_diskProvider.FolderExists(erm.Folder)) if (!_diskProvider.FolderExists(erm.Folder))
_diskProvider.CreateDirectory(erm.Folder); _diskProvider.CreateDirectory(erm.Folder);
@ -189,5 +185,12 @@ namespace NzbDrone.Core.Providers
return String.Format("{0} - S{1:00}E{2} - {3}", erm.SeriesName, erm.EpisodeFile.Episodes[0].SeasonNumber, return String.Format("{0} - S{1:00}E{2} - {3}", erm.SeriesName, erm.EpisodeFile.Episodes[0].SeasonNumber,
epNumberString, epNameString); epNumberString, epNameString);
} }
private string GetSeasonFolder(int seasonNumber)
{
return
_configProvider.GetValue("SeasonFolder", "Season %s", true).Replace("%s", seasonNumber.ToString()).
Replace("%0s", seasonNumber.ToString("00"));
}
} }
} }

@ -218,7 +218,7 @@ namespace NzbDrone.Web.Controllers
public ActionResult RenameSeries(int seriesId) public ActionResult RenameSeries(int seriesId)
{ {
_renameProvider.RenameSeries(seriesId); _renameProvider.RenameSeries(seriesId);
return RedirectToAction("Index"); return RedirectToAction("Details", new { seriesId });
} }
public ActionResult RenameSeason(int seasonId) public ActionResult RenameSeason(int seasonId)
@ -235,6 +235,15 @@ namespace NzbDrone.Web.Controllers
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
public ActionResult ReScanFiles(int seriesId)
{
var epFiles = _mediaFileProvider.GetEpisodeFiles().Where(s => s.SeriesId == seriesId).ToList();
_mediaFileProvider.CleanUp(epFiles);
_mediaFileProvider.Scan(_seriesProvider.GetSeries(seriesId));
return RedirectToAction("Details", "Series", new { seriesId });
}
//Local Helpers //Local Helpers
private string GetEpisodePath(EpisodeFile file) private string GetEpisodePath(EpisodeFile file)
{ {

@ -13,6 +13,7 @@
items.Add().Text("Back to Series List").Action("Index", "Series"); items.Add().Text("Back to Series List").Action("Index", "Series");
items.Add().Text("Scan For Episodes on Disk").Action("SyncEpisodesOnDisk", "Series", new { seriesId = Model.SeriesId }); items.Add().Text("Scan For Episodes on Disk").Action("SyncEpisodesOnDisk", "Series", new { seriesId = Model.SeriesId });
items.Add().Text("Rename Series").Action("RenameSeries", "Series", new { seriesId = Model.SeriesId }); items.Add().Text("Rename Series").Action("RenameSeries", "Series", new { seriesId = Model.SeriesId });
items.Add().Text("Re-Scan Files").Action("ReScanFiles", "Series", new { seriesId = Model.SeriesId });
}).Render(); }).Render();
%> %>
</asp:Content> </asp:Content>

Loading…
Cancel
Save