2011-04-01 08:36:34 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
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-04-01 08:36:34 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class AddSeriesController : Controller
|
|
|
|
|
{
|
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 SyncProvider _syncProvider;
|
|
|
|
|
private readonly TvDbProvider _tvDbProvider;
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-04-10 04:44:01 +02:00
|
|
|
|
public AddSeriesController(SyncProvider syncProvider, RootDirProvider rootFolderProvider,
|
|
|
|
|
ConfigProvider configProvider,
|
|
|
|
|
QualityProvider qualityProvider, TvDbProvider tvDbProvider,
|
2011-04-20 09:44:13 +02:00
|
|
|
|
SeriesProvider seriesProvider, JobProvider jobProvider)
|
2011-04-01 08:36:34 +02:00
|
|
|
|
{
|
|
|
|
|
_syncProvider = syncProvider;
|
|
|
|
|
_rootFolderProvider = rootFolderProvider;
|
|
|
|
|
_configProvider = configProvider;
|
|
|
|
|
_qualityProvider = qualityProvider;
|
|
|
|
|
_tvDbProvider = tvDbProvider;
|
|
|
|
|
_seriesProvider = seriesProvider;
|
2011-04-20 09:44:13 +02:00
|
|
|
|
_jobProvider = jobProvider;
|
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()
|
|
|
|
|
{
|
|
|
|
|
ViewData["RootDirs"] = _rootFolderProvider.GetAll();
|
|
|
|
|
ViewData["DirSep"] = Path.DirectorySeparatorChar;
|
|
|
|
|
|
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles();
|
|
|
|
|
var selectList = new SelectList(profiles, "QualityProfileId", "Name");
|
|
|
|
|
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
|
|
|
|
|
|
|
|
|
|
var model = new AddNewSeriesModel
|
2011-04-10 04:44:01 +02:00
|
|
|
|
{
|
|
|
|
|
DirectorySeparatorChar = Path.DirectorySeparatorChar.ToString(),
|
|
|
|
|
RootDirectories = _rootFolderProvider.GetAll(),
|
|
|
|
|
QualityProfileId = defaultQuality,
|
|
|
|
|
QualitySelectList = selectList
|
|
|
|
|
};
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult AddExisting()
|
|
|
|
|
{
|
|
|
|
|
var unmappedList = new List<String>();
|
|
|
|
|
|
2011-04-08 01:49:18 +02:00
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles();
|
|
|
|
|
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
|
|
|
|
|
var selectList = new SelectList(profiles, "QualityProfileId", "Name", defaultQuality);
|
|
|
|
|
|
|
|
|
|
ViewData["qualities"] = selectList;
|
|
|
|
|
|
2011-04-01 08:36:34 +02:00
|
|
|
|
foreach (var folder in _rootFolderProvider.GetAll())
|
|
|
|
|
{
|
2011-05-20 05:47:07 +02:00
|
|
|
|
unmappedList.AddRange(_rootFolderProvider.GetUnmappedFolders(folder.Path));
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(unmappedList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult RenderPartial(string path)
|
|
|
|
|
{
|
2011-04-02 01:11:09 +02:00
|
|
|
|
var suggestions = GetSuggestionList(new DirectoryInfo(path).Name);
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
|
|
|
|
ViewData["guid"] = Guid.NewGuid();
|
|
|
|
|
ViewData["path"] = path;
|
2011-04-25 04:30:40 +02:00
|
|
|
|
ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`');
|
2011-04-04 03:31:27 +02:00
|
|
|
|
|
2011-04-05 04:48:46 +02:00
|
|
|
|
var defaultQuality = _configProvider.DefaultQualityProfile;
|
2011-04-04 03:31:27 +02:00
|
|
|
|
var qualityProfiles = _qualityProvider.GetAllProfiles();
|
2011-04-05 04:48:46 +02:00
|
|
|
|
|
2011-04-04 03:31:27 +02:00
|
|
|
|
ViewData["quality"] = new SelectList(
|
|
|
|
|
qualityProfiles,
|
|
|
|
|
"QualityProfileId",
|
|
|
|
|
"Name",
|
2011-04-10 04:44:01 +02:00
|
|
|
|
defaultQuality);
|
2011-04-04 03:31:27 +02:00
|
|
|
|
|
2011-04-02 01:11:09 +02:00
|
|
|
|
return PartialView("AddSeriesItem", suggestions);
|
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-04-02 01:11:09 +02:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult _textLookUp(string text, int? filterMode)
|
|
|
|
|
{
|
|
|
|
|
var suggestions = GetSuggestionList(text);
|
|
|
|
|
|
|
|
|
|
return new JsonResult
|
2011-04-10 04:44:01 +02:00
|
|
|
|
{
|
|
|
|
|
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
|
|
|
|
|
Data = suggestions
|
|
|
|
|
};
|
2011-04-02 01:11:09 +02:00
|
|
|
|
}
|
2011-04-04 03:31:27 +02:00
|
|
|
|
|
2011-04-02 01:11:09 +02:00
|
|
|
|
public SelectList GetSuggestionList(string searchString)
|
|
|
|
|
{
|
|
|
|
|
var dataVal = _tvDbProvider.SearchSeries(searchString);
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
int selectId = 0;
|
|
|
|
|
if (dataVal.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
selectId = dataVal[0].Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new SelectList(dataVal, "Id", "SeriesName", selectId);
|
2011-04-02 01:11:09 +02:00
|
|
|
|
}
|
2011-04-01 08:36:34 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|