2010-09-23 03:19:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-02-25 01:18:22 +00:00
|
|
|
|
using System.IO;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
2010-09-28 04:25:41 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2010-10-30 02:46:32 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
using Telerik.Web.Mvc;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
2010-10-08 03:35:04 +00:00
|
|
|
|
[HandleError]
|
2010-09-23 03:19:47 +00:00
|
|
|
|
public class SeriesController : Controller
|
|
|
|
|
{
|
2011-04-10 00:14:51 +00:00
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
private readonly QualityProvider _qualityProvider;
|
2011-04-09 00:08:03 +00:00
|
|
|
|
private readonly RenameProvider _renameProvider;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-04-08 04:11:45 +00:00
|
|
|
|
private readonly TvDbProvider _tvDbProvider;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-05-16 06:27:02 +00:00
|
|
|
|
private readonly SeasonProvider _seasonProvider;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
//
|
|
|
|
|
// GET: /Series/
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
public SeriesController(SeriesProvider seriesProvider,
|
2011-04-20 01:20:20 +00:00
|
|
|
|
EpisodeProvider episodeProvider,
|
2011-05-22 17:29:10 +00:00
|
|
|
|
QualityProvider qualityProvider,
|
|
|
|
|
RenameProvider renameProvider,
|
|
|
|
|
TvDbProvider tvDbProvider,
|
|
|
|
|
JobProvider jobProvider,
|
2011-05-16 06:27:02 +00:00
|
|
|
|
SeasonProvider seasonProvider)
|
2010-09-23 03:19:47 +00:00
|
|
|
|
{
|
2010-09-28 04:25:41 +00:00
|
|
|
|
_seriesProvider = seriesProvider;
|
2010-10-05 06:21:18 +00:00
|
|
|
|
_episodeProvider = episodeProvider;
|
2011-02-18 02:50:40 +00:00
|
|
|
|
_qualityProvider = qualityProvider;
|
2011-02-23 06:49:02 +00:00
|
|
|
|
_renameProvider = renameProvider;
|
2011-03-11 09:04:56 +00:00
|
|
|
|
_tvDbProvider = tvDbProvider;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
_jobProvider = jobProvider;
|
2011-05-16 06:27:02 +00:00
|
|
|
|
_seasonProvider = seasonProvider;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2011-05-10 06:32:33 +00:00
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles();
|
|
|
|
|
ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name");
|
|
|
|
|
|
2010-09-23 03:19:47 +00:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 01:30:59 +00:00
|
|
|
|
public ActionResult RssSync()
|
|
|
|
|
{
|
2011-05-17 07:04:49 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(RssSyncJob));
|
2011-01-31 01:30:59 +00:00
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 06:21:18 +00:00
|
|
|
|
public ActionResult LoadEpisodes(int seriesId)
|
2010-09-23 03:19:47 +00:00
|
|
|
|
{
|
2010-10-17 17:22:48 +00:00
|
|
|
|
_episodeProvider.RefreshEpisodeInfo(seriesId);
|
2010-10-05 06:21:18 +00:00
|
|
|
|
return RedirectToAction("Details", new
|
2011-04-10 02:44:01 +00:00
|
|
|
|
{
|
|
|
|
|
seriesId
|
|
|
|
|
});
|
2010-09-23 03:19:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 06:27:02 +00:00
|
|
|
|
public ActionResult SeasonEditor(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
var model =
|
|
|
|
|
_seriesProvider.GetSeries(seriesId).Seasons.Select(s => new SeasonEditModel
|
|
|
|
|
{
|
|
|
|
|
SeasonId = s.SeasonId,
|
|
|
|
|
SeasonNumber = s.SeasonNumber,
|
|
|
|
|
SeasonString = GetSeasonString(s.SeasonNumber),
|
|
|
|
|
Monitored = s.Monitored
|
2011-05-18 05:32:23 +00:00
|
|
|
|
}).OrderBy(s => s.SeasonNumber).ToList();
|
2011-05-16 06:27:02 +00:00
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult GetSingleSeasonView(SeasonEditModel model)
|
|
|
|
|
{
|
|
|
|
|
return PartialView("SingleSeason", model);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-10 06:32:33 +00:00
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _AjaxSeriesGrid()
|
|
|
|
|
{
|
2011-05-12 02:53:19 +00:00
|
|
|
|
var series = GetSeriesModels(_seriesProvider.GetAllSeries().ToList());
|
2011-05-10 06:32:33 +00:00
|
|
|
|
|
|
|
|
|
return View(new GridModel(series));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
|
|
|
[GridAction]
|
2011-05-16 06:27:02 +00:00
|
|
|
|
public ActionResult _SaveAjaxSeriesEditing(int id, string path, bool monitored, bool seasonFolder, int qualityProfileId, List<SeasonEditModel> seasons)
|
2011-05-10 06:32:33 +00:00
|
|
|
|
{
|
|
|
|
|
var oldSeries = _seriesProvider.GetSeries(id);
|
|
|
|
|
oldSeries.Path = path;
|
|
|
|
|
oldSeries.Monitored = monitored;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
oldSeries.SeasonFolder = seasonFolder;
|
2011-05-10 06:32:33 +00:00
|
|
|
|
oldSeries.QualityProfileId = qualityProfileId;
|
|
|
|
|
|
|
|
|
|
_seriesProvider.UpdateSeries(oldSeries);
|
|
|
|
|
|
2011-05-12 02:53:19 +00: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 06:32:33 +00:00
|
|
|
|
var seriesInDb = _seriesProvider.GetAllSeries().ToList();
|
|
|
|
|
|
2011-05-12 02:53:19 +00: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 06:32:33 +00:00
|
|
|
|
|
2011-05-12 02:53:19 +00:00
|
|
|
|
//Start removing this series
|
2011-05-17 07:04:49 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(DeleteSeriesJob), id);
|
2011-05-18 05:32:23 +00:00
|
|
|
|
|
2011-05-12 02:53:19 +00:00
|
|
|
|
var series = GetSeriesModels(seriesInDb);
|
2011-05-10 06:32:33 +00:00
|
|
|
|
return View(new GridModel(series));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-30 02:46:32 +00:00
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _AjaxSeasonGrid(int seasonId)
|
2010-10-08 05:04:25 +00:00
|
|
|
|
{
|
2011-04-10 02:44:01 +00:00
|
|
|
|
var episodes = _episodeProvider.GetEpisodeBySeason(seasonId).Select(c => new EpisodeModel
|
|
|
|
|
{
|
|
|
|
|
EpisodeId = c.EpisodeId,
|
2011-04-22 00:30:19 +00:00
|
|
|
|
EpisodeNumber = c.EpisodeNumber,
|
|
|
|
|
SeasonNumber = c.SeasonNumber,
|
2011-04-10 02:44:01 +00:00
|
|
|
|
Title = c.Title,
|
|
|
|
|
Overview = c.Overview,
|
|
|
|
|
AirDate = c.AirDate,
|
2011-04-22 00:30:19 +00:00
|
|
|
|
Path = GetEpisodePath(c.EpisodeFile),
|
2011-05-22 17:29:10 +00:00
|
|
|
|
Status = c.Status.ToString(),
|
2011-04-22 00:30:19 +00:00
|
|
|
|
Quality = c.EpisodeFile == null
|
2011-04-10 02:44:01 +00:00
|
|
|
|
? String.Empty
|
2011-04-22 00:30:19 +00:00
|
|
|
|
: c.EpisodeFile.Quality.ToString()
|
2011-04-10 02:44:01 +00:00
|
|
|
|
});
|
2010-10-30 02:46:32 +00:00
|
|
|
|
return View(new GridModel(episodes));
|
2010-10-08 05:04:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-24 04:12:54 +00:00
|
|
|
|
//Local Helpers
|
|
|
|
|
private string GetEpisodePath(EpisodeFile file)
|
2010-10-08 05:50:01 +00:00
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
if (file == null)
|
|
|
|
|
return String.Empty;
|
|
|
|
|
|
|
|
|
|
//Return the path relative to the Series' Folder
|
|
|
|
|
return file.Path.Replace(file.Series.Path, "").Trim(Path.DirectorySeparatorChar);
|
2010-10-08 05:50:01 +00:00
|
|
|
|
}
|
2011-03-09 07:40:48 +00:00
|
|
|
|
|
2011-03-11 09:04:56 +00: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 07:40:23 +00:00
|
|
|
|
foreach (var tvdbSearchResult in _tvDbProvider.SearchSeries(seriesName))
|
|
|
|
|
{
|
|
|
|
|
model.Add(new SeriesSearchResultModel
|
|
|
|
|
{
|
|
|
|
|
TvDbId = tvdbSearchResult.Id,
|
|
|
|
|
TvDbName = tvdbSearchResult.SeriesName,
|
|
|
|
|
FirstAired = tvdbSearchResult.FirstAired
|
|
|
|
|
});
|
|
|
|
|
}
|
2011-03-11 09:04:56 +00:00
|
|
|
|
|
2011-03-17 07:40:23 +00: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 09:04:56 +00:00
|
|
|
|
|
|
|
|
|
return PartialView("SeriesSearchResults", model);
|
2011-03-09 07:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 00:48:09 +00:00
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _SaveAjaxEditing(string id)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("UnMapped");
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 06:27:02 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SaveSeasons(List<SeasonEditModel> seasons)
|
|
|
|
|
{
|
|
|
|
|
foreach (var season in seasons)
|
|
|
|
|
{
|
|
|
|
|
var seasonInDb = _seasonProvider.GetSeason(season.SeasonId);
|
|
|
|
|
seasonInDb.Monitored = season.Monitored;
|
|
|
|
|
_seasonProvider.SaveSeason(seasonInDb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Content("Saved");
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 06:21:18 +00:00
|
|
|
|
public ActionResult Details(int seriesId)
|
2010-09-23 03:19:47 +00:00
|
|
|
|
{
|
2011-02-17 17:45:02 +00:00
|
|
|
|
var series = _seriesProvider.GetSeries(seriesId);
|
|
|
|
|
return View(series);
|
2010-09-23 03:19:47 +00:00
|
|
|
|
}
|
2011-02-18 02:50:40 +00:00
|
|
|
|
|
2011-02-23 06:23:59 +00:00
|
|
|
|
public ActionResult SyncEpisodesOnDisk(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
//Syncs the episodes on disk for the specified series
|
2011-05-21 00:23:49 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(DiskScanJob), seriesId);
|
2011-02-23 06:23:59 +00:00
|
|
|
|
|
2011-04-20 01:20:20 +00:00
|
|
|
|
return RedirectToAction("Details", new { seriesId });
|
2011-02-23 06:23:59 +00:00
|
|
|
|
}
|
2011-02-23 06:49:02 +00:00
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
public ActionResult UpdateInfo(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
//Syncs the episodes on disk for the specified series
|
2011-05-17 07:04:49 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
return RedirectToAction("Details", new { seriesId });
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 06:49:02 +00:00
|
|
|
|
public ActionResult RenameAll()
|
|
|
|
|
{
|
|
|
|
|
_renameProvider.RenameAll();
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult RenameSeries(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
_renameProvider.RenameSeries(seriesId);
|
2011-04-20 01:20:20 +00:00
|
|
|
|
return RedirectToAction("Details", new { seriesId });
|
2011-02-23 06:49:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult RenameSeason(int seasonId)
|
|
|
|
|
{
|
|
|
|
|
//Todo: Stay of Series Detail... AJAX?
|
|
|
|
|
_renameProvider.RenameSeason(seasonId);
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult RenameEpisode(int episodeId)
|
|
|
|
|
{
|
|
|
|
|
//Todo: Stay of Series Detail... AJAX?
|
|
|
|
|
_renameProvider.RenameEpisode(episodeId);
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
2011-02-25 01:18:22 +00:00
|
|
|
|
|
2011-05-12 02:53:19 +00:00
|
|
|
|
private List<SeriesModel> GetSeriesModels(List<Series> seriesInDb)
|
|
|
|
|
{
|
|
|
|
|
var series = new List<SeriesModel>();
|
|
|
|
|
|
|
|
|
|
seriesInDb.ForEach(s => series.Add(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,
|
2011-05-12 05:21:48 +00:00
|
|
|
|
SeasonsCount = s.Seasons.Where(x => x.SeasonNumber > 0).Count(),
|
2011-05-12 02:53:19 +00:00
|
|
|
|
SeasonFolder = s.SeasonFolder,
|
|
|
|
|
Status = s.Status
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return series;
|
|
|
|
|
}
|
2011-05-16 06:27:02 +00:00
|
|
|
|
|
|
|
|
|
private string GetSeasonString(int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
if (seasonNumber == 0)
|
|
|
|
|
return "Specials";
|
|
|
|
|
|
|
|
|
|
return String.Format("Season# {0}", seasonNumber);
|
|
|
|
|
}
|
2010-09-23 03:19:47 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|