2010-09-23 05:19:47 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-03-10 08:49:59 +01:00
|
|
|
|
using System.Collections.Specialized;
|
2011-02-25 02:18:22 +01:00
|
|
|
|
using System.IO;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using System.Linq;
|
2010-10-30 04:46:32 +02:00
|
|
|
|
using System.Threading;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
2011-03-10 08:49:59 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
2010-09-28 06:25:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 05:50:12 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2010-10-30 04:46:32 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-03-31 04:56:00 +02:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-10-30 04:46:32 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
using Telerik.Web.Mvc;
|
2011-03-10 08:49:59 +01:00
|
|
|
|
using TvdbLib.Data;
|
|
|
|
|
using EpisodeModel = NzbDrone.Web.Models.EpisodeModel;
|
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
|
|
|
|
|
{
|
2010-09-28 06:25:41 +02:00
|
|
|
|
private readonly ISeriesProvider _seriesProvider;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
private readonly IEpisodeProvider _episodeProvider;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
private readonly ISyncProvider _syncProvider;
|
2011-01-31 02:30:59 +01:00
|
|
|
|
private readonly IRssSyncProvider _rssSyncProvider;
|
2011-02-18 03:50:40 +01:00
|
|
|
|
private readonly IQualityProvider _qualityProvider;
|
2011-02-23 07:23:59 +01:00
|
|
|
|
private readonly IMediaFileProvider _mediaFileProvider;
|
2011-02-23 07:49:02 +01:00
|
|
|
|
private readonly IRenameProvider _renameProvider;
|
2011-03-09 08:40:48 +01:00
|
|
|
|
private readonly IRootDirProvider _rootDirProvider;
|
2011-03-11 10:04:56 +01:00
|
|
|
|
private readonly ITvDbProvider _tvDbProvider;
|
2011-03-17 08:40:23 +01:00
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
2011-03-28 22:22:12 +02:00
|
|
|
|
private readonly IConfigProvider _configProvider;
|
2011-02-23 07:49:02 +01:00
|
|
|
|
|
2010-09-23 05:19:47 +02:00
|
|
|
|
//
|
|
|
|
|
// GET: /Series/
|
|
|
|
|
|
2011-02-23 07:23:59 +01:00
|
|
|
|
public SeriesController(ISyncProvider syncProvider, ISeriesProvider seriesProvider,
|
|
|
|
|
IEpisodeProvider episodeProvider, IRssSyncProvider rssSyncProvider,
|
2011-02-23 07:49:02 +01:00
|
|
|
|
IQualityProvider qualityProvider, IMediaFileProvider mediaFileProvider,
|
2011-03-11 10:04:56 +01:00
|
|
|
|
IRenameProvider renameProvider, IRootDirProvider rootDirProvider,
|
2011-03-28 22:22:12 +02:00
|
|
|
|
ITvDbProvider tvDbProvider, IDiskProvider diskProvider,
|
|
|
|
|
IConfigProvider configProvider)
|
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;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
_syncProvider = syncProvider;
|
2011-01-31 02:30:59 +01:00
|
|
|
|
_rssSyncProvider = rssSyncProvider;
|
2011-02-18 03:50:40 +01:00
|
|
|
|
_qualityProvider = qualityProvider;
|
2011-02-23 07:23:59 +01:00
|
|
|
|
_mediaFileProvider = mediaFileProvider;
|
2011-02-23 07:49:02 +01:00
|
|
|
|
_renameProvider = renameProvider;
|
2011-03-09 08:40:48 +01:00
|
|
|
|
_rootDirProvider = rootDirProvider;
|
2011-03-11 10:04:56 +01:00
|
|
|
|
_tvDbProvider = tvDbProvider;
|
2011-03-17 08:40:23 +01:00
|
|
|
|
_diskProvider = diskProvider;
|
2011-03-28 22:22:12 +02:00
|
|
|
|
_configProvider = configProvider;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2010-10-17 19:22:48 +02:00
|
|
|
|
ViewData.Model = _seriesProvider.GetAllSeries().ToList();
|
2010-09-23 05:19:47 +02:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2011-03-28 22:22:12 +02:00
|
|
|
|
|
|
|
|
|
|
2011-03-11 10:04:56 +01:00
|
|
|
|
|
2011-01-31 02:30:59 +01:00
|
|
|
|
public ActionResult RssSync()
|
|
|
|
|
{
|
|
|
|
|
_rssSyncProvider.Begin();
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 08:40:48 +01:00
|
|
|
|
public ActionResult UnMapped(string path)
|
2010-10-02 21:01:43 +02:00
|
|
|
|
{
|
2011-03-09 08:40:48 +01:00
|
|
|
|
return View(_syncProvider.GetUnmappedFolders(path).Select(c => new MappingModel() { Id = 1, Path = c }).ToList());
|
2010-10-02 21:01:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 08:21:18 +02:00
|
|
|
|
public ActionResult LoadEpisodes(int seriesId)
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2010-10-17 19:22:48 +02:00
|
|
|
|
_episodeProvider.RefreshEpisodeInfo(seriesId);
|
2010-10-05 08:21:18 +02:00
|
|
|
|
return RedirectToAction("Details", new
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2010-10-05 08:21:18 +02:00
|
|
|
|
seriesId = seriesId
|
|
|
|
|
});
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-30 04:46:32 +02:00
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _AjaxSeasonGrid(int seasonId)
|
2010-10-08 07:04:25 +02:00
|
|
|
|
{
|
2010-10-30 04:46:32 +02:00
|
|
|
|
var episodes = _episodeProvider.GetEpisodeBySeason(seasonId).Select(c => new EpisodeModel()
|
|
|
|
|
{
|
|
|
|
|
EpisodeId = c.EpisodeId,
|
|
|
|
|
EpisodeNumber = c.EpisodeNumber,
|
|
|
|
|
SeasonNumber = c.SeasonNumber,
|
|
|
|
|
Title = c.Title,
|
|
|
|
|
Overview = c.Overview,
|
2011-02-25 02:18:22 +01:00
|
|
|
|
AirDate = c.AirDate,
|
2011-03-31 04:56:00 +02:00
|
|
|
|
Path = GetEpisodePath(c.EpisodeFile),
|
|
|
|
|
Quality = c.EpisodeFile == null ? String.Empty : c.EpisodeFile.Quality.ToString()
|
|
|
|
|
|
2010-10-30 04:46:32 +02:00
|
|
|
|
});
|
|
|
|
|
return View(new GridModel(episodes));
|
2010-10-08 07:04:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-30 04:46:32 +02:00
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _CustomBinding(GridCommand command, int seasonId)
|
2010-10-08 07:50:01 +02:00
|
|
|
|
{
|
2010-10-30 04:46:32 +02:00
|
|
|
|
IEnumerable<Episode> data = GetData(command);
|
|
|
|
|
return View(new GridModel
|
|
|
|
|
{
|
|
|
|
|
Data = data,
|
|
|
|
|
Total = data.Count()
|
|
|
|
|
});
|
2010-10-08 07:50:01 +02:00
|
|
|
|
}
|
2011-03-09 08:40:48 +01:00
|
|
|
|
|
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _AjaxUnmappedFoldersGrid()
|
|
|
|
|
{
|
2011-03-10 08:49:59 +01:00
|
|
|
|
var unmappedList = new List<AddExistingSeriesModel>();
|
2011-03-09 08:40:48 +01:00
|
|
|
|
|
|
|
|
|
foreach (var folder in _rootDirProvider.GetAll())
|
2011-03-10 08:49:59 +01:00
|
|
|
|
{
|
|
|
|
|
foreach (var unmappedFolder in _syncProvider.GetUnmappedFolders(folder.Path))
|
|
|
|
|
{
|
|
|
|
|
var tvDbSeries = _seriesProvider.MapPathToSeries(unmappedFolder);
|
|
|
|
|
|
|
|
|
|
//We still want to show this series as unmapped, but we don't know what it will be when mapped
|
|
|
|
|
//Todo: Provide the user with a way to manually map a folder to a TvDb series (or make them rename the folder...)
|
|
|
|
|
if (tvDbSeries == null)
|
2011-03-31 04:56:00 +02:00
|
|
|
|
tvDbSeries = new TvdbSeries { Id = 0, SeriesName = String.Empty };
|
|
|
|
|
|
2011-03-10 08:49:59 +01:00
|
|
|
|
unmappedList.Add(new AddExistingSeriesModel
|
|
|
|
|
{
|
|
|
|
|
IsWanted = true,
|
|
|
|
|
Path = unmappedFolder,
|
2011-03-17 08:40:23 +01:00
|
|
|
|
PathEncoded = Url.Encode(unmappedFolder),
|
2011-03-10 08:49:59 +01:00
|
|
|
|
TvDbId = tvDbSeries.Id,
|
|
|
|
|
TvDbName = tvDbSeries.SeriesName
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(new GridModel(unmappedList));
|
|
|
|
|
}
|
2011-03-09 08:40:48 +01:00
|
|
|
|
|
2011-03-17 08:40:23 +01: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
|
|
|
|
}
|
|
|
|
|
|
2010-10-30 04:46:32 +02:00
|
|
|
|
private IEnumerable<Episode> GetData(GridCommand command)
|
2010-10-08 07:50:01 +02:00
|
|
|
|
{
|
2010-10-30 04:46:32 +02:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
/*
|
|
|
|
|
IQueryable<Episode> data = .Orders;
|
|
|
|
|
//Apply filtering
|
|
|
|
|
if (command.FilterDescriptors.Any())
|
|
|
|
|
{
|
|
|
|
|
data = data.Where(ExpressionBuilder.Expression<Order>(command.FilterDescriptors));
|
|
|
|
|
}
|
|
|
|
|
// Apply sorting
|
|
|
|
|
foreach (SortDescriptor sortDescriptor in command.SortDescriptors)
|
|
|
|
|
{
|
|
|
|
|
if (sortDescriptor.SortDirection == ListSortDirection.Ascending)
|
|
|
|
|
{
|
|
|
|
|
switch (sortDescriptor.Member)
|
|
|
|
|
{
|
|
|
|
|
case "OrderID":
|
|
|
|
|
data = data.OrderBy(ExpressionBuilder.Expression<Order, int>(sortDescriptor.Member));
|
|
|
|
|
break;
|
|
|
|
|
case "Customer.ContactName":
|
|
|
|
|
data = data.OrderBy(order => order.Customer.ContactName);
|
|
|
|
|
break;
|
|
|
|
|
case "ShipAddress":
|
|
|
|
|
data = data.OrderBy(order => order.ShipAddress);
|
|
|
|
|
break;
|
|
|
|
|
case "OrderDate":
|
|
|
|
|
data = data.OrderBy(order => order.OrderDate);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (sortDescriptor.Member)
|
|
|
|
|
{
|
|
|
|
|
case "OrderID":
|
|
|
|
|
data = data.OrderByDescending(order => order.OrderID);
|
|
|
|
|
break;
|
|
|
|
|
case "Customer.ContactName":
|
|
|
|
|
data = data.OrderByDescending(order => order.Customer.ContactName);
|
|
|
|
|
break;
|
|
|
|
|
case "ShipAddress":
|
|
|
|
|
data = data.OrderByDescending(order => order.ShipAddress);
|
|
|
|
|
break;
|
|
|
|
|
case "OrderDate":
|
|
|
|
|
data = data.OrderByDescending(order => order.OrderDate);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
count = data.Count();
|
|
|
|
|
// ... and paging
|
|
|
|
|
if (command.PageSize > 0)
|
2010-10-08 07:50:01 +02:00
|
|
|
|
{
|
2010-10-30 04:46:32 +02:00
|
|
|
|
data = data.Skip((command.Page - 1) * command.PageSize);
|
2010-10-08 07:50:01 +02:00
|
|
|
|
}
|
2010-10-30 04:46:32 +02:00
|
|
|
|
data = data.Take(command.PageSize);
|
|
|
|
|
return data;*/
|
2010-10-08 07:50:01 +02:00
|
|
|
|
}
|
2010-10-17 19:22:48 +02:00
|
|
|
|
|
2011-02-04 01:48:09 +01:00
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
|
|
|
[GridAction]
|
|
|
|
|
public ActionResult _SaveAjaxEditing(string id)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("UnMapped");
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
return View(series);
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
2011-02-18 03:50:40 +01:00
|
|
|
|
|
|
|
|
|
public ActionResult Edit(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles();
|
|
|
|
|
ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name");
|
|
|
|
|
|
|
|
|
|
var series = _seriesProvider.GetSeries(seriesId);
|
|
|
|
|
return View(series);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Edit(Series series)
|
|
|
|
|
{
|
|
|
|
|
//Need to add seriesProvider.Update
|
|
|
|
|
_seriesProvider.UpdateSeries(series);
|
|
|
|
|
return Content("Series Updated Successfully");
|
|
|
|
|
}
|
2011-02-18 07:49:23 +01:00
|
|
|
|
|
|
|
|
|
public ActionResult Delete(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
//Need to add seriesProvider.Update
|
|
|
|
|
_seriesProvider.DeleteSeries(seriesId);
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("Index", "Series");
|
|
|
|
|
}
|
2011-02-23 07:23:59 +01:00
|
|
|
|
|
|
|
|
|
public ActionResult SyncEpisodesOnDisk(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
//Syncs the episodes on disk for the specified series
|
|
|
|
|
var series = _seriesProvider.GetSeries(seriesId);
|
|
|
|
|
_mediaFileProvider.Scan(series);
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("Details", new { seriesId });
|
|
|
|
|
}
|
2011-02-23 07:49:02 +01:00
|
|
|
|
|
|
|
|
|
public ActionResult RenameAll()
|
|
|
|
|
{
|
|
|
|
|
_renameProvider.RenameAll();
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult RenameSeries(int seriesId)
|
|
|
|
|
{
|
|
|
|
|
_renameProvider.RenameSeries(seriesId);
|
2011-02-25 04:52:06 +01:00
|
|
|
|
return RedirectToAction("Details", new { seriesId });
|
2011-02-23 07:49:02 +01: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 02:18:22 +01:00
|
|
|
|
|
|
|
|
|
//Local Helpers
|
|
|
|
|
private string GetEpisodePath(EpisodeFile file)
|
|
|
|
|
{
|
|
|
|
|
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-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|