2011-04-01 09:36:34 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
2011-05-28 10:16:16 +03:00
|
|
|
using System.Linq;
|
2011-09-04 06:05:44 +03:00
|
|
|
using System.Web.Mvc;
|
2011-11-13 07:07:06 +03:00
|
|
|
using NzbDrone.Common;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Jobs;
|
2011-04-01 09:36:34 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 06:50:12 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-31 09:13:46 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
2012-01-19 06:58:32 +03:00
|
|
|
using NzbDrone.Web.Filters;
|
2011-04-01 09:36:34 +03:00
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
{
|
|
|
|
public class AddSeriesController : Controller
|
|
|
|
{
|
2011-04-10 04:34:36 +03:00
|
|
|
private readonly ConfigProvider _configProvider;
|
2011-04-08 07:11:45 +03:00
|
|
|
private readonly QualityProvider _qualityProvider;
|
2011-04-10 05:44:01 +03:00
|
|
|
private readonly RootDirProvider _rootFolderProvider;
|
2011-04-09 02:55:23 +03:00
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-04-20 10:44:13 +03:00
|
|
|
private readonly JobProvider _jobProvider;
|
2011-04-10 05:44:01 +03:00
|
|
|
private readonly TvDbProvider _tvDbProvider;
|
2011-05-28 10:16:16 +03:00
|
|
|
private readonly DiskProvider _diskProvider;
|
2011-04-01 09:36:34 +03:00
|
|
|
|
2011-06-14 04:23:04 +03:00
|
|
|
public AddSeriesController(RootDirProvider rootFolderProvider,
|
2011-04-10 05:44:01 +03:00
|
|
|
ConfigProvider configProvider,
|
|
|
|
QualityProvider qualityProvider, TvDbProvider tvDbProvider,
|
2011-05-28 10:16:16 +03:00
|
|
|
SeriesProvider seriesProvider, JobProvider jobProvider,
|
|
|
|
DiskProvider diskProvider)
|
2011-04-01 09:36:34 +03:00
|
|
|
{
|
2011-06-14 04:23:04 +03:00
|
|
|
|
2011-04-01 09:36:34 +03:00
|
|
|
_rootFolderProvider = rootFolderProvider;
|
|
|
|
_configProvider = configProvider;
|
|
|
|
_qualityProvider = qualityProvider;
|
|
|
|
_tvDbProvider = tvDbProvider;
|
|
|
|
_seriesProvider = seriesProvider;
|
2011-04-20 10:44:13 +03:00
|
|
|
_jobProvider = jobProvider;
|
2011-05-28 10:16:16 +03:00
|
|
|
_diskProvider = diskProvider;
|
2011-04-01 09:36:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
2012-01-19 08:01:47 +03:00
|
|
|
public EmptyResult ScanNewSeries()
|
2011-04-01 09:36:34 +03:00
|
|
|
{
|
2011-05-21 03:23:49 +03:00
|
|
|
_jobProvider.QueueJob(typeof(ImportNewSeriesJob));
|
2012-01-19 08:01:47 +03:00
|
|
|
return new EmptyResult();
|
2011-04-01 09:36:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult AddNew()
|
|
|
|
{
|
2011-07-08 06:27:11 +03:00
|
|
|
ViewData["RootDirs"] = _rootFolderProvider.GetAll().Select(c => c.Path).OrderBy(e => e).ToList();
|
2011-04-01 09:36:34 +03:00
|
|
|
|
2011-05-28 10:16:16 +03:00
|
|
|
var defaultQuality = _configProvider.DefaultQualityProfile;
|
2011-07-08 08:41:08 +03:00
|
|
|
var qualityProfiles = _qualityProvider.All();
|
2011-04-01 09:36:34 +03:00
|
|
|
|
2011-10-19 18:16:34 +03:00
|
|
|
ViewData["qualityProfiles"] = new SelectList(
|
2011-05-28 10:16:16 +03:00
|
|
|
qualityProfiles,
|
|
|
|
"QualityProfileId",
|
|
|
|
"Name",
|
|
|
|
defaultQuality);
|
2011-04-01 09:36:34 +03:00
|
|
|
|
2011-05-28 10:16:16 +03:00
|
|
|
return View();
|
2011-04-01 09:36:34 +03:00
|
|
|
}
|
|
|
|
|
2011-05-31 23:50:19 +03:00
|
|
|
public ActionResult Index()
|
2011-04-01 09:36:34 +03:00
|
|
|
{
|
2011-07-28 01:59:48 +03:00
|
|
|
return View();
|
2011-05-31 23:50:19 +03:00
|
|
|
}
|
|
|
|
|
2011-07-28 01:59:48 +03:00
|
|
|
public ActionResult ExistingSeries()
|
2011-05-31 23:50:19 +03:00
|
|
|
{
|
2011-07-28 01:59:48 +03:00
|
|
|
var result = new ExistingSeriesModel();
|
2011-05-31 23:50:19 +03:00
|
|
|
|
|
|
|
var unmappedList = new List<String>();
|
|
|
|
|
2011-07-28 01:59:48 +03:00
|
|
|
foreach (var folder in _rootFolderProvider.GetAll())
|
2011-04-01 09:36:34 +03:00
|
|
|
{
|
2011-05-20 06:47:07 +03:00
|
|
|
unmappedList.AddRange(_rootFolderProvider.GetUnmappedFolders(folder.Path));
|
2011-04-01 09:36:34 +03:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:52:25 +03:00
|
|
|
result.ExistingSeries = new List<Tuple<string, string, int>>();
|
2011-04-01 09:36:34 +03:00
|
|
|
|
2011-07-28 01:59:48 +03:00
|
|
|
foreach (var folder in unmappedList)
|
|
|
|
{
|
|
|
|
var foldername = new DirectoryInfo(folder).Name;
|
|
|
|
var tvdbResult = _tvDbProvider.SearchSeries(foldername).FirstOrDefault();
|
2011-04-01 09:36:34 +03:00
|
|
|
|
2011-07-28 01:59:48 +03:00
|
|
|
var title = String.Empty;
|
2011-09-09 06:52:25 +03:00
|
|
|
var seriesId = 0;
|
2011-07-28 01:59:48 +03:00
|
|
|
if (tvdbResult != null)
|
|
|
|
{
|
|
|
|
title = tvdbResult.SeriesName;
|
2011-09-09 06:52:25 +03:00
|
|
|
seriesId = tvdbResult.Id;
|
2011-07-28 01:59:48 +03:00
|
|
|
}
|
2011-04-04 04:31:27 +03:00
|
|
|
|
2011-09-09 06:52:25 +03:00
|
|
|
result.ExistingSeries.Add(new Tuple<string, string, int>(folder, title, seriesId));
|
2011-07-28 01:59:48 +03:00
|
|
|
}
|
2011-04-05 05:48:46 +03:00
|
|
|
|
2011-07-28 01:59:48 +03:00
|
|
|
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
|
|
|
|
result.Quality = new SelectList(_qualityProvider.All(), "QualityProfileId", "Name", defaultQuality);
|
2011-04-04 04:31:27 +03:00
|
|
|
|
2011-07-28 01:59:48 +03:00
|
|
|
return View(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
2011-09-09 06:52:25 +03:00
|
|
|
public JsonResult AddNewSeries(string path, string seriesName, int seriesId, int qualityProfileId)
|
2011-07-28 01:59:48 +03:00
|
|
|
{
|
|
|
|
path = Path.Combine(path, MediaFileProvider.CleanFilename(seriesName));
|
2011-09-10 02:28:21 +03:00
|
|
|
|
|
|
|
//Create the folder for the new series
|
|
|
|
//Use the created folder name when adding the series
|
|
|
|
path = _diskProvider.CreateDirectory(path);
|
|
|
|
|
2011-09-09 06:52:25 +03:00
|
|
|
return AddExistingSeries(path, seriesName, seriesId, qualityProfileId);
|
2011-04-01 09:36:34 +03:00
|
|
|
}
|
|
|
|
|
2011-05-28 10:16:16 +03:00
|
|
|
[HttpPost]
|
2012-01-19 08:01:47 +03:00
|
|
|
[JsonErrorFilter]
|
2011-09-09 06:52:25 +03:00
|
|
|
public JsonResult AddExistingSeries(string path, string seriesName, int seriesId, int qualityProfileId)
|
2011-05-28 10:16:16 +03:00
|
|
|
{
|
2012-01-13 19:54:20 +03:00
|
|
|
if (seriesId == 0 || String.IsNullOrWhiteSpace(seriesName))
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Error("Add Existing series failed.", "Invalid Series information");
|
2012-01-13 19:54:20 +03:00
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
_seriesProvider.AddSeries(path, seriesId, qualityProfileId);
|
|
|
|
ScanNewSeries();
|
2011-05-31 09:13:46 +03:00
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Info(seriesName, "Was added successfully");
|
2011-05-28 10:16:16 +03:00
|
|
|
}
|
|
|
|
|
2011-10-19 18:16:34 +03:00
|
|
|
[HttpPost]
|
|
|
|
public JsonResult QuickAddNewSeries(string seriesName, int seriesId, int qualityProfileId)
|
|
|
|
{
|
|
|
|
var path = _rootFolderProvider.GetMostFreeRootDir();
|
|
|
|
path = Path.Combine(path, MediaFileProvider.CleanFilename(seriesName));
|
|
|
|
|
|
|
|
//Create the folder for the new series
|
|
|
|
//Use the created folder name when adding the series
|
|
|
|
path = _diskProvider.CreateDirectory(path);
|
|
|
|
|
|
|
|
return AddExistingSeries(path, seriesName, seriesId, qualityProfileId);
|
|
|
|
}
|
|
|
|
|
|
|
|
[ChildActionOnly]
|
|
|
|
public ActionResult QuickAdd()
|
|
|
|
{
|
|
|
|
var defaultQuality = _configProvider.DefaultQualityProfile;
|
|
|
|
var qualityProfiles = _qualityProvider.All();
|
|
|
|
|
|
|
|
ViewData["qualityProfiles"] = new SelectList(
|
|
|
|
qualityProfiles,
|
|
|
|
"QualityProfileId",
|
|
|
|
"Name",
|
|
|
|
defaultQuality);
|
|
|
|
|
|
|
|
return PartialView();
|
|
|
|
}
|
|
|
|
|
2011-05-31 09:13:46 +03:00
|
|
|
|
|
|
|
[HttpPost]
|
2012-01-19 08:01:47 +03:00
|
|
|
[JsonErrorFilter]
|
2011-06-30 09:15:06 +03:00
|
|
|
public JsonResult SaveRootDir(string path)
|
2011-05-31 09:13:46 +03:00
|
|
|
{
|
2011-06-16 05:32:55 +03:00
|
|
|
if (String.IsNullOrWhiteSpace(path))
|
2012-01-19 08:01:47 +03:00
|
|
|
JsonNotificationResult.Error("Can't add root folder", "Path can not be empty");
|
2011-09-23 03:18:41 +03:00
|
|
|
|
2012-01-19 06:58:32 +03:00
|
|
|
_rootFolderProvider.Add(new RootDir { Path = path });
|
2011-06-16 05:32:55 +03:00
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Info("Root Folder saved", "Root foler saved successfully.");
|
2011-05-31 09:13:46 +03:00
|
|
|
}
|
|
|
|
|
2011-07-28 01:59:48 +03:00
|
|
|
[HttpGet]
|
2011-09-09 06:26:48 +03:00
|
|
|
public JsonResult LookupSeries(string term)
|
2011-05-31 09:13:46 +03:00
|
|
|
{
|
2011-09-09 06:26:48 +03:00
|
|
|
var tvDbResults = _tvDbProvider.SearchSeries(term).Select(r => new TvDbSearchResultModel
|
|
|
|
{
|
|
|
|
Id = r.Id,
|
|
|
|
Title = r.SeriesName,
|
|
|
|
FirstAired = r.FirstAired.ToShortDateString()
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
return Json(tvDbResults, JsonRequestBehavior.AllowGet);
|
2011-05-31 09:13:46 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 10:23:07 +03:00
|
|
|
public ActionResult RootList()
|
2011-06-30 09:15:06 +03:00
|
|
|
{
|
2011-07-01 10:52:44 +03:00
|
|
|
IEnumerable<String> rootDir = _rootFolderProvider.GetAll().Select(c => c.Path).OrderBy(e => e);
|
2011-07-01 10:23:07 +03:00
|
|
|
return PartialView("RootList", rootDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult RootDir()
|
|
|
|
{
|
|
|
|
return PartialView("RootDir");
|
2011-06-30 09:15:06 +03:00
|
|
|
}
|
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
[JsonErrorFilter]
|
2011-06-30 09:15:06 +03:00
|
|
|
public JsonResult DeleteRootDir(string path)
|
2011-05-31 09:13:46 +03:00
|
|
|
{
|
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
var id = _rootFolderProvider.GetAll().Where(c => c.Path == path).First().Id;
|
|
|
|
_rootFolderProvider.Remove(id);
|
2011-05-31 09:13:46 +03:00
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
return null;
|
2011-05-31 09:13:46 +03:00
|
|
|
}
|
2011-04-01 09:36:34 +03:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|