mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-03 05:25:10 +00:00
Renaming fixes, extension will be used now.
Removing EpisodeFile from DB now works.
This commit is contained in:
parent
a950a13c30
commit
3b749a39a7
4 changed files with 25 additions and 12 deletions
|
@ -109,7 +109,7 @@ public void CleanUp(List<EpisodeFile> files)
|
||||||
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 @@ public void RenameAll()
|
||||||
{
|
{
|
||||||
//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 @@ public void RenameSeries(int seriesId)
|
||||||
//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 @@ public void RenameSeason(int seasonId)
|
||||||
//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 @@ public void RenameEpisode(int episodeId)
|
||||||
//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 @@ private void RenameFile(EpisodeRenameModel erm)
|
||||||
//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 @@ private string GetNewName(EpisodeRenameModel erm)
|
||||||
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 @@ public ActionResult RenameAll()
|
||||||
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 @@ public ActionResult RenameEpisode(int episodeId)
|
||||||
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…
Reference in a new issue