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;
|
2010-09-28 06:25:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-20 09:44:13 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2010-10-30 04:46:32 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
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-05-10 08:32:33 +02:00
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles();
|
|
|
|
|
ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name");
|
|
|
|
|
|
2010-09-23 05:19:47 +02:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 02:30:59 +01:00
|
|
|
|
public ActionResult RssSync()
|
|
|
|
|
{
|
2011-05-17 09:04:49 +02:00
|
|
|
|
_jobProvider.QueueJob(typeof(RssSyncJob));
|
2011-01-31 02:30:59 +01:00
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 08:27:02 +02:00
|
|
|
|
public ActionResult SeasonEditor(int seriesId)
|
|
|
|
|
{
|
2011-06-04 03:56:53 +02:00
|
|
|
|
var model = new List<SeasonEditModel>();
|
|
|
|
|
|
|
|
|
|
var seasons = _episodeProvider.GetSeasons(seriesId);
|
|
|
|
|
|
|
|
|
|
foreach (var season in seasons)
|
|
|
|
|
{
|
|
|
|
|
var seasonEdit = new SeasonEditModel();
|
|
|
|
|
seasonEdit.Monitored = !_episodeProvider.IsIgnored(seriesId, season);
|
|
|
|
|
seasonEdit.SeasonNumber = season;
|
|
|
|
|
seasonEdit.SeriesId = seriesId;
|
|
|
|
|
seasonEdit.SeasonString = GetSeasonString(season);
|
|
|
|
|
|
|
|
|
|
model.Add(seasonEdit);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 08:27:02 +02:00
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult GetSingleSeasonView(SeasonEditModel model)
|
|
|
|
|
{
|
|
|
|
|
return PartialView("SingleSeason", model);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-10 08:32:33 +02:00
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _AjaxSeriesGrid()
|
|
|
|
|
{
|
2011-06-20 09:13:17 +02:00
|
|
|
|
var series = GetSeriesModels(_seriesProvider.GetAllSeriesWithEpisodeCount(true).ToList());
|
2011-05-10 08:32:33 +02:00
|
|
|
|
return View(new GridModel(series));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
|
|
|
[GridAction]
|
2011-06-05 07:23:50 +02:00
|
|
|
|
public ActionResult _SaveAjaxSeriesEditing(int id, string path, bool monitored, bool seasonFolder, int qualityProfileId, List<SeasonEditModel> seasonEditor)
|
2011-05-10 08:32:33 +02:00
|
|
|
|
{
|
|
|
|
|
var oldSeries = _seriesProvider.GetSeries(id);
|
|
|
|
|
oldSeries.Path = path;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
_seriesProvider.UpdateSeries(oldSeries);
|
|
|
|
|
|
2011-05-12 04:53:19 +02:00
|
|
|
|
var series = GetSeriesModels(_seriesProvider.GetAllSeries().ToList());
|
|
|
|
|
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-05-10 08:32:33 +02:00
|
|
|
|
var seriesInDb = _seriesProvider.GetAllSeries().ToList();
|
|
|
|
|
|
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-05-12 04:53:19 +02:00
|
|
|
|
var series = GetSeriesModels(seriesInDb);
|
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-06 00:19:07 +02:00
|
|
|
|
var episodes = GetEpisodeModels(_episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber));
|
2010-10-30 04:46:32 +02:00
|
|
|
|
return View(new GridModel(episodes));
|
2010-10-08 07:04:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 10:04:56 +01:00
|
|
|
|
public ActionResult SearchForSeries(string seriesName)
|
|
|
|
|
{
|
|
|
|
|
var model = new List<SeriesSearchResultModel>();
|
|
|
|
|
|
|
|
|
|
//Get Results from TvDb and convert them to something we can use.
|
2011-03-17 08:40:23 +01:00
|
|
|
|
foreach (var tvdbSearchResult in _tvDbProvider.SearchSeries(seriesName))
|
|
|
|
|
{
|
|
|
|
|
model.Add(new SeriesSearchResultModel
|
|
|
|
|
{
|
|
|
|
|
TvDbId = tvdbSearchResult.Id,
|
|
|
|
|
TvDbName = tvdbSearchResult.SeriesName,
|
|
|
|
|
FirstAired = tvdbSearchResult.FirstAired
|
|
|
|
|
});
|
|
|
|
|
}
|
2011-03-11 10:04:56 +01:00
|
|
|
|
|
2011-03-17 08:40:23 +01:00
|
|
|
|
//model.Add(new SeriesSearchResultModel{ TvDbId = 12345, TvDbName = "30 Rock", FirstAired = DateTime.Today });
|
|
|
|
|
//model.Add(new SeriesSearchResultModel { TvDbId = 65432, TvDbName = "The Office (US)", FirstAired = DateTime.Today.AddDays(-100) });
|
2011-03-11 10:04:56 +01:00
|
|
|
|
|
|
|
|
|
return PartialView("SeriesSearchResults", model);
|
2011-03-09 08:40:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 08:27:02 +02:00
|
|
|
|
[HttpPost]
|
2011-06-05 07:23:50 +02:00
|
|
|
|
public JsonResult SaveSeason(int seriesId, int seasonNumber, bool monitored)
|
2011-05-16 08:27:02 +02:00
|
|
|
|
{
|
2011-06-05 07:23:50 +02:00
|
|
|
|
if (_episodeProvider.IsIgnored(seriesId, seasonNumber) == monitored)
|
2011-05-16 08:27:02 +02:00
|
|
|
|
{
|
2011-06-05 07:23:50 +02:00
|
|
|
|
_episodeProvider.SetSeasonIgnore(seriesId, seasonNumber, !monitored);
|
2011-05-16 08:27:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-05 07:23:50 +02:00
|
|
|
|
return new JsonResult { Data = "ok" };
|
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;
|
|
|
|
|
|
|
|
|
|
return View(model);
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
2011-02-18 03:50:40 +01:00
|
|
|
|
|
2011-02-23 07:23:59 +01:00
|
|
|
|
public ActionResult SyncEpisodesOnDisk(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
//Syncs the episodes on disk for the specified series
|
2011-05-21 02:23:49 +02:00
|
|
|
|
_jobProvider.QueueJob(typeof(DiskScanJob), seriesId);
|
2011-02-23 07:23:59 +01:00
|
|
|
|
|
2011-04-20 03:20:20 +02:00
|
|
|
|
return RedirectToAction("Details", new { seriesId });
|
2011-02-23 07:23:59 +01:00
|
|
|
|
}
|
2011-02-23 07:49:02 +01:00
|
|
|
|
|
2011-04-20 09:44:13 +02:00
|
|
|
|
public ActionResult UpdateInfo(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
//Syncs the episodes on disk for the specified series
|
2011-05-17 09:04:49 +02:00
|
|
|
|
_jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId);
|
2011-04-20 09:44:13 +02:00
|
|
|
|
return RedirectToAction("Details", new { seriesId });
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-12 04:53:19 +02:00
|
|
|
|
private List<SeriesModel> GetSeriesModels(List<Series> seriesInDb)
|
|
|
|
|
{
|
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,
|
|
|
|
|
EpisodeFileCount = s.EpisodeFileCount
|
|
|
|
|
}).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;
|
|
|
|
|
EpisodeFile episodeFile = null;
|
|
|
|
|
|
|
|
|
|
if (e.EpisodeFileId > 0)
|
|
|
|
|
episodeFile = _mediaFileProvider.GetEpisodeFile(e.EpisodeFileId);
|
2011-06-06 00:19:07 +02:00
|
|
|
|
|
|
|
|
|
if (episodeFile != null)
|
|
|
|
|
{
|
|
|
|
|
episodePath = episodeFile.Path;
|
|
|
|
|
episodeFileId = episodeFile.EpisodeFileId;
|
2011-06-17 05:29:39 +02:00
|
|
|
|
episodeQuality = episodeFile.Quality.ToString();
|
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,
|
|
|
|
|
AirDate = e.AirDate,
|
|
|
|
|
Path = episodePath,
|
|
|
|
|
EpisodeFileId = episodeFileId,
|
|
|
|
|
Status = e.Status.ToString(),
|
2011-06-17 05:29:39 +02:00
|
|
|
|
Quality = episodeQuality
|
2011-06-06 00:19:07 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return episodes;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 08:27:02 +02:00
|
|
|
|
private string GetSeasonString(int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
if (seasonNumber == 0)
|
|
|
|
|
return "Specials";
|
|
|
|
|
|
2011-06-02 09:23:38 +02:00
|
|
|
|
return String.Format("Season #{0}", seasonNumber);
|
2011-05-16 08:27:02 +02:00
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|