From cb992f1b520b55ef327953ef221c3fd5e0efbbc2 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 25 Apr 2011 22:54:12 -0700 Subject: [PATCH] Added StatsProvider. Bound AutoConfigureProvider to kernel. Feed Item Parsing will now check for a SceneName match in SceneNameHelper. --- NzbDrone.Core/CentralDispatch.cs | 1 + NzbDrone.Core/Helpers/SceneNameHelper.cs | 7 +- NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Providers/Indexer/IndexerProviderBase.cs | 27 ++++--- NzbDrone.Core/Providers/StatsProvider.cs | 78 +++++++++++++++++++ 5 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 NzbDrone.Core/Providers/StatsProvider.cs diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 65070a9a9..5ba34fb83 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -99,6 +99,7 @@ namespace NzbDrone.Core _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); + _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToMethod( c => new SimpleRepository(dbProvider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope(); diff --git a/NzbDrone.Core/Helpers/SceneNameHelper.cs b/NzbDrone.Core/Helpers/SceneNameHelper.cs index 73e50159e..47e07ef2c 100644 --- a/NzbDrone.Core/Helpers/SceneNameHelper.cs +++ b/NzbDrone.Core/Helpers/SceneNameHelper.cs @@ -7,6 +7,8 @@ namespace NzbDrone.Core.Helpers { public static class SceneNameHelper { + //Todo: Move this to a publically available location (so updates can be applied without releasing a new version of NzbDrone) + //Todo: GoogleDocs? WCF Web Services on NzbDrone.com? private static readonly List SceneNameMappings = new List { new SceneNameModel @@ -147,11 +149,6 @@ namespace NzbDrone.Core.Helpers SeriesId = 83714, Name = "Genius with Dave Gorman" }, - new SceneNameModel - { - SeriesId = 168161, - Name = "Law and Order Los Angeles" - }, new SceneNameModel { SeriesId = 168161, diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 0f9621696..6e715c37e 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -177,6 +177,7 @@ + diff --git a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs index aa7ed2111..863b3a8cd 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs @@ -4,6 +4,7 @@ using System.IO; using System.Net; using System.ServiceModel.Syndication; using NLog; +using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; @@ -147,17 +148,17 @@ namespace NzbDrone.Core.Providers.Indexer return; } - //var sabTitle = _sabProvider.GetSabTitle(parseResult); + var sabTitle = _sabProvider.GetSabTitle(parseResult); - //if (_sabProvider.IsInQueue(sabTitle)) - //{ - // return; - //} + if (_sabProvider.IsInQueue(sabTitle)) + { + return; + } - //if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle)) - //{ - // return; - //} + if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle)) + { + return; + } foreach (var episode in episodes) { @@ -185,6 +186,14 @@ namespace NzbDrone.Core.Providers.Indexer var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.CleanTitle); + if (seriesInfo == null) + { + var seriesId = SceneNameHelper.FindByName(episodeParseResult.CleanTitle); + + if (seriesId != 0) + seriesInfo = _seriesProvider.GetSeries(seriesId); + } + if (seriesInfo != null) { episodeParseResult.SeriesId = seriesInfo.SeriesId; diff --git a/NzbDrone.Core/Providers/StatsProvider.cs b/NzbDrone.Core/Providers/StatsProvider.cs new file mode 100644 index 000000000..a211fc564 --- /dev/null +++ b/NzbDrone.Core/Providers/StatsProvider.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Providers +{ + public class StatsProvider + { + private readonly SeriesProvider _seriesProvider; + + public StatsProvider(SeriesProvider seriesProvider) + { + _seriesProvider = seriesProvider; + } + + public virtual int SeriesCount() + { + return _seriesProvider.GetAllSeries().Count(); + } + + public virtual int ActiveSeriesCount() + { + return _seriesProvider.GetAllSeries().Where(s => s.Status == "Continuing").Count(); + } + + public virtual int EndedSeriesCount() + { + return _seriesProvider.GetAllSeries().Where(s => s.Status == "Ended").Count(); + } + + public virtual int TotalEpisodesCount() + { + var count = 0; + var series = _seriesProvider.GetAllSeries(); + foreach (var s in series) + { + count += s.Episodes.Count; + } + return count; + } + + public virtual int TotalAiredEpisodesCount() + { + var count = 0; + var series = _seriesProvider.GetAllSeries(); + foreach (var s in series) + { + count += s.Episodes.Where(e => e.AirDate.Date <= DateTime.Today).Count(); + } + return count; + } + + public virtual int TotalUnairedEpisodesCount() + { + var count = 0; + var series = _seriesProvider.GetAllSeries(); + foreach (var s in series) + { + count += s.Episodes.Where(e => e.AirDate.Date > DateTime.Today).Count(); + } + return count; + } + + public virtual int TotalEpisodesOnDisk() + { + var count = 0; + var series = _seriesProvider.GetAllSeries(); + foreach (var s in series) + { + count += s.Episodes.Where(e => e.EpisodeFileId != 0).Count(); + } + return count; + } + + + } +}