2010-09-23 06:19:47 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2011-02-25 03:18:22 +02:00
|
|
|
using System.IO;
|
2010-09-23 06:19:47 +03:00
|
|
|
using System.Linq;
|
|
|
|
using System.Web.Mvc;
|
2011-06-23 09:56:17 +03:00
|
|
|
using MvcMiniProfiler;
|
2011-09-28 03:10:08 +03:00
|
|
|
using NzbDrone.Core;
|
2011-09-05 22:59:39 +03:00
|
|
|
using NzbDrone.Core.Helpers;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Jobs;
|
2010-09-28 07:25:41 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-30 05:46:32 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
using Telerik.Web.Mvc;
|
2010-09-23 06:19:47 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
{
|
2010-10-08 06:35:04 +03:00
|
|
|
[HandleError]
|
2010-09-23 06:19:47 +03:00
|
|
|
public class SeriesController : Controller
|
|
|
|
{
|
2011-04-10 03:14:51 +03:00
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2011-04-10 05:44:01 +03:00
|
|
|
private readonly QualityProvider _qualityProvider;
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-04-08 07:11:45 +03:00
|
|
|
private readonly TvDbProvider _tvDbProvider;
|
2011-04-20 10:44:13 +03:00
|
|
|
private readonly JobProvider _jobProvider;
|
2011-06-03 06:04:39 +03:00
|
|
|
private readonly MediaFileProvider _mediaFileProvider;
|
2010-09-23 06:19:47 +03:00
|
|
|
//
|
|
|
|
// GET: /Series/
|
|
|
|
|
2011-04-20 10:44:13 +03:00
|
|
|
public SeriesController(SeriesProvider seriesProvider,
|
2011-04-20 04:20:20 +03:00
|
|
|
EpisodeProvider episodeProvider,
|
2011-05-22 20:29:10 +03:00
|
|
|
QualityProvider qualityProvider,
|
|
|
|
TvDbProvider tvDbProvider,
|
2011-06-03 06:04:39 +03:00
|
|
|
JobProvider jobProvider,
|
|
|
|
MediaFileProvider mediaFileProvider)
|
2010-09-23 06:19:47 +03:00
|
|
|
{
|
2010-09-28 07:25:41 +03:00
|
|
|
_seriesProvider = seriesProvider;
|
2010-10-05 09:21:18 +03:00
|
|
|
_episodeProvider = episodeProvider;
|
2011-02-18 04:50:40 +02:00
|
|
|
_qualityProvider = qualityProvider;
|
2011-03-11 11:04:56 +02:00
|
|
|
_tvDbProvider = tvDbProvider;
|
2011-04-20 10:44:13 +03:00
|
|
|
_jobProvider = jobProvider;
|
2011-06-03 06:04:39 +03:00
|
|
|
_mediaFileProvider = mediaFileProvider;
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
{
|
2011-07-08 08:41:08 +03:00
|
|
|
var profiles = _qualityProvider.All();
|
2011-05-10 09:32:33 +03:00
|
|
|
ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name");
|
|
|
|
|
2010-09-23 06:19:47 +03:00
|
|
|
return View();
|
|
|
|
}
|
|
|
|
|
2011-05-10 09:32:33 +03:00
|
|
|
[GridAction]
|
|
|
|
public ActionResult _AjaxSeriesGrid()
|
|
|
|
{
|
2011-09-05 22:59:39 +03:00
|
|
|
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount()).OrderBy(o => SortHelper.SkipArticles(o.Title));
|
2011-05-10 09:32:33 +03:00
|
|
|
return View(new GridModel(series));
|
|
|
|
}
|
|
|
|
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
|
|
[GridAction]
|
2011-08-26 02:05:31 +03:00
|
|
|
public ActionResult _SaveAjaxSeriesEditing(int id, string path, bool monitored, bool seasonFolder, int qualityProfileId)
|
2011-05-10 09:32:33 +03:00
|
|
|
{
|
|
|
|
var oldSeries = _seriesProvider.GetSeries(id);
|
|
|
|
oldSeries.Monitored = monitored;
|
2011-05-12 05:53:19 +03:00
|
|
|
oldSeries.SeasonFolder = seasonFolder;
|
2011-05-10 09:32:33 +03:00
|
|
|
oldSeries.QualityProfileId = qualityProfileId;
|
2011-08-26 02:05:31 +03:00
|
|
|
oldSeries.Path = path;
|
2011-05-10 09:32:33 +03:00
|
|
|
|
|
|
|
_seriesProvider.UpdateSeries(oldSeries);
|
|
|
|
|
2011-09-07 09:43:10 +03:00
|
|
|
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount()).OrderBy(o => SortHelper.SkipArticles(o.Title));
|
2011-05-12 05:53:19 +03: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 09:43:10 +03:00
|
|
|
var seriesInDb = _seriesProvider.GetAllSeriesWithEpisodeCount().ToList();
|
2011-05-10 09:32:33 +03:00
|
|
|
|
2011-05-12 05:53:19 +03: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 09:32:33 +03:00
|
|
|
|
2011-05-12 05:53:19 +03:00
|
|
|
//Start removing this series
|
2011-05-17 10:04:49 +03:00
|
|
|
_jobProvider.QueueJob(typeof(DeleteSeriesJob), id);
|
2011-05-18 08:32:23 +03:00
|
|
|
|
2011-09-07 09:43:10 +03:00
|
|
|
var series = GetSeriesModels(seriesInDb).OrderBy(o => SortHelper.SkipArticles(o.Title));
|
2011-05-10 09:32:33 +03:00
|
|
|
return View(new GridModel(series));
|
|
|
|
}
|
|
|
|
|
2010-10-30 05:46:32 +03:00
|
|
|
[GridAction]
|
2011-06-04 04:56:53 +03:00
|
|
|
public ActionResult _AjaxSeasonGrid(int seriesId, int seasonNumber)
|
2010-10-08 08:04:25 +03:00
|
|
|
{
|
2011-06-23 09:56:17 +03:00
|
|
|
using (MiniProfiler.StepStatic("Controller"))
|
|
|
|
{
|
2011-12-02 19:14:38 +03:00
|
|
|
var episodes = GetEpisodeModels(_episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber)).OrderByDescending(e => e.EpisodeNumber);
|
2011-06-23 09:56:17 +03:00
|
|
|
return View(new GridModel(episodes));
|
|
|
|
}
|
2010-10-08 08:04:25 +03:00
|
|
|
}
|
|
|
|
|
2011-10-21 02:36:47 +03:00
|
|
|
public JsonResult LocalSearch(string term)
|
2011-03-11 11:04:56 +02:00
|
|
|
{
|
2011-10-21 02:36:47 +03:00
|
|
|
//Get Results from the local DB and return
|
2011-03-11 11:04:56 +02:00
|
|
|
|
2011-10-21 02:36:47 +03:00
|
|
|
var results = _seriesProvider.SearchForSeries(term).Select(s => new SeriesSearchResultModel
|
|
|
|
{
|
|
|
|
Id = s.SeriesId,
|
|
|
|
Title = s.Title
|
|
|
|
}).ToList();
|
2011-03-11 11:04:56 +02:00
|
|
|
|
2011-10-21 02:36:47 +03:00
|
|
|
return Json(results, JsonRequestBehavior.AllowGet);
|
2011-03-09 09:40:48 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 09:27:02 +03:00
|
|
|
[HttpPost]
|
2011-08-04 04:45:45 +03:00
|
|
|
public JsonResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored)
|
2011-05-16 09:27:02 +03:00
|
|
|
{
|
2011-08-04 04:45:45 +03:00
|
|
|
_episodeProvider.SetSeasonIgnore(seriesId, seasonNumber, ignored);
|
|
|
|
|
|
|
|
return new JsonResult { Data = "ok" };
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public JsonResult SaveEpisodeIgnore(int episodeId, bool ignored)
|
|
|
|
{
|
|
|
|
_episodeProvider.SetEpisodeIgnore(episodeId, ignored);
|
2011-05-16 09:27:02 +03:00
|
|
|
|
2011-06-05 08:23:50 +03:00
|
|
|
return new JsonResult { Data = "ok" };
|
2011-05-16 09:27:02 +03:00
|
|
|
}
|
|
|
|
|
2010-10-05 09:21:18 +03:00
|
|
|
public ActionResult Details(int seriesId)
|
2010-09-23 06:19:47 +03:00
|
|
|
{
|
2011-02-17 19:45:02 +02:00
|
|
|
var series = _seriesProvider.GetSeries(seriesId);
|
2011-06-04 04:56:53 +03: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 09:41:31 +03:00
|
|
|
model.Title = series.Title;
|
2011-06-04 04:56:53 +03:00
|
|
|
model.SeriesId = series.SeriesId;
|
2011-09-11 02:01:15 +03:00
|
|
|
model.HasBanner = !String.IsNullOrEmpty(series.BannerUrl);
|
2011-06-04 04:56:53 +03:00
|
|
|
|
|
|
|
return View(model);
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
2011-02-18 04:50:40 +02:00
|
|
|
|
2011-06-22 09:39:45 +03:00
|
|
|
private List<SeriesModel> GetSeriesModels(IList<Series> seriesInDb)
|
2011-05-12 05:53:19 +03:00
|
|
|
{
|
2011-06-20 10:13:17 +03: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 20:56:30 +03:00
|
|
|
EpisodeFileCount = s.EpisodeFileCount,
|
|
|
|
NextAiring = s.NextAiring == null ? String.Empty : s.NextAiring.Value.ToBestDateString()
|
2011-06-20 10:13:17 +03:00
|
|
|
}).ToList();
|
2011-05-12 05:53:19 +03:00
|
|
|
|
|
|
|
return series;
|
|
|
|
}
|
2011-05-16 09:27:02 +03:00
|
|
|
|
2011-06-06 01:19:07 +03:00
|
|
|
private List<EpisodeModel> GetEpisodeModels(IList<Episode> episodesInDb)
|
|
|
|
{
|
|
|
|
var episodes = new List<EpisodeModel>();
|
|
|
|
|
|
|
|
foreach (var e in episodesInDb)
|
|
|
|
{
|
|
|
|
var episodeFileId = 0;
|
2011-06-17 06:29:39 +03:00
|
|
|
var episodePath = String.Empty;
|
|
|
|
var episodeQuality = String.Empty;
|
|
|
|
|
2011-06-22 08:43:45 +03:00
|
|
|
if (e.EpisodeFile != null)
|
2011-06-06 01:19:07 +03:00
|
|
|
{
|
2011-06-22 08:43:45 +03:00
|
|
|
episodePath = e.EpisodeFile.Path;
|
|
|
|
episodeFileId = e.EpisodeFile.EpisodeFileId;
|
|
|
|
episodeQuality = e.EpisodeFile.Quality.ToString();
|
2011-06-06 01:19:07 +03:00
|
|
|
}
|
|
|
|
|
2011-06-23 21:37:17 +03:00
|
|
|
var airDate = String.Empty;
|
|
|
|
|
|
|
|
if (e.AirDate != null)
|
2011-09-28 03:10:08 +03:00
|
|
|
airDate = e.AirDate.Value.ToBestDateString();
|
2011-06-23 21:37:17 +03:00
|
|
|
|
2011-06-06 01:19:07 +03:00
|
|
|
episodes.Add(new EpisodeModel
|
|
|
|
{
|
|
|
|
EpisodeId = e.EpisodeId,
|
|
|
|
EpisodeNumber = e.EpisodeNumber,
|
|
|
|
SeasonNumber = e.SeasonNumber,
|
|
|
|
Title = e.Title,
|
|
|
|
Overview = e.Overview,
|
2011-06-23 21:37:17 +03:00
|
|
|
AirDate = airDate,
|
2011-06-06 01:19:07 +03:00
|
|
|
Path = episodePath,
|
|
|
|
EpisodeFileId = episodeFileId,
|
|
|
|
Status = e.Status.ToString(),
|
2011-08-03 10:26:39 +03:00
|
|
|
Quality = episodeQuality,
|
|
|
|
Ignored = e.Ignored
|
2011-06-06 01:19:07 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return episodes;
|
|
|
|
}
|
|
|
|
|
2011-05-16 09:27:02 +03:00
|
|
|
private string GetSeasonString(int seasonNumber)
|
|
|
|
{
|
|
|
|
if (seasonNumber == 0)
|
|
|
|
return "Specials";
|
|
|
|
|
2011-06-02 10:23:38 +03:00
|
|
|
return String.Format("Season #{0}", seasonNumber);
|
2011-05-16 09:27:02 +03:00
|
|
|
}
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|