From f582457ddce0136384a159436dc34aaf67d0ad61 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 26 May 2011 18:46:00 -0700 Subject: [PATCH 1/3] EpisodesWithoutFiles will now only return episodes where the series and season are monitored. --- NzbDrone.Core/Providers/EpisodeProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index bcb2a8968..a1cebd493 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -65,9 +65,9 @@ namespace NzbDrone.Core.Providers public virtual IList EpisodesWithoutFiles(bool includeSpecials) { if (includeSpecials) - return _repository.All().Where(e => e.EpisodeFileId == 0 && e.AirDate <= DateTime.Today).ToList(); + return _repository.All().Where(e => e.EpisodeFileId == 0 && e.AirDate <= DateTime.Today && e.Series.Monitored && e.Season.Monitored).ToList(); - return _repository.All().Where(e => e.EpisodeFileId == 0 && e.AirDate <= DateTime.Today && e.SeasonNumber > 0).ToList(); + return _repository.All().Where(e => e.EpisodeFileId == 0 && e.AirDate <= DateTime.Today && e.SeasonNumber > 0 && e.Series.Monitored && e.Season.Monitored).ToList(); } /// From 463881843ecdb98f5dca12847d84c9cc45820d66 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 28 May 2011 00:16:16 -0700 Subject: [PATCH 2/3] Combined AddNew and AddExisting Series pages. Fixed AddNew Series --- NzbDrone.Core/Helpers/EpisodeRenameHelper.cs | 12 ++ .../Controllers/AddSeriesController.cs | 52 +++++-- NzbDrone.Web/Models/RootDirModel.cs | 13 ++ NzbDrone.Web/NzbDrone.Web.csproj | 6 +- NzbDrone.Web/Views/AddSeries/Add.cshtml | 65 ++++++++ .../Views/AddSeries/AddExisting.cshtml | 35 ----- NzbDrone.Web/Views/AddSeries/AddNew.cshtml | 145 +++++++----------- NzbDrone.Web/Views/Series/SubMenu.cshtml | 15 +- NzbDrone.Web/Views/Settings/Test.cshtml | 59 +------ 9 files changed, 193 insertions(+), 209 deletions(-) create mode 100644 NzbDrone.Web/Models/RootDirModel.cs create mode 100644 NzbDrone.Web/Views/AddSeries/Add.cshtml delete mode 100644 NzbDrone.Web/Views/AddSeries/AddExisting.cshtml diff --git a/NzbDrone.Core/Helpers/EpisodeRenameHelper.cs b/NzbDrone.Core/Helpers/EpisodeRenameHelper.cs index f401c221a..d02781b55 100644 --- a/NzbDrone.Core/Helpers/EpisodeRenameHelper.cs +++ b/NzbDrone.Core/Helpers/EpisodeRenameHelper.cs @@ -55,5 +55,17 @@ namespace NzbDrone.Core.Helpers return String.Format("{0} - S{1:00}E{2} - {3}", erm.SeriesName, erm.EpisodeFile.Episodes[0].SeasonNumber, epNumberString, epNameString); } + + public static string CleanFilename(string name) + { + string result = name; + string[] badCharacters = {"\\", "/", "<", ">", "?", "*", ":", "|", "\""}; + string[] goodCharacters = {"+", "+", "{", "}", "!", "@", "-", "#", "`"}; + + for (int i = 0; i < badCharacters.Length; i++) + result = result.Replace(badCharacters[i], goodCharacters[i]); + + return result.Trim(); + } } } \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index b957ff317..e2ad88b50 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Web.Mvc; +using System.Linq; +using NzbDrone.Core.Helpers; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Jobs; @@ -18,11 +20,13 @@ namespace NzbDrone.Web.Controllers private readonly JobProvider _jobProvider; private readonly SyncProvider _syncProvider; private readonly TvDbProvider _tvDbProvider; + private readonly DiskProvider _diskProvider; public AddSeriesController(SyncProvider syncProvider, RootDirProvider rootFolderProvider, ConfigProvider configProvider, QualityProvider qualityProvider, TvDbProvider tvDbProvider, - SeriesProvider seriesProvider, JobProvider jobProvider) + SeriesProvider seriesProvider, JobProvider jobProvider, + DiskProvider diskProvider) { _syncProvider = syncProvider; _rootFolderProvider = rootFolderProvider; @@ -31,6 +35,7 @@ namespace NzbDrone.Web.Controllers _tvDbProvider = tvDbProvider; _seriesProvider = seriesProvider; _jobProvider = jobProvider; + _diskProvider = diskProvider; } [HttpPost] @@ -42,25 +47,28 @@ namespace NzbDrone.Web.Controllers public ActionResult AddNew() { - ViewData["RootDirs"] = _rootFolderProvider.GetAll(); - ViewData["DirSep"] = Path.DirectorySeparatorChar; + var rootDirs =_rootFolderProvider.GetAll().Select(r => + new RootDirModel + { + Path = r.Path, + CleanPath = r.Path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`') + }).ToList(); + ViewData["RootDirs"] = rootDirs; + ViewData["DirSep"] = Path.DirectorySeparatorChar.ToString().Replace(Path.DirectorySeparatorChar, '|'); - var profiles = _qualityProvider.GetAllProfiles(); - var selectList = new SelectList(profiles, "QualityProfileId", "Name"); - var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile); + var defaultQuality = _configProvider.DefaultQualityProfile; + var qualityProfiles = _qualityProvider.GetAllProfiles(); - var model = new AddNewSeriesModel - { - DirectorySeparatorChar = Path.DirectorySeparatorChar.ToString(), - RootDirectories = _rootFolderProvider.GetAll(), - QualityProfileId = defaultQuality, - QualitySelectList = selectList - }; + ViewData["quality"] = new SelectList( + qualityProfiles, + "QualityProfileId", + "Name", + defaultQuality); - return View(model); + return View(); } - public ActionResult AddExisting() + public ActionResult Add() { var unmappedList = new List(); @@ -98,6 +106,20 @@ namespace NzbDrone.Web.Controllers return PartialView("AddSeriesItem", suggestions); } + [HttpPost] + public JsonResult AddNewSeries(string rootPath, string seriesName, int seriesId, int qualityProfileId) + { + var path = rootPath.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace('`', '\'') + + Path.DirectorySeparatorChar + EpisodeRenameHelper.CleanFilename(seriesName); + + //Create the folder for the new series and then Add it + _diskProvider.CreateDirectory(path); + + _seriesProvider.AddSeries(path, seriesId, qualityProfileId); + ScanNewSeries(); + return new JsonResult { Data = "ok" }; + } + public JsonResult AddSeries(string path, int seriesId, int qualityProfileId) { //Get TVDB Series Name diff --git a/NzbDrone.Web/Models/RootDirModel.cs b/NzbDrone.Web/Models/RootDirModel.cs new file mode 100644 index 000000000..b3c231f9d --- /dev/null +++ b/NzbDrone.Web/Models/RootDirModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace NzbDrone.Web.Models +{ + public class RootDirModel + { + public string Path { get; set; } + public string CleanPath { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index c827a14fb..b5034d831 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -237,6 +237,7 @@ + @@ -662,7 +663,7 @@ - + @@ -870,6 +871,9 @@ + + +