2011-04-01 06:36:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-01 06:36:34 +00:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class AddSeriesController : Controller
|
|
|
|
|
{
|
|
|
|
|
public IConfigProvider ConfigProvider { get; set; }
|
|
|
|
|
private readonly ISyncProvider _syncProvider;
|
|
|
|
|
private readonly IRootDirProvider _rootFolderProvider;
|
|
|
|
|
private readonly IConfigProvider _configProvider;
|
|
|
|
|
private readonly IQualityProvider _qualityProvider;
|
|
|
|
|
private readonly ITvDbProvider _tvDbProvider;
|
|
|
|
|
private readonly ISeriesProvider _seriesProvider;
|
|
|
|
|
|
|
|
|
|
public AddSeriesController(ISyncProvider syncProvider, IRootDirProvider rootFolderProvider, IConfigProvider configProvider,
|
|
|
|
|
IQualityProvider qualityProvider, ITvDbProvider tvDbProvider, ISeriesProvider seriesProvider)
|
|
|
|
|
{
|
|
|
|
|
ConfigProvider = configProvider;
|
|
|
|
|
_syncProvider = syncProvider;
|
|
|
|
|
_rootFolderProvider = rootFolderProvider;
|
|
|
|
|
_configProvider = configProvider;
|
|
|
|
|
_qualityProvider = qualityProvider;
|
|
|
|
|
_tvDbProvider = tvDbProvider;
|
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult ScanNewSeries()
|
|
|
|
|
{
|
|
|
|
|
_syncProvider.BeginUpdateNewSeries();
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
DirectorySeparatorChar = Path.DirectorySeparatorChar.ToString(),
|
|
|
|
|
RootDirectories = _rootFolderProvider.GetAll(),
|
|
|
|
|
QualityProfileId = defaultQuality,
|
|
|
|
|
QualitySelectList = selectList
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult AddExisting()
|
|
|
|
|
{
|
|
|
|
|
var unmappedList = new List<String>();
|
|
|
|
|
|
|
|
|
|
foreach (var folder in _rootFolderProvider.GetAll())
|
|
|
|
|
{
|
|
|
|
|
unmappedList.AddRange(_syncProvider.GetUnmappedFolders(folder.Path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^');
|
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-05 02:48:46 +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
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
_seriesProvider.AddSeries(path.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar), seriesId, qualityProfileId);
|
|
|
|
|
ScanNewSeries();
|
|
|
|
|
return new JsonResult() { Data = "ok" };
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 23:11:09 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult _textLookUp(string text, int? filterMode)
|
|
|
|
|
{
|
|
|
|
|
var suggestions = GetSuggestionList(text);
|
|
|
|
|
|
|
|
|
|
return new JsonResult
|
|
|
|
|
{
|
|
|
|
|
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
|
|
|
|
|
Data = suggestions
|
|
|
|
|
};
|
|
|
|
|
}
|
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-05 02:48:46 +00:00
|
|
|
|
var bestResult = _tvDbProvider.GetBestMatch(dataVal.ToList(), searchString);
|
2011-04-01 23:11:09 +00:00
|
|
|
|
|
2011-04-05 02:48:46 +00:00
|
|
|
|
return new SelectList(dataVal, "Id", "SeriesName", bestResult);
|
2011-04-01 23:11:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 06:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|