From a950a13c300efa4f767daeafc1f89a4bda8fcd02 Mon Sep 17 00:00:00 2001 From: markus101 Date: Thu, 24 Feb 2011 17:18:22 -0800 Subject: [PATCH] Show Path to episode on disk in Details. Timer to cleanup/scan for EpisodeFiles (Midnight) Fixed Relationship for EpisodeFile to Series --- NzbDrone.Core/Providers/IMediaFileProvider.cs | 1 + NzbDrone.Core/Providers/SeriesProvider.cs | 2 +- NzbDrone.Core/Providers/TimerProvider.cs | 22 ++++++++++++++----- NzbDrone.Core/Repository/Episode.cs | 2 +- NzbDrone.Core/Repository/EpisodeFile.cs | 5 ++++- NzbDrone.Core/Repository/Series.cs | 2 +- NzbDrone.Web/Controllers/SeriesController.cs | 14 +++++++++++- NzbDrone.Web/Models/EpisodeModel.cs | 2 +- NzbDrone.Web/Views/Series/Details.aspx | 1 + 9 files changed, 40 insertions(+), 11 deletions(-) diff --git a/NzbDrone.Core/Providers/IMediaFileProvider.cs b/NzbDrone.Core/Providers/IMediaFileProvider.cs index 618af1f46..d7479c52f 100644 --- a/NzbDrone.Core/Providers/IMediaFileProvider.cs +++ b/NzbDrone.Core/Providers/IMediaFileProvider.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.Providers EpisodeFile ImportFile(Series series, string filePath); string GenerateEpisodePath(EpisodeModel episode); + void CleanUp(List files); void DeleteFromDb(int fileId); void DeleteFromDisk(int fileId, string path); void Update(EpisodeFile episodeFile); diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index bc4ff2c3c..b09a38fa7 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -132,7 +132,7 @@ namespace NzbDrone.Core.Providers //Can't use providers because episode provider needs series provider - Cyclic Dependency Injection, this will work Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId); - _sonioRepo.DeleteMany(series.Files); + _sonioRepo.DeleteMany(series.EpisodeFiles); Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId); _sonioRepo.DeleteMany(series.Episodes); diff --git a/NzbDrone.Core/Providers/TimerProvider.cs b/NzbDrone.Core/Providers/TimerProvider.cs index d53e9fce4..2aeccb290 100644 --- a/NzbDrone.Core/Providers/TimerProvider.cs +++ b/NzbDrone.Core/Providers/TimerProvider.cs @@ -10,22 +10,24 @@ namespace NzbDrone.Core.Providers { public class TimerProvider : ITimerProvider { - private IRssSyncProvider _rssSyncProvider; - private ISeriesProvider _seriesProvider; - private ISeasonProvider _seasonProvider; - private IEpisodeProvider _episodeProvider; + private readonly IRssSyncProvider _rssSyncProvider; + private readonly ISeriesProvider _seriesProvider; + private readonly ISeasonProvider _seasonProvider; + private readonly IEpisodeProvider _episodeProvider; + private readonly IMediaFileProvider _mediaFileProvider; private Timer _rssSyncTimer; private Timer _minuteTimer; private DateTime _rssSyncNextInterval; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public TimerProvider(IRssSyncProvider rssSyncProvider, ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider) + public TimerProvider(IRssSyncProvider rssSyncProvider, ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider, IMediaFileProvider mediaFileProvider) { _rssSyncProvider = rssSyncProvider; _seriesProvider = seriesProvider; _seasonProvider = seasonProvider; _episodeProvider = episodeProvider; + _mediaFileProvider = mediaFileProvider; _rssSyncTimer = new Timer(); _minuteTimer = new Timer(60000); @@ -117,6 +119,16 @@ namespace NzbDrone.Core.Providers } } + //Daily 00:00 (Midnight) - Cleanup (removed) EpisodeFiles + Scan for New EpisodeFiles + if (now.Hour == 0 && now.Minute == 0) + { + foreach (var series in _seriesProvider.GetAllSeries()) + { + _mediaFileProvider.CleanUp(series.EpisodeFiles); + _mediaFileProvider.Scan(series); + } + } + throw new NotImplementedException(); } } diff --git a/NzbDrone.Core/Repository/Episode.cs b/NzbDrone.Core/Repository/Episode.cs index 40c66cb25..f7e3ff41e 100644 --- a/NzbDrone.Core/Repository/Episode.cs +++ b/NzbDrone.Core/Repository/Episode.cs @@ -12,9 +12,9 @@ namespace NzbDrone.Core.Repository public virtual int EpisodeId { get; set; } public virtual int SeriesId { get; set; } public virtual int EpisodeFileId { get; set; } + public virtual int SeasonId { get; set; } public int SeasonNumber { get; set; } public int EpisodeNumber { get; set; } - public int SeasonId { get; set; } public string Title { get; set; } public DateTime AirDate { get; set; } [SubSonicLongString] diff --git a/NzbDrone.Core/Repository/EpisodeFile.cs b/NzbDrone.Core/Repository/EpisodeFile.cs index e3cb7177a..e3f96fda2 100644 --- a/NzbDrone.Core/Repository/EpisodeFile.cs +++ b/NzbDrone.Core/Repository/EpisodeFile.cs @@ -9,7 +9,7 @@ namespace NzbDrone.Core.Repository { [SubSonicPrimaryKey] public virtual int EpisodeFileId { get; set; } - public int SeriesId { get; set; } + public virtual int SeriesId { get; set; } public string Path { get; set; } public QualityTypes Quality { get; set; } public bool Proper { get; set; } @@ -18,5 +18,8 @@ namespace NzbDrone.Core.Repository [SubSonicToManyRelation] public virtual List Episodes { get; private set; } + + [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] + public virtual Series Series { get; private set; } } } diff --git a/NzbDrone.Core/Repository/Series.cs b/NzbDrone.Core/Repository/Series.cs index b8b032df4..de411c8ca 100644 --- a/NzbDrone.Core/Repository/Series.cs +++ b/NzbDrone.Core/Repository/Series.cs @@ -42,6 +42,6 @@ namespace NzbDrone.Core.Repository public virtual List Episodes { get; private set; } [SubSonicToManyRelation] - public virtual List Files { get; private set; } + public virtual List EpisodeFiles { get; private set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 746e13b58..0c4d55428 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Web; @@ -81,7 +82,8 @@ namespace NzbDrone.Web.Controllers SeasonNumber = c.SeasonNumber, Title = c.Title, Overview = c.Overview, - AirDate = c.AirDate + AirDate = c.AirDate, + Path = GetEpisodePath(c.EpisodeFile) }); return View(new GridModel(episodes)); } @@ -232,5 +234,15 @@ namespace NzbDrone.Web.Controllers _renameProvider.RenameEpisode(episodeId); return RedirectToAction("Index"); } + + //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); + } } } diff --git a/NzbDrone.Web/Models/EpisodeModel.cs b/NzbDrone.Web/Models/EpisodeModel.cs index 6447a3702..d31ae9a7c 100644 --- a/NzbDrone.Web/Models/EpisodeModel.cs +++ b/NzbDrone.Web/Models/EpisodeModel.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Web.Models public int EpisodeNumber { get; set; } public int SeasonNumber { get; set; } public string Overview { get; set; } - + public string Path { get; set; } public DateTime AirDate { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Series/Details.aspx b/NzbDrone.Web/Views/Series/Details.aspx index 02ffde03e..ee6f655ec 100644 --- a/NzbDrone.Web/Views/Series/Details.aspx +++ b/NzbDrone.Web/Views/Series/Details.aspx @@ -64,6 +64,7 @@ columns.Bound(c => c.EpisodeNumber).Width(0).Title("Episode"); columns.Bound(c => c.Title).Title("Title"); columns.Bound(c => c.AirDate).Format("{0:d}").Width(0); + columns.Bound(c => c.Path); }) //.DetailView(detailView => detailView.Template(e => Html.RenderPartial("EpisodeDetail", e))) .DetailView(detailView => detailView.ClientTemplate("
<#= Overview #>
"))