2011-04-01 08:36:34 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2011-05-28 09:16:16 +02:00
|
|
|
|
using System.Linq;
|
2011-09-04 05:05:44 +02:00
|
|
|
|
using System.Web.Mvc;
|
2011-05-31 08:13:46 +02:00
|
|
|
|
using NLog;
|
2011-05-28 09:16:16 +02:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2011-04-01 08:36:34 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 05:50:12 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-20 09:44:13 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2011-05-31 08:13:46 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-04-01 08:36:34 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class AddSeriesController : Controller
|
|
|
|
|
{
|
2011-05-31 08:13:46 +02:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-10 03:34:36 +02:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
2011-04-08 06:11:45 +02:00
|
|
|
|
private readonly QualityProvider _qualityProvider;
|
2011-04-10 04:44:01 +02:00
|
|
|
|
private readonly RootDirProvider _rootFolderProvider;
|
2011-04-09 01:55:23 +02:00
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-04-20 09:44:13 +02:00
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-04-10 04:44:01 +02:00
|
|
|
|
private readonly TvDbProvider _tvDbProvider;
|
2011-05-28 09:16:16 +02:00
|
|
|
|
private readonly DiskProvider _diskProvider;
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-06-14 03:23:04 +02:00
|
|
|
|
public AddSeriesController(RootDirProvider rootFolderProvider,
|
2011-04-10 04:44:01 +02:00
|
|
|
|
ConfigProvider configProvider,
|
|
|
|
|
QualityProvider qualityProvider, TvDbProvider tvDbProvider,
|
2011-05-28 09:16:16 +02:00
|
|
|
|
SeriesProvider seriesProvider, JobProvider jobProvider,
|
|
|
|
|
DiskProvider diskProvider)
|
2011-04-01 08:36:34 +02:00
|
|
|
|
{
|
2011-06-14 03:23:04 +02:00
|
|
|
|
|
2011-04-01 08:36:34 +02:00
|
|
|
|
_rootFolderProvider = rootFolderProvider;
|
|
|
|
|
_configProvider = configProvider;
|
|
|
|
|
_qualityProvider = qualityProvider;
|
|
|
|
|
_tvDbProvider = tvDbProvider;
|
|
|
|
|
_seriesProvider = seriesProvider;
|
2011-04-20 09:44:13 +02:00
|
|
|
|
_jobProvider = jobProvider;
|
2011-05-28 09:16:16 +02:00
|
|
|
|
_diskProvider = diskProvider;
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult ScanNewSeries()
|
|
|
|
|
{
|
2011-05-21 02:23:49 +02:00
|
|
|
|
_jobProvider.QueueJob(typeof(ImportNewSeriesJob));
|
2011-04-01 08:36:34 +02:00
|
|
|
|
return new JsonResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult AddNew()
|
|
|
|
|
{
|
2011-07-08 05:27:11 +02:00
|
|
|
|
ViewData["RootDirs"] = _rootFolderProvider.GetAll().Select(c => c.Path).OrderBy(e => e).ToList();
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-05-28 09:16:16 +02:00
|
|
|
|
var defaultQuality = _configProvider.DefaultQualityProfile;
|
2011-07-08 07:41:08 +02:00
|
|
|
|
var qualityProfiles = _qualityProvider.All();
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-07-08 05:27:11 +02:00
|
|
|
|
ViewData["qualityList"] = qualityProfiles;
|
|
|
|
|
|
2011-05-28 09:16:16 +02:00
|
|
|
|
ViewData["quality"] = new SelectList(
|
|
|
|
|
qualityProfiles,
|
|
|
|
|
"QualityProfileId",
|
|
|
|
|
"Name",
|
|
|
|
|
defaultQuality);
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-05-28 09:16:16 +02:00
|
|
|
|
return View();
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 22:50:19 +02:00
|
|
|
|
public ActionResult Index()
|
2011-04-01 08:36:34 +02:00
|
|
|
|
{
|
2011-07-28 00:59:48 +02:00
|
|
|
|
return View();
|
2011-05-31 22:50:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-30 08:15:06 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
public ActionResult ExistingSeries()
|
2011-05-31 22:50:19 +02:00
|
|
|
|
{
|
2011-07-28 00:59:48 +02:00
|
|
|
|
var result = new ExistingSeriesModel();
|
2011-05-31 22:50:19 +02:00
|
|
|
|
|
|
|
|
|
var unmappedList = new List<String>();
|
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
foreach (var folder in _rootFolderProvider.GetAll())
|
2011-04-01 08:36:34 +02:00
|
|
|
|
{
|
2011-05-20 05:47:07 +02:00
|
|
|
|
unmappedList.AddRange(_rootFolderProvider.GetUnmappedFolders(folder.Path));
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
result.ExistingSeries = new List<Tuple<string, string>>();
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
foreach (var folder in unmappedList)
|
|
|
|
|
{
|
|
|
|
|
var foldername = new DirectoryInfo(folder).Name;
|
|
|
|
|
var tvdbResult = _tvDbProvider.SearchSeries(foldername).FirstOrDefault();
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
var title = String.Empty;
|
|
|
|
|
if (tvdbResult != null)
|
|
|
|
|
{
|
|
|
|
|
title = tvdbResult.SeriesName;
|
|
|
|
|
}
|
2011-04-04 03:31:27 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
result.ExistingSeries.Add(new Tuple<string, string>(folder, title));
|
|
|
|
|
}
|
2011-04-05 04:48:46 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
|
|
|
|
|
result.Quality = new SelectList(_qualityProvider.All(), "QualityProfileId", "Name", defaultQuality);
|
2011-04-04 03:31:27 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
return View(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult AddNewSeries(string path, string seriesName, int qualityProfileId)
|
|
|
|
|
{
|
|
|
|
|
path = Path.Combine(path, MediaFileProvider.CleanFilename(seriesName));
|
|
|
|
|
return AddExistingSeries(path, seriesName, qualityProfileId);
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-28 09:16:16 +02:00
|
|
|
|
[HttpPost]
|
2011-07-28 00:59:48 +02:00
|
|
|
|
public JsonResult AddExistingSeries(string path, string seriesName, int qualityProfileId)
|
2011-05-28 09:16:16 +02:00
|
|
|
|
{
|
2011-05-31 08:13:46 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//Create the folder for the new series and then Add it
|
|
|
|
|
_diskProvider.CreateDirectory(path);
|
2011-05-28 09:16:16 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
var series = _tvDbProvider.SearchSeries(seriesName).Where(s => s.SeriesName == seriesName).Single();
|
|
|
|
|
|
|
|
|
|
_seriesProvider.AddSeries(path, series.Id, qualityProfileId);
|
2011-05-31 08:13:46 +02:00
|
|
|
|
ScanNewSeries();
|
2011-08-22 03:00:12 +02:00
|
|
|
|
return Json(new NotificationResult() { Title = seriesName, Text = "Was added successfully" });
|
2011-05-31 08:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-22 03:00:12 +02:00
|
|
|
|
catch (Exception ex)
|
2011-05-31 08:13:46 +02:00
|
|
|
|
{
|
2011-08-22 03:00:12 +02:00
|
|
|
|
return Json(new NotificationResult() { Title = "Failed", Text = ex.Message, NotificationType = NotificationType.Error});
|
2011-05-31 08:13:46 +02:00
|
|
|
|
}
|
2011-05-28 09:16:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 08:36:34 +02: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 04:44:01 +02:00
|
|
|
|
_seriesProvider.AddSeries(
|
2011-04-25 04:30:40 +02:00
|
|
|
|
path.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace('`', '\''), seriesId,
|
2011-04-10 04:44:01 +02:00
|
|
|
|
qualityProfileId);
|
2011-04-01 08:36:34 +02:00
|
|
|
|
ScanNewSeries();
|
2011-04-20 09:44:13 +02:00
|
|
|
|
return new JsonResult { Data = "ok" };
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 08:13:46 +02:00
|
|
|
|
|
2011-06-09 03:45:06 +02:00
|
|
|
|
//Root Directory
|
2011-05-31 08:13:46 +02:00
|
|
|
|
[HttpPost]
|
2011-06-30 08:15:06 +02:00
|
|
|
|
public JsonResult SaveRootDir(string path)
|
2011-05-31 08:13:46 +02:00
|
|
|
|
{
|
2011-06-16 04:32:55 +02:00
|
|
|
|
if (String.IsNullOrWhiteSpace(path))
|
|
|
|
|
return new JsonResult { Data = "failed" };
|
|
|
|
|
|
2011-05-31 08:13:46 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2011-06-30 08:15:06 +02:00
|
|
|
|
_rootFolderProvider.Add(new RootDir { Path = path });
|
2011-06-16 04:32:55 +02:00
|
|
|
|
|
2011-05-31 08:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Failed to save Root Dir");
|
|
|
|
|
Logger.DebugException(ex.Message, ex);
|
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = "failed" };
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-23 22:31:28 +02:00
|
|
|
|
return new JsonResult { Data = "ok" };
|
2011-05-31 08:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public JsonResult LookupSeries(string q)
|
2011-05-31 08:13:46 +02:00
|
|
|
|
{
|
2011-06-16 04:32:55 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
var dataVal = _tvDbProvider.SearchSeries(q);
|
2011-05-31 08:13:46 +02:00
|
|
|
|
|
2011-07-28 00:59:48 +02:00
|
|
|
|
return Json(dataVal.Select(c => new KeyValuePair<int, string>(c.Id, c.SeriesName)), JsonRequestBehavior.AllowGet);
|
2011-05-31 08:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-01 09:23:07 +02:00
|
|
|
|
public ActionResult RootList()
|
2011-06-30 08:15:06 +02:00
|
|
|
|
{
|
2011-07-01 09:52:44 +02:00
|
|
|
|
IEnumerable<String> rootDir = _rootFolderProvider.GetAll().Select(c => c.Path).OrderBy(e => e);
|
2011-07-01 09:23:07 +02:00
|
|
|
|
return PartialView("RootList", rootDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult RootDir()
|
|
|
|
|
{
|
|
|
|
|
return PartialView("RootDir");
|
2011-06-30 08:15:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult DeleteRootDir(string path)
|
2011-05-31 08:13:46 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-06-30 08:15:06 +02:00
|
|
|
|
var id = _rootFolderProvider.GetAll().Where(c => c.Path == path).First().Id;
|
|
|
|
|
_rootFolderProvider.Remove(id);
|
2011-05-31 08:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return new JsonResult { Data = "failed" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = "ok" };
|
|
|
|
|
}
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|