2011-04-01 06:36:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Web.Mvc;
|
2011-05-28 07:16:16 +00:00
|
|
|
|
using System.Linq;
|
2011-05-31 06:13:46 +00:00
|
|
|
|
using NLog;
|
2011-05-28 07:16:16 +00:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2011-04-01 06:36:34 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2011-05-31 06:13:46 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-04-01 06:36:34 +00:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class AddSeriesController : Controller
|
|
|
|
|
{
|
2011-05-31 06:13:46 +00:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-10 01:34:36 +00:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
2011-04-08 04:11:45 +00:00
|
|
|
|
private readonly QualityProvider _qualityProvider;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
private readonly RootDirProvider _rootFolderProvider;
|
2011-04-08 23:55:23 +00:00
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
private readonly TvDbProvider _tvDbProvider;
|
2011-05-28 07:16:16 +00:00
|
|
|
|
private readonly DiskProvider _diskProvider;
|
2011-04-01 06:36:34 +00:00
|
|
|
|
|
2011-06-14 01:23:04 +00:00
|
|
|
|
public AddSeriesController(RootDirProvider rootFolderProvider,
|
2011-04-10 02:44:01 +00:00
|
|
|
|
ConfigProvider configProvider,
|
|
|
|
|
QualityProvider qualityProvider, TvDbProvider tvDbProvider,
|
2011-05-28 07:16:16 +00:00
|
|
|
|
SeriesProvider seriesProvider, JobProvider jobProvider,
|
|
|
|
|
DiskProvider diskProvider)
|
2011-04-01 06:36:34 +00:00
|
|
|
|
{
|
2011-06-14 01:23:04 +00:00
|
|
|
|
|
2011-04-01 06:36:34 +00:00
|
|
|
|
_rootFolderProvider = rootFolderProvider;
|
|
|
|
|
_configProvider = configProvider;
|
|
|
|
|
_qualityProvider = qualityProvider;
|
|
|
|
|
_tvDbProvider = tvDbProvider;
|
|
|
|
|
_seriesProvider = seriesProvider;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
_jobProvider = jobProvider;
|
2011-05-28 07:16:16 +00:00
|
|
|
|
_diskProvider = diskProvider;
|
2011-04-01 06:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult ScanNewSeries()
|
|
|
|
|
{
|
2011-05-21 00:23:49 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(ImportNewSeriesJob));
|
2011-04-01 06:36:34 +00:00
|
|
|
|
return new JsonResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult AddNew()
|
|
|
|
|
{
|
2011-06-14 01:23:04 +00:00
|
|
|
|
var rootDirs = _rootFolderProvider.GetAll().Select(r =>
|
2011-05-28 07:16:16 +00:00
|
|
|
|
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, '|');
|
2011-04-01 06:36:34 +00:00
|
|
|
|
|
2011-05-28 07:16:16 +00:00
|
|
|
|
var defaultQuality = _configProvider.DefaultQualityProfile;
|
|
|
|
|
var qualityProfiles = _qualityProvider.GetAllProfiles();
|
2011-04-01 06:36:34 +00:00
|
|
|
|
|
2011-05-28 07:16:16 +00:00
|
|
|
|
ViewData["quality"] = new SelectList(
|
|
|
|
|
qualityProfiles,
|
|
|
|
|
"QualityProfileId",
|
|
|
|
|
"Name",
|
|
|
|
|
defaultQuality);
|
2011-04-01 06:36:34 +00:00
|
|
|
|
|
2011-05-28 07:16:16 +00:00
|
|
|
|
return View();
|
2011-04-01 06:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 20:50:19 +00:00
|
|
|
|
public ActionResult Index()
|
2011-04-01 06:36:34 +00:00
|
|
|
|
{
|
2011-05-31 20:50:19 +00:00
|
|
|
|
var rootDirs = _rootFolderProvider.GetAll();
|
2011-04-01 06:36:34 +00:00
|
|
|
|
|
2011-04-07 23:49:18 +00:00
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles();
|
|
|
|
|
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
|
|
|
|
|
var selectList = new SelectList(profiles, "QualityProfileId", "Name", defaultQuality);
|
|
|
|
|
ViewData["qualities"] = selectList;
|
2011-06-06 21:31:08 +00:00
|
|
|
|
ViewData["ShowRootDirs"] = false;
|
|
|
|
|
|
|
|
|
|
//There are no RootDirs Show the RootDirs Panel
|
|
|
|
|
if (rootDirs.Count == 0)
|
|
|
|
|
ViewData["ShowRootDirs"] = true;
|
2011-04-07 23:49:18 +00:00
|
|
|
|
|
2011-05-31 20:50:19 +00:00
|
|
|
|
return View(rootDirs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult AddExisting()
|
|
|
|
|
{
|
|
|
|
|
var rootDirs = _rootFolderProvider.GetAll();
|
|
|
|
|
|
|
|
|
|
var unmappedList = new List<String>();
|
|
|
|
|
|
|
|
|
|
foreach (var folder in rootDirs)
|
2011-04-01 06:36:34 +00:00
|
|
|
|
{
|
2011-05-20 03:47:07 +00:00
|
|
|
|
unmappedList.AddRange(_rootFolderProvider.GetUnmappedFolders(folder.Path));
|
2011-04-01 06:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(unmappedList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult RenderPartial(string path)
|
|
|
|
|
{
|
2011-04-01 23:11:09 +00:00
|
|
|
|
var suggestions = GetSuggestionList(new DirectoryInfo(path).Name);
|
2011-04-01 06:36:34 +00:00
|
|
|
|
|
|
|
|
|
ViewData["guid"] = Guid.NewGuid();
|
|
|
|
|
ViewData["path"] = path;
|
2011-04-25 02:30:40 +00:00
|
|
|
|
ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`');
|
2011-04-04 01:31:27 +00:00
|
|
|
|
|
2011-04-05 02:48:46 +00:00
|
|
|
|
var defaultQuality = _configProvider.DefaultQualityProfile;
|
2011-04-04 01:31:27 +00:00
|
|
|
|
var qualityProfiles = _qualityProvider.GetAllProfiles();
|
2011-04-05 02:48:46 +00:00
|
|
|
|
|
2011-04-04 01:31:27 +00:00
|
|
|
|
ViewData["quality"] = new SelectList(
|
|
|
|
|
qualityProfiles,
|
|
|
|
|
"QualityProfileId",
|
|
|
|
|
"Name",
|
2011-04-10 02:44:01 +00:00
|
|
|
|
defaultQuality);
|
2011-04-04 01:31:27 +00:00
|
|
|
|
|
2011-04-01 23:11:09 +00:00
|
|
|
|
return PartialView("AddSeriesItem", suggestions);
|
2011-04-01 06:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-28 07:16:16 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult AddNewSeries(string rootPath, string seriesName, int seriesId, int qualityProfileId)
|
|
|
|
|
{
|
2011-05-31 06:13:46 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var path =
|
|
|
|
|
rootPath.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace(
|
|
|
|
|
'`', '\'') +
|
2011-06-20 23:46:54 +00:00
|
|
|
|
Path.DirectorySeparatorChar + MediaFileProvider.CleanFilename(seriesName);
|
2011-05-28 07:16:16 +00:00
|
|
|
|
|
2011-05-31 06:13:46 +00:00
|
|
|
|
//Create the folder for the new series and then Add it
|
|
|
|
|
_diskProvider.CreateDirectory(path);
|
2011-05-28 07:16:16 +00:00
|
|
|
|
|
2011-05-31 06:13:46 +00:00
|
|
|
|
_seriesProvider.AddSeries(path, seriesId, qualityProfileId);
|
|
|
|
|
ScanNewSeries();
|
2011-06-14 01:23:04 +00:00
|
|
|
|
return new JsonResult { Data = "ok" };
|
2011-05-31 06:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-19 20:43:47 +00:00
|
|
|
|
catch (Exception)
|
2011-05-31 06:13:46 +00:00
|
|
|
|
{
|
|
|
|
|
return new JsonResult { Data = "failed" };
|
|
|
|
|
}
|
2011-05-28 07:16:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 06:36:34 +00:00
|
|
|
|
public JsonResult AddSeries(string path, int seriesId, int qualityProfileId)
|
|
|
|
|
{
|
|
|
|
|
//Get TVDB Series Name
|
|
|
|
|
//Create new folder for series
|
|
|
|
|
//Add the new series to the Database
|
|
|
|
|
|
2011-04-10 02:44:01 +00:00
|
|
|
|
_seriesProvider.AddSeries(
|
2011-04-25 02:30:40 +00:00
|
|
|
|
path.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace('`', '\''), seriesId,
|
2011-04-10 02:44:01 +00:00
|
|
|
|
qualityProfileId);
|
2011-04-01 06:36:34 +00:00
|
|
|
|
ScanNewSeries();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
return new JsonResult { Data = "ok" };
|
2011-04-01 06:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 23:11:09 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult _textLookUp(string text, int? filterMode)
|
|
|
|
|
{
|
|
|
|
|
var suggestions = GetSuggestionList(text);
|
|
|
|
|
|
|
|
|
|
return new JsonResult
|
2011-04-10 02:44:01 +00:00
|
|
|
|
{
|
|
|
|
|
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
|
|
|
|
|
Data = suggestions
|
|
|
|
|
};
|
2011-04-01 23:11:09 +00:00
|
|
|
|
}
|
2011-04-04 01:31:27 +00:00
|
|
|
|
|
2011-04-01 23:11:09 +00:00
|
|
|
|
public SelectList GetSuggestionList(string searchString)
|
|
|
|
|
{
|
|
|
|
|
var dataVal = _tvDbProvider.SearchSeries(searchString);
|
|
|
|
|
|
2011-04-10 01:34:36 +00:00
|
|
|
|
int selectId = 0;
|
|
|
|
|
if (dataVal.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
selectId = dataVal[0].Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new SelectList(dataVal, "Id", "SeriesName", selectId);
|
2011-04-01 23:11:09 +00:00
|
|
|
|
}
|
2011-05-31 06:13:46 +00:00
|
|
|
|
|
2011-06-09 01:45:06 +00:00
|
|
|
|
//Root Directory
|
2011-05-31 06:13:46 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult SaveRootDir(int id, string path)
|
|
|
|
|
{
|
2011-06-16 02:32:55 +00:00
|
|
|
|
if (String.IsNullOrWhiteSpace(path))
|
|
|
|
|
return new JsonResult { Data = "failed" };
|
|
|
|
|
|
2011-05-31 06:13:46 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2011-06-16 02:32:55 +00:00
|
|
|
|
if (id == 0)
|
|
|
|
|
id = _rootFolderProvider.Add(new RootDir { Path = path });
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
_rootFolderProvider.Update(new RootDir { Id = id, Path = path });
|
2011-05-31 06:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Failed to save Root Dir");
|
|
|
|
|
Logger.DebugException(ex.Message, ex);
|
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = "failed" };
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 02:32:55 +00:00
|
|
|
|
return new JsonResult { Data = id };
|
2011-05-31 06:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-09 01:45:06 +00:00
|
|
|
|
public PartialViewResult AddRootDir()
|
2011-05-31 06:13:46 +00:00
|
|
|
|
{
|
2011-06-16 02:32:55 +00:00
|
|
|
|
var model = new RootDirModel
|
|
|
|
|
{
|
|
|
|
|
Id = 0,
|
|
|
|
|
Path = "",
|
|
|
|
|
SelectList = new SelectList(new List<string> { "" }, "")
|
|
|
|
|
};
|
2011-05-31 06:13:46 +00:00
|
|
|
|
|
2011-06-16 02:32:55 +00:00
|
|
|
|
ViewData["guid"] = Guid.NewGuid();
|
2011-05-31 06:13:46 +00:00
|
|
|
|
|
2011-06-09 01:45:06 +00:00
|
|
|
|
return PartialView("RootDir", model);
|
2011-05-31 06:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult GetRootDirView(RootDir rootDir)
|
|
|
|
|
{
|
2011-06-16 02:32:55 +00:00
|
|
|
|
var model = new RootDirModel
|
|
|
|
|
{
|
|
|
|
|
Id = rootDir.Id,
|
|
|
|
|
Path = rootDir.Path,
|
|
|
|
|
SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ViewData["guid"] = Guid.NewGuid();
|
2011-05-31 06:13:46 +00:00
|
|
|
|
|
2011-06-09 01:45:06 +00:00
|
|
|
|
return PartialView("RootDir", model);
|
2011-05-31 06:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult DeleteRootDir(int rootDirId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_rootFolderProvider.Remove(rootDirId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return new JsonResult { Data = "failed" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = "ok" };
|
|
|
|
|
}
|
2011-04-01 06:36:34 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|