2010-09-23 05:19:47 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-02-25 02:18:22 +01:00
|
|
|
|
using System.IO;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
2011-06-23 08:56:17 +02:00
|
|
|
|
using MvcMiniProfiler;
|
2011-09-28 02:10:08 +02:00
|
|
|
|
using NzbDrone.Core;
|
2011-09-05 21:59:39 +02:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2010-09-28 06:25:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-30 04:46:32 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2012-01-20 08:50:45 +01:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-10-30 04:46:32 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
using Telerik.Web.Mvc;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
2010-10-08 05:35:04 +02:00
|
|
|
|
[HandleError]
|
2010-09-23 05:19:47 +02:00
|
|
|
|
public class SeriesController : Controller
|
|
|
|
|
{
|
2011-04-10 02:14:51 +02:00
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2011-04-10 04:44:01 +02:00
|
|
|
|
private readonly QualityProvider _qualityProvider;
|
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-04-08 06:11:45 +02:00
|
|
|
|
private readonly TvDbProvider _tvDbProvider;
|
2011-04-20 09:44:13 +02:00
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-06-03 05:04:39 +02:00
|
|
|
|
private readonly MediaFileProvider _mediaFileProvider;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
//
|
|
|
|
|
// GET: /Series/
|
|
|
|
|
|
2011-04-20 09:44:13 +02:00
|
|
|
|
public SeriesController(SeriesProvider seriesProvider,
|
2011-04-20 03:20:20 +02:00
|
|
|
|
EpisodeProvider episodeProvider,
|
2011-05-22 19:29:10 +02:00
|
|
|
|
QualityProvider qualityProvider,
|
|
|
|
|
TvDbProvider tvDbProvider,
|
2011-06-03 05:04:39 +02:00
|
|
|
|
JobProvider jobProvider,
|
|
|
|
|
MediaFileProvider mediaFileProvider)
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2010-09-28 06:25:41 +02:00
|
|
|
|
_seriesProvider = seriesProvider;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
_episodeProvider = episodeProvider;
|
2011-02-18 03:50:40 +01:00
|
|
|
|
_qualityProvider = qualityProvider;
|
2011-03-11 10:04:56 +01:00
|
|
|
|
_tvDbProvider = tvDbProvider;
|
2011-04-20 09:44:13 +02:00
|
|
|
|
_jobProvider = jobProvider;
|
2011-06-03 05:04:39 +02:00
|
|
|
|
_mediaFileProvider = mediaFileProvider;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2011-07-08 07:41:08 +02:00
|
|
|
|
var profiles = _qualityProvider.All();
|
2011-05-10 08:32:33 +02:00
|
|
|
|
ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name");
|
|
|
|
|
|
2010-09-23 05:19:47 +02:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-10 08:32:33 +02:00
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _AjaxSeriesGrid()
|
|
|
|
|
{
|
2011-09-05 21:59:39 +02:00
|
|
|
|
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount()).OrderBy(o => SortHelper.SkipArticles(o.Title));
|
2011-05-10 08:32:33 +02:00
|
|
|
|
return View(new GridModel(series));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
|
|
|
[GridAction]
|
2011-08-26 01:05:31 +02:00
|
|
|
|
public ActionResult _SaveAjaxSeriesEditing(int id, string path, bool monitored, bool seasonFolder, int qualityProfileId)
|
2011-05-10 08:32:33 +02:00
|
|
|
|
{
|
|
|
|
|
var oldSeries = _seriesProvider.GetSeries(id);
|
|
|
|
|
oldSeries.Monitored = monitored;
|
2011-05-12 04:53:19 +02:00
|
|
|
|
oldSeries.SeasonFolder = seasonFolder;
|
2011-05-10 08:32:33 +02:00
|
|
|
|
oldSeries.QualityProfileId = qualityProfileId;
|
2011-08-26 01:05:31 +02:00
|
|
|
|
oldSeries.Path = path;
|
2011-05-10 08:32:33 +02:00
|
|
|
|
|
|
|
|
|
_seriesProvider.UpdateSeries(oldSeries);
|
|
|
|
|
|
2011-09-07 08:43:10 +02:00
|
|
|
|
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount()).OrderBy(o => SortHelper.SkipArticles(o.Title));
|
2011-05-12 04:53:19 +02:00
|
|
|
|
return View(new GridModel(series));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _DeleteAjaxSeriesEditing(int id)
|
|
|
|
|
{
|
|
|
|
|
//Grab the series from the DB so we can remove it from the list we return to the client
|
2011-09-07 08:43:10 +02:00
|
|
|
|
var seriesInDb = _seriesProvider.GetAllSeriesWithEpisodeCount().ToList();
|
2011-05-10 08:32:33 +02:00
|
|
|
|
|
2011-05-12 04:53:19 +02:00
|
|
|
|
//Remove this so we don't send it back to the client (since it hasn't really been deleted yet)
|
|
|
|
|
seriesInDb.RemoveAll(s => s.SeriesId == id);
|
2011-05-10 08:32:33 +02:00
|
|
|
|
|
2011-05-12 04:53:19 +02:00
|
|
|
|
//Start removing this series
|
2011-05-17 09:04:49 +02:00
|
|
|
|
_jobProvider.QueueJob(typeof(DeleteSeriesJob), id);
|
2011-05-18 07:32:23 +02:00
|
|
|
|
|
2011-09-07 08:43:10 +02:00
|
|
|
|
var series = GetSeriesModels(seriesInDb).OrderBy(o => SortHelper.SkipArticles(o.Title));
|
2011-05-10 08:32:33 +02:00
|
|
|
|
return View(new GridModel(series));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-30 04:46:32 +02:00
|
|
|
|
[GridAction]
|
2011-06-04 03:56:53 +02:00
|
|
|
|
public ActionResult _AjaxSeasonGrid(int seriesId, int seasonNumber)
|
2010-10-08 07:04:25 +02:00
|
|
|
|
{
|
2011-06-23 08:56:17 +02:00
|
|
|
|
using (MiniProfiler.StepStatic("Controller"))
|
|
|
|
|
{
|
2011-12-04 00:44:48 +01:00
|
|
|
|
var episodes = GetEpisodeModels(_episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber));
|
2011-06-23 08:56:17 +02:00
|
|
|
|
return View(new GridModel(episodes));
|
|
|
|
|
}
|
2010-10-08 07:04:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-21 01:36:47 +02:00
|
|
|
|
public JsonResult LocalSearch(string term)
|
2011-03-11 10:04:56 +01:00
|
|
|
|
{
|
2011-10-21 01:36:47 +02:00
|
|
|
|
//Get Results from the local DB and return
|
2011-03-11 10:04:56 +01:00
|
|
|
|
|
2011-10-21 01:36:47 +02:00
|
|
|
|
var results = _seriesProvider.SearchForSeries(term).Select(s => new SeriesSearchResultModel
|
|
|
|
|
{
|
|
|
|
|
Id = s.SeriesId,
|
|
|
|
|
Title = s.Title
|
|
|
|
|
}).ToList();
|
2011-03-11 10:04:56 +01:00
|
|
|
|
|
2011-10-21 01:36:47 +02:00
|
|
|
|
return Json(results, JsonRequestBehavior.AllowGet);
|
2011-03-09 08:40:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 08:27:02 +02:00
|
|
|
|
[HttpPost]
|
2012-01-19 06:01:47 +01:00
|
|
|
|
public EmptyResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored)
|
2011-05-16 08:27:02 +02:00
|
|
|
|
{
|
2011-08-04 03:45:45 +02:00
|
|
|
|
_episodeProvider.SetSeasonIgnore(seriesId, seasonNumber, ignored);
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return new EmptyResult();
|
2011-08-04 03:45:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2012-01-19 06:01:47 +01:00
|
|
|
|
public EmptyResult SaveEpisodeIgnore(int episodeId, bool ignored)
|
2011-08-04 03:45:45 +02:00
|
|
|
|
{
|
|
|
|
|
_episodeProvider.SetEpisodeIgnore(episodeId, ignored);
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return new EmptyResult();
|
2011-05-16 08:27:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 08:21:18 +02:00
|
|
|
|
public ActionResult Details(int seriesId)
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2011-02-17 18:45:02 +01:00
|
|
|
|
var series = _seriesProvider.GetSeries(seriesId);
|
2011-06-04 03:56:53 +02:00
|
|
|
|
|
|
|
|
|
var model = new SeriesModel();
|
|
|
|
|
|
|
|
|
|
if (series.AirsDayOfWeek != null)
|
|
|
|
|
{
|
|
|
|
|
model.AirsDayOfWeek = series.AirsDayOfWeek.Value.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model.AirsDayOfWeek = "N/A";
|
|
|
|
|
}
|
|
|
|
|
model.Overview = series.Overview;
|
|
|
|
|
model.Seasons = _episodeProvider.GetSeasons(seriesId);
|
2011-06-18 08:41:31 +02:00
|
|
|
|
model.Title = series.Title;
|
2011-06-04 03:56:53 +02:00
|
|
|
|
model.SeriesId = series.SeriesId;
|
2011-09-11 01:01:15 +02:00
|
|
|
|
model.HasBanner = !String.IsNullOrEmpty(series.BannerUrl);
|
2011-06-04 03:56:53 +02:00
|
|
|
|
|
|
|
|
|
return View(model);
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
2011-02-18 03:50:40 +01:00
|
|
|
|
|
2012-01-20 08:50:45 +01:00
|
|
|
|
public ActionResult MassEdit()
|
|
|
|
|
{
|
|
|
|
|
var profiles = _qualityProvider.All();
|
|
|
|
|
ViewData["QualityProfiles"] = profiles;
|
|
|
|
|
|
|
|
|
|
//Create the select lists
|
|
|
|
|
var masterProfiles = profiles.ToList();
|
|
|
|
|
masterProfiles.Insert(0, new QualityProfile {QualityProfileId = -10, Name = "Unchanged"});
|
|
|
|
|
ViewData["MasterProfileSelectList"] = new SelectList(masterProfiles, "QualityProfileId", "Name");
|
|
|
|
|
|
|
|
|
|
ViewData["BoolSelectList"] = new SelectList(new List<KeyValuePair<int, string>>
|
|
|
|
|
{
|
|
|
|
|
new KeyValuePair<int, string>(-10, "Unchanged"),
|
|
|
|
|
new KeyValuePair<int, string>(1, "True"),
|
|
|
|
|
new KeyValuePair<int, string>(0, "False")
|
|
|
|
|
}, "Key", "Value"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var series = _seriesProvider.GetAllSeries().OrderBy(o => SortHelper.SkipArticles(o.Title));
|
|
|
|
|
|
|
|
|
|
return View(series);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult SaveMassEdit(List<Series> series)
|
|
|
|
|
{
|
|
|
|
|
//Save edits
|
|
|
|
|
if (series == null || series.Count == 0)
|
|
|
|
|
return JsonNotificationResult.Opps("Invalid post data");
|
|
|
|
|
|
|
|
|
|
_seriesProvider.UpdateFromMassEdit(series);
|
|
|
|
|
return JsonNotificationResult.Info("Series Mass Edit Saved");
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-22 08:39:45 +02:00
|
|
|
|
private List<SeriesModel> GetSeriesModels(IList<Series> seriesInDb)
|
2011-05-12 04:53:19 +02:00
|
|
|
|
{
|
2011-06-20 09:13:17 +02:00
|
|
|
|
var series = seriesInDb.Select(s => new SeriesModel
|
|
|
|
|
{
|
|
|
|
|
SeriesId = s.SeriesId,
|
|
|
|
|
Title = s.Title,
|
|
|
|
|
AirsDayOfWeek = s.AirsDayOfWeek.ToString(),
|
|
|
|
|
Monitored = s.Monitored,
|
|
|
|
|
Overview = s.Overview,
|
|
|
|
|
Path = s.Path,
|
|
|
|
|
QualityProfileId = s.QualityProfileId,
|
|
|
|
|
QualityProfileName = s.QualityProfile.Name,
|
|
|
|
|
SeasonFolder = s.SeasonFolder,
|
|
|
|
|
Status = s.Status,
|
|
|
|
|
SeasonsCount = s.SeasonCount,
|
|
|
|
|
EpisodeCount = s.EpisodeCount,
|
2011-09-28 19:56:30 +02:00
|
|
|
|
EpisodeFileCount = s.EpisodeFileCount,
|
|
|
|
|
NextAiring = s.NextAiring == null ? String.Empty : s.NextAiring.Value.ToBestDateString()
|
2011-06-20 09:13:17 +02:00
|
|
|
|
}).ToList();
|
2011-05-12 04:53:19 +02:00
|
|
|
|
|
|
|
|
|
return series;
|
|
|
|
|
}
|
2011-05-16 08:27:02 +02:00
|
|
|
|
|
2011-06-06 00:19:07 +02:00
|
|
|
|
private List<EpisodeModel> GetEpisodeModels(IList<Episode> episodesInDb)
|
|
|
|
|
{
|
|
|
|
|
var episodes = new List<EpisodeModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var e in episodesInDb)
|
|
|
|
|
{
|
|
|
|
|
var episodeFileId = 0;
|
2011-06-17 05:29:39 +02:00
|
|
|
|
var episodePath = String.Empty;
|
|
|
|
|
var episodeQuality = String.Empty;
|
|
|
|
|
|
2011-06-22 07:43:45 +02:00
|
|
|
|
if (e.EpisodeFile != null)
|
2011-06-06 00:19:07 +02:00
|
|
|
|
{
|
2011-06-22 07:43:45 +02:00
|
|
|
|
episodePath = e.EpisodeFile.Path;
|
|
|
|
|
episodeFileId = e.EpisodeFile.EpisodeFileId;
|
|
|
|
|
episodeQuality = e.EpisodeFile.Quality.ToString();
|
2011-06-06 00:19:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-23 20:37:17 +02:00
|
|
|
|
var airDate = String.Empty;
|
|
|
|
|
|
|
|
|
|
if (e.AirDate != null)
|
2011-09-28 02:10:08 +02:00
|
|
|
|
airDate = e.AirDate.Value.ToBestDateString();
|
2011-06-23 20:37:17 +02:00
|
|
|
|
|
2011-06-06 00:19:07 +02:00
|
|
|
|
episodes.Add(new EpisodeModel
|
|
|
|
|
{
|
|
|
|
|
EpisodeId = e.EpisodeId,
|
|
|
|
|
EpisodeNumber = e.EpisodeNumber,
|
|
|
|
|
SeasonNumber = e.SeasonNumber,
|
|
|
|
|
Title = e.Title,
|
|
|
|
|
Overview = e.Overview,
|
2011-06-23 20:37:17 +02:00
|
|
|
|
AirDate = airDate,
|
2011-06-06 00:19:07 +02:00
|
|
|
|
Path = episodePath,
|
|
|
|
|
EpisodeFileId = episodeFileId,
|
|
|
|
|
Status = e.Status.ToString(),
|
2011-08-03 09:26:39 +02:00
|
|
|
|
Quality = episodeQuality,
|
|
|
|
|
Ignored = e.Ignored
|
2011-06-06 00:19:07 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return episodes;
|
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|