From 62b2cd510f40e8711ab8fbb68b8f58c4b5a8454f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 3 Apr 2011 20:50:12 -0700 Subject: [PATCH] started rss cleanup --- NzbDrone.Core.Test/DbConfigControllerTest.cs | 1 + NzbDrone.Core.Test/IndexerProviderTest.cs | 1 + NzbDrone.Core.Test/MediaFileProviderTests.cs | 1 + NzbDrone.Core.Test/MockLib.cs | 1 + NzbDrone.Core.Test/RssProviderTest.cs | 1 + NzbDrone.Core.Test/SabControllerTest.cs | 1 + NzbDrone.Core/CentralDispatch.cs | 1 + NzbDrone.Core/Helpers/SceneNameHelper.cs | 6 +- NzbDrone.Core/Model/EpisodeParseResult.cs | 8 +- NzbDrone.Core/Model/NzbInfoModel.cs | 3 - NzbDrone.Core/Model/NzbSiteModel.cs | 37 ------- NzbDrone.Core/Model/Season.cs | 21 ---- NzbDrone.Core/Model/SeasonModel.cs | 15 --- NzbDrone.Core/Model/SeriesMappingModel.cs | 14 --- NzbDrone.Core/NzbDrone.Core.csproj | 24 +++-- NzbDrone.Core/Parser.cs | 35 ++++--- NzbDrone.Core/Providers/BacklogProvider.cs | 1 + .../Providers/{ => Core}/ConfigProvider.cs | 2 +- .../Providers/{ => Core}/DiskProvider.cs | 2 +- .../Providers/{ => Core}/HttpProvider.cs | 2 +- .../Providers/{ => Core}/IConfigProvider.cs | 2 +- .../Providers/{ => Core}/IDiskProvider.cs | 2 +- .../Providers/{ => Core}/IHttpProvider.cs | 2 +- .../Providers/{ => Core}/IRssProvider.cs | 7 +- .../Providers/{ => Core}/RssProvider.cs | 3 +- .../Providers/ExternalNotificationProvider.cs | 1 + NzbDrone.Core/Providers/FeedProviderBase.cs | 85 ++++++++++++++++ .../Providers/IRssItemProcessingProvider.cs | 2 +- NzbDrone.Core/Providers/IndexerProvider.cs | 1 + NzbDrone.Core/Providers/MediaFileProvider.cs | 10 +- .../Providers/PostProcessingProvider.cs | 1 + NzbDrone.Core/Providers/RenameProvider.cs | 1 + .../Providers/RssItemProcessingProvider.cs | 96 +++++++------------ NzbDrone.Core/Providers/RssSyncProvider.cs | 1 + NzbDrone.Core/Providers/SabProvider.cs | 1 + NzbDrone.Core/Providers/SeriesProvider.cs | 1 + NzbDrone.Core/Providers/SyncProvider.cs | 1 + NzbDrone.Core/Providers/XbmcProvider.cs | 1 + .../Controllers/AddSeriesController.cs | 1 + NzbDrone.Web/Controllers/ApiController.cs | 1 + NzbDrone.Web/Controllers/SeriesController.cs | 1 + .../Controllers/SettingsController.cs | 1 + NzbDrone.sln | 4 - 43 files changed, 187 insertions(+), 216 deletions(-) delete mode 100644 NzbDrone.Core/Model/NzbSiteModel.cs delete mode 100644 NzbDrone.Core/Model/Season.cs delete mode 100644 NzbDrone.Core/Model/SeasonModel.cs delete mode 100644 NzbDrone.Core/Model/SeriesMappingModel.cs rename NzbDrone.Core/Providers/{ => Core}/ConfigProvider.cs (99%) rename NzbDrone.Core/Providers/{ => Core}/DiskProvider.cs (96%) rename NzbDrone.Core/Providers/{ => Core}/HttpProvider.cs (98%) rename NzbDrone.Core/Providers/{ => Core}/IConfigProvider.cs (96%) rename NzbDrone.Core/Providers/{ => Core}/IDiskProvider.cs (92%) rename NzbDrone.Core/Providers/{ => Core}/IHttpProvider.cs (88%) rename NzbDrone.Core/Providers/{ => Core}/IRssProvider.cs (55%) rename NzbDrone.Core/Providers/{ => Core}/RssProvider.cs (95%) create mode 100644 NzbDrone.Core/Providers/FeedProviderBase.cs diff --git a/NzbDrone.Core.Test/DbConfigControllerTest.cs b/NzbDrone.Core.Test/DbConfigControllerTest.cs index 456c46a3c..0c3fa2ff4 100644 --- a/NzbDrone.Core.Test/DbConfigControllerTest.cs +++ b/NzbDrone.Core.Test/DbConfigControllerTest.cs @@ -6,6 +6,7 @@ using MbUnit.Framework; using MbUnit.Framework.ContractVerifiers; using Moq; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using SubSonic.Repository; diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index da057daf3..2f015ca18 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -7,6 +7,7 @@ using MbUnit.Framework; using MbUnit.Framework.ContractVerifiers; using Moq; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using SubSonic.Repository; diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index 1498ea563..9c82eec06 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -11,6 +11,7 @@ using Ninject; using Ninject.Moq; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using SubSonic.Repository; diff --git a/NzbDrone.Core.Test/MockLib.cs b/NzbDrone.Core.Test/MockLib.cs index b05505196..4713adb3a 100644 --- a/NzbDrone.Core.Test/MockLib.cs +++ b/NzbDrone.Core.Test/MockLib.cs @@ -9,6 +9,7 @@ using Moq; using NLog; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using SubSonic.DataProviders; using SubSonic.Repository; using TvdbLib; diff --git a/NzbDrone.Core.Test/RssProviderTest.cs b/NzbDrone.Core.Test/RssProviderTest.cs index bf95ed775..003c97d6d 100644 --- a/NzbDrone.Core.Test/RssProviderTest.cs +++ b/NzbDrone.Core.Test/RssProviderTest.cs @@ -8,6 +8,7 @@ using MbUnit.Framework.ContractVerifiers; using Moq; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using Rss; namespace NzbDrone.Core.Test diff --git a/NzbDrone.Core.Test/SabControllerTest.cs b/NzbDrone.Core.Test/SabControllerTest.cs index 36f347f2e..8bc5cc433 100644 --- a/NzbDrone.Core.Test/SabControllerTest.cs +++ b/NzbDrone.Core.Test/SabControllerTest.cs @@ -7,6 +7,7 @@ using MbUnit.Framework; using MbUnit.Framework.ContractVerifiers; using Moq; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using SubSonic.Repository; namespace NzbDrone.Core.Test diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 53ba15338..62dc42127 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -8,6 +8,7 @@ using NLog.Config; using NLog.Targets; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Fakes; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; diff --git a/NzbDrone.Core/Helpers/SceneNameHelper.cs b/NzbDrone.Core/Helpers/SceneNameHelper.cs index 60dcd98ff..91afad92f 100644 --- a/NzbDrone.Core/Helpers/SceneNameHelper.cs +++ b/NzbDrone.Core/Helpers/SceneNameHelper.cs @@ -8,7 +8,7 @@ namespace NzbDrone.Core.Helpers { public static class SceneNameHelper { - private static List _sceneNameMappings = new List + private static readonly List SceneNameMappings = new List { new SceneNameModel { SeriesId = 72546, Name = "CSI" }, new SceneNameModel { SeriesId = 73696, Name = "CSI New York" }, @@ -76,7 +76,7 @@ namespace NzbDrone.Core.Helpers public static int FindByName(string cleanSeriesName) { - var map = _sceneNameMappings.Find(s => Parser.NormalizeTitle(s.Name) == cleanSeriesName); + var map = SceneNameMappings.Find(s => Parser.NormalizeTitle(s.Name) == cleanSeriesName); if (map == null) return 0; @@ -88,7 +88,7 @@ namespace NzbDrone.Core.Helpers { List results = new List(); - var maps = _sceneNameMappings.Where(s => s.SeriesId == seriesId); + var maps = SceneNameMappings.Where(s => s.SeriesId == seriesId); foreach (var map in maps) results.Add(map.Name); diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index cafde35f4..6c24b5551 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -1,5 +1,5 @@ -using NzbDrone.Core.Repository.Quality; -using SubSonic.SqlGeneration.Schema; +using System; +using System.Collections.Generic; namespace NzbDrone.Core.Model { @@ -7,12 +7,12 @@ namespace NzbDrone.Core.Model { internal string SeriesTitle { get; set; } internal int SeasonNumber { get; set; } - internal int EpisodeNumber { get; set; } + internal List Episodes { get; set; } internal int Year { get; set; } public override string ToString() { - return string.Format("Series:{0} Season:{1} Episode:{2}", SeriesTitle, SeasonNumber, EpisodeNumber); + return string.Format("Series:{0} Season:{1} Episode:{2}", SeriesTitle, SeasonNumber, String.Join(",", Episodes)); } } diff --git a/NzbDrone.Core/Model/NzbInfoModel.cs b/NzbDrone.Core/Model/NzbInfoModel.cs index 8c92611e3..aa816e431 100644 --- a/NzbDrone.Core/Model/NzbInfoModel.cs +++ b/NzbDrone.Core/Model/NzbInfoModel.cs @@ -9,12 +9,9 @@ namespace NzbDrone.Core.Model { public class NzbInfoModel { - public string Id { get; set; } public string Title { get; set; } public string TitleFix { get; set; } - public NzbSiteModel Site { get; set; } public Uri Link { get; set; } - public string Description { get; set; } public bool Proper { get; set; } public QualityTypes Quality { get; set; } diff --git a/NzbDrone.Core/Model/NzbSiteModel.cs b/NzbDrone.Core/Model/NzbSiteModel.cs deleted file mode 100644 index f7be4741b..000000000 --- a/NzbDrone.Core/Model/NzbSiteModel.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace NzbDrone.Core.Model -{ - public class NzbSiteModel - { - private static readonly IList Sites = new List - { - new NzbSiteModel {Name = "newzbin", Url = "newzbin.com", Pattern = @"\d{7,10}"}, - new NzbSiteModel {Name = "nzbmatrix", Url = "nzbmatrix.com", Pattern = @"\d{6,10}"}, - new NzbSiteModel {Name = "nzbsDotOrg", Url = "nzbs.org", Pattern = @"\d{5,10}"}, - new NzbSiteModel {Name = "nzbsrus", Url = "nzbsrus.com", Pattern = @"\d{6,10}"}, - new NzbSiteModel {Name = "lilx", Url = "lilx.net", Pattern = @"\d{6,10}"}, - }; - - public string Name { get; set; } - public string Pattern { get; set; } - public string Url { get; set; } - - // TODO: use HttpUtility.ParseQueryString(); - // https://nzbmatrix.com/api-nzb-download.php?id=626526 - public string ParseId(string url) - { - return Regex.Match(url, Pattern).Value; - } - - public static NzbSiteModel Parse(string url) - { - return Sites.Where(site => url.Contains(site.Url)).SingleOrDefault() ?? - new NzbSiteModel { Name = "unknown", Pattern = @"\d{6,10}" }; - } - } -} diff --git a/NzbDrone.Core/Model/Season.cs b/NzbDrone.Core/Model/Season.cs deleted file mode 100644 index 42e5ad1fd..000000000 --- a/NzbDrone.Core/Model/Season.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using SubSonic.SqlGeneration.Schema; - -namespace NzbDrone.Core.Repository -{ - public class Season - { - [SubSonicPrimaryKey(false)] - public virtual long SeasonId { get; set; } - public long SeriesId { get; set; } - public int SeasonNumber { get; set; } - public bool Monitored { get; set; } - public string Folder { get; set; } - - [SubSonicToManyRelation] - public virtual List Episodes { get; private set; } - - [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] - public virtual Series Series { get; private set; } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Model/SeasonModel.cs b/NzbDrone.Core/Model/SeasonModel.cs deleted file mode 100644 index c23be62cf..000000000 --- a/NzbDrone.Core/Model/SeasonModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using NzbDrone.Core.Repository.Quality; -using SubSonic.SqlGeneration.Schema; - -namespace NzbDrone.Core.Model -{ - public class SeasonModel - { - public string SeriesTitle { get; set; } - public int SeriesId { get; set; } - public int SeasonNumber { get; set; } - public QualityTypes Quality { get; set; } - public long Size { get; set; } - public bool Proper { get; set; } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Model/SeriesMappingModel.cs b/NzbDrone.Core/Model/SeriesMappingModel.cs deleted file mode 100644 index 91522c3f6..000000000 --- a/NzbDrone.Core/Model/SeriesMappingModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NzbDrone.Core.Model -{ - public class SeriesMappingModel - { - public string Path { get; set; } - public int TvDbId { get; set; } - public int QualityProfileId { get; set; } - } -} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index eac082a46..1db86fbc6 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -168,21 +168,19 @@ - - - + - - + + @@ -196,7 +194,7 @@ - + @@ -206,7 +204,7 @@ - + @@ -224,12 +222,12 @@ - + - + - + @@ -247,9 +245,9 @@ - - - + + + diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index 8e1af4c82..befcdfc74 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -34,11 +34,11 @@ namespace NzbDrone.Core /// /// Title of the report /// List of episodes contained to the post - internal static List ParseEpisodeInfo(string title) + internal static EpisodeParseResult ParseEpisodeInfo(string title) { Logger.Trace("Parsing string '{0}'", title); - var result = new List(); + var result = new EpisodeParseResult(); foreach (var regex in ReportTitleRegex) { @@ -55,22 +55,22 @@ namespace NzbDrone.Core year = 0; } - foreach (Match matchGroup in match) + var parsedEpisode = new EpisodeParseResult { + SeriesTitle = seriesName, + SeasonNumber = Convert.ToInt32(match[0].Groups["season"].Value), + Year = year, + Episodes = new List() + }; - var parsedEpisode = new EpisodeParseResult - { - SeriesTitle = seriesName, - SeasonNumber = Convert.ToInt32(matchGroup.Groups["season"].Value), - EpisodeNumber = Convert.ToInt32(matchGroup.Groups["episode"].Value), - Year = year - }; + foreach (Match matchGroup in match) + { + parsedEpisode.Episodes.Add(Convert.ToInt32(matchGroup.Groups["episode"].Value)); + } - result.Add(parsedEpisode); + Logger.Trace("Episode Parsed. {0}", parsedEpisode); - Logger.Trace("Episode Parsed. {0}", parsedEpisode); - } break; //Break out of the for loop, we don't want to process every REGEX for each item otherwise we'll get duplicates } } @@ -111,7 +111,7 @@ namespace NzbDrone.Core Year = year }; - + Logger.Trace("Season Parsed. {0}", result); return result; @@ -257,14 +257,11 @@ namespace NzbDrone.Core public static NzbInfoModel ParseNzbInfo(FeedInfoModel feed, RssItem item) { - NzbSiteModel site = NzbSiteModel.Parse(feed.Url.ToLower()); + return new NzbInfoModel { - Id = site.ParseId(item.Link.ToString()), Title = item.Title, - Site = site, - Link = item.Link, - Description = item.Description + Link = item.Link }; } } diff --git a/NzbDrone.Core/Providers/BacklogProvider.cs b/NzbDrone.Core/Providers/BacklogProvider.cs index a4bda3e4b..920626e80 100644 --- a/NzbDrone.Core/Providers/BacklogProvider.cs +++ b/NzbDrone.Core/Providers/BacklogProvider.cs @@ -8,6 +8,7 @@ using NLog; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using Rss; diff --git a/NzbDrone.Core/Providers/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs similarity index 99% rename from NzbDrone.Core/Providers/ConfigProvider.cs rename to NzbDrone.Core/Providers/Core/ConfigProvider.cs index 044e165ce..dfd0c01c2 100644 --- a/NzbDrone.Core/Providers/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -3,7 +3,7 @@ using NLog; using NzbDrone.Core.Repository; using SubSonic.Repository; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { public class ConfigProvider : IConfigProvider { diff --git a/NzbDrone.Core/Providers/DiskProvider.cs b/NzbDrone.Core/Providers/Core/DiskProvider.cs similarity index 96% rename from NzbDrone.Core/Providers/DiskProvider.cs rename to NzbDrone.Core/Providers/Core/DiskProvider.cs index e87263262..4921ec98e 100644 --- a/NzbDrone.Core/Providers/DiskProvider.cs +++ b/NzbDrone.Core/Providers/Core/DiskProvider.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { public class DiskProvider : IDiskProvider { diff --git a/NzbDrone.Core/Providers/HttpProvider.cs b/NzbDrone.Core/Providers/Core/HttpProvider.cs similarity index 98% rename from NzbDrone.Core/Providers/HttpProvider.cs rename to NzbDrone.Core/Providers/Core/HttpProvider.cs index 8fc7b587e..b07c18071 100644 --- a/NzbDrone.Core/Providers/HttpProvider.cs +++ b/NzbDrone.Core/Providers/Core/HttpProvider.cs @@ -2,7 +2,7 @@ using System.Net; using NLog; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { internal class HttpProvider : IHttpProvider { diff --git a/NzbDrone.Core/Providers/IConfigProvider.cs b/NzbDrone.Core/Providers/Core/IConfigProvider.cs similarity index 96% rename from NzbDrone.Core/Providers/IConfigProvider.cs rename to NzbDrone.Core/Providers/Core/IConfigProvider.cs index 67979c576..536753af2 100644 --- a/NzbDrone.Core/Providers/IConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/IConfigProvider.cs @@ -1,6 +1,6 @@ using System; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { public interface IConfigProvider { diff --git a/NzbDrone.Core/Providers/IDiskProvider.cs b/NzbDrone.Core/Providers/Core/IDiskProvider.cs similarity index 92% rename from NzbDrone.Core/Providers/IDiskProvider.cs rename to NzbDrone.Core/Providers/Core/IDiskProvider.cs index bf17cf1d1..e0d115bc8 100644 --- a/NzbDrone.Core/Providers/IDiskProvider.cs +++ b/NzbDrone.Core/Providers/Core/IDiskProvider.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { public interface IDiskProvider { diff --git a/NzbDrone.Core/Providers/IHttpProvider.cs b/NzbDrone.Core/Providers/Core/IHttpProvider.cs similarity index 88% rename from NzbDrone.Core/Providers/IHttpProvider.cs rename to NzbDrone.Core/Providers/Core/IHttpProvider.cs index 3b8d78702..e10a6849a 100644 --- a/NzbDrone.Core/Providers/IHttpProvider.cs +++ b/NzbDrone.Core/Providers/Core/IHttpProvider.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { public interface IHttpProvider { diff --git a/NzbDrone.Core/Providers/IRssProvider.cs b/NzbDrone.Core/Providers/Core/IRssProvider.cs similarity index 55% rename from NzbDrone.Core/Providers/IRssProvider.cs rename to NzbDrone.Core/Providers/Core/IRssProvider.cs index 85e52f952..45da1442e 100644 --- a/NzbDrone.Core/Providers/IRssProvider.cs +++ b/NzbDrone.Core/Providers/Core/IRssProvider.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; using NzbDrone.Core.Model; using Rss; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { public interface IRssProvider { diff --git a/NzbDrone.Core/Providers/RssProvider.cs b/NzbDrone.Core/Providers/Core/RssProvider.cs similarity index 95% rename from NzbDrone.Core/Providers/RssProvider.cs rename to NzbDrone.Core/Providers/Core/RssProvider.cs index 495ccf109..017c26630 100644 --- a/NzbDrone.Core/Providers/RssProvider.cs +++ b/NzbDrone.Core/Providers/Core/RssProvider.cs @@ -1,12 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using NLog; using NzbDrone.Core.Model; using Rss; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.Providers.Core { public class RssProvider : IRssProvider { diff --git a/NzbDrone.Core/Providers/ExternalNotificationProvider.cs b/NzbDrone.Core/Providers/ExternalNotificationProvider.cs index e4c9fcbd7..5c397d268 100644 --- a/NzbDrone.Core/Providers/ExternalNotificationProvider.cs +++ b/NzbDrone.Core/Providers/ExternalNotificationProvider.cs @@ -5,6 +5,7 @@ using System.Text; using NLog; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; namespace NzbDrone.Core.Providers diff --git a/NzbDrone.Core/Providers/FeedProviderBase.cs b/NzbDrone.Core/Providers/FeedProviderBase.cs new file mode 100644 index 000000000..cda12260d --- /dev/null +++ b/NzbDrone.Core/Providers/FeedProviderBase.cs @@ -0,0 +1,85 @@ +using System; +using System.ServiceModel.Syndication; +using System.Xml; +using NLog; +using NzbDrone.Core.Model; +using NzbDrone.Core.Repository; + +namespace NzbDrone.Core.Providers +{ + abstract class FeedProviderBase + { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Gets the source URL for the feed + /// + protected abstract string[] URL { get; } + + /// + /// Gets the name for this feed + /// + protected abstract string Name { get; } + + + public void Fetch() + { + Logger.Info("Fetching feeds from " + Name); + + foreach (var url in URL) + { + var feed = SyndicationFeed.Load(XmlReader.Create(url)).Items; + + foreach (var item in feed) + { + ProcessItem(item); + } + } + + + Logger.Info("Finished processing feeds from " + Name); + } + + private void ProcessItem(SyndicationItem item) + { + var parseResult = ParseFeed(item); + } + + + public void DownloadIfWanted(NzbInfoModel nzb, Indexer indexer) + { + if (nzb.IsPassworded()) + { + Logger.Debug("Skipping Passworded Report {0}", nzb.Title); + return; + } + + var episodeParseResults = Parser.ParseEpisodeInfo(nzb.Title); + + if (episodeParseResults.Episodes.Count > 0) + { + //ProcessStandardItem(nzb, indexer, episodeParseResults); + return; + } + + //Handles Full Season NZBs + var seasonParseResult = Parser.ParseSeasonInfo(nzb.Title); + + if (seasonParseResult != null) + { + //ProcessFullSeasonItem(nzb, indexer, seasonParseResult); + return; + } + + Logger.Debug("Unsupported Title: {0}", nzb.Title); + + } + + + protected EpisodeParseResult ParseFeed(SyndicationItem item) + { + return Parser.ParseEpisodeInfo(item.Title.ToString()); + } + } + +} diff --git a/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs b/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs index 32911e591..adcbd099c 100644 --- a/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs +++ b/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs @@ -12,6 +12,6 @@ namespace NzbDrone.Core.Providers //This interface will contain methods to process individual RSS Feed Items (Queue if wanted) void DownloadIfWanted(NzbInfoModel nzb, Indexer indexer); - string GetTitleFix(List episodes, int seriesId); + string GetTitleFix(EpisodeParseResult episodes, int seriesId); } } diff --git a/NzbDrone.Core/Providers/IndexerProvider.cs b/NzbDrone.Core/Providers/IndexerProvider.cs index d7f044d81..4c1c036d8 100644 --- a/NzbDrone.Core/Providers/IndexerProvider.cs +++ b/NzbDrone.Core/Providers/IndexerProvider.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using NLog; using NzbDrone.Core.Model; +using NzbDrone.Core.Providers.Core; using SubSonic.Repository; using NzbDrone.Core.Repository; diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 592d96ba5..2f6abf600 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -6,6 +6,7 @@ using System.Text; using System.Text.RegularExpressions; using NLog; using NzbDrone.Core.Model; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using SubSonic.Repository; @@ -76,18 +77,17 @@ namespace NzbDrone.Core.Providers //Stores the list of episodes to add to the EpisodeFile var episodes = new List(); - foreach (var parsedEpisode in episodesInFile) + foreach (var episodeNumber in episodesInFile.Episodes) { - EpisodeParseResult closureEpisode = parsedEpisode; - var episode = _episodeProvider.GetEpisode(series.SeriesId, closureEpisode.SeasonNumber, - closureEpisode.EpisodeNumber); + var episode = _episodeProvider.GetEpisode(series.SeriesId, episodesInFile.SeasonNumber, episodeNumber); + if (episode != null) { episodes.Add(episode); } else - Logger.Warn("Unable to find Series:{0} Season:{1} Episode:{2} in the database. File:{3}", series.Title, closureEpisode.SeasonNumber, closureEpisode.EpisodeNumber, filePath); + Logger.Warn("Unable to find Series:{0} Season:{1} Episode:{2} in the database. File:{3}", series.Title, episodesInFile.SeasonNumber, episodeNumber, filePath); } //Return null if no Episodes exist in the DB for the parsed episodes from file diff --git a/NzbDrone.Core/Providers/PostProcessingProvider.cs b/NzbDrone.Core/Providers/PostProcessingProvider.cs index 15f8c46a2..4490ca3cb 100644 --- a/NzbDrone.Core/Providers/PostProcessingProvider.cs +++ b/NzbDrone.Core/Providers/PostProcessingProvider.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Xml.Linq; using NzbDrone.Core.Helpers; +using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers { diff --git a/NzbDrone.Core/Providers/RenameProvider.cs b/NzbDrone.Core/Providers/RenameProvider.cs index d8e334405..570bf8898 100644 --- a/NzbDrone.Core/Providers/RenameProvider.cs +++ b/NzbDrone.Core/Providers/RenameProvider.cs @@ -7,6 +7,7 @@ using System.Threading; using NLog; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; namespace NzbDrone.Core.Providers diff --git a/NzbDrone.Core/Providers/RssItemProcessingProvider.cs b/NzbDrone.Core/Providers/RssItemProcessingProvider.cs index 8553e85cd..10d794602 100644 --- a/NzbDrone.Core/Providers/RssItemProcessingProvider.cs +++ b/NzbDrone.Core/Providers/RssItemProcessingProvider.cs @@ -6,6 +6,7 @@ using System.Text; using NLog; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; namespace NzbDrone.Core.Providers @@ -23,7 +24,7 @@ namespace NzbDrone.Core.Providers private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RssItemProcessingProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, + public RssItemProcessingProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider, IHistoryProvider historyProvider, IDownloadProvider sabProvider, IConfigProvider configProvider, IHttpProvider httpProvider, IDiskProvider diskProvider) @@ -53,7 +54,7 @@ namespace NzbDrone.Core.Providers var episodeParseResults = Parser.ParseEpisodeInfo(nzb.Title); - if (episodeParseResults.Count() > 0) + if (episodeParseResults.Episodes.Count() > 0) { ProcessStandardItem(nzb, indexer, episodeParseResults); return; @@ -78,7 +79,7 @@ namespace NzbDrone.Core.Providers } } - public string GetTitleFix(List episodes, int seriesId) + public string GetTitleFix(EpisodeParseResult episodes, int seriesId) { var series = _seriesProvider.GetSeries(seriesId); @@ -86,16 +87,16 @@ namespace NzbDrone.Core.Providers string episodeNumbers = String.Empty; string episodeTitles = String.Empty; - foreach (var episode in episodes) + foreach (var episode in episodes.Episodes) { - var episodeInDb = _episodeProvider.GetEpisode(seriesId, episode.SeasonNumber, episode.EpisodeNumber); + var episodeInDb = _episodeProvider.GetEpisode(seriesId, episodes.SeasonNumber, episode); if (episodeInDb == null) { //Todo: Handle this some other way? Logger.Debug("Episode Not found in Database, Fake it..."); //return String.Format("{0} - {1:00}x{2}", series.Title, episode.SeasonNumber, episode.EpisodeNumber); - episodeInDb = new Episode { EpisodeNumber = episode.EpisodeNumber, Title = "TBA" }; + episodeInDb = new Episode { EpisodeNumber = episode, Title = "TBA" }; } seasonNumber = episodeInDb.SeasonNumber; @@ -110,23 +111,23 @@ namespace NzbDrone.Core.Providers #endregion - private void ProcessStandardItem(NzbInfoModel nzb, Indexer indexer, List episodeParseResults) + private void ProcessStandardItem(NzbInfoModel nzb, Indexer indexer, EpisodeParseResult episodeParseResults) { //Will try to match via NormalizeTitle, if that fails it will look for a scene name and do a lookup for your shows - var series = _seriesProvider.FindSeries(episodeParseResults[0].SeriesTitle); + var series = _seriesProvider.FindSeries(episodeParseResults.SeriesTitle); if (series == null) { //If we weren't able to find a title using the clean name, lets try again looking for a scene name - var sceneId = SceneNameHelper.FindByName(episodeParseResults[0].SeriesTitle); + var sceneId = SceneNameHelper.FindByName(episodeParseResults.SeriesTitle); if (sceneId != 0) series = _seriesProvider.GetSeries(sceneId); if (series == null) { - Logger.Debug("Show is not being watched: {0}", episodeParseResults[0].SeriesTitle); + Logger.Debug("Show is not being watched: {0}", episodeParseResults.SeriesTitle); return; } } @@ -137,7 +138,7 @@ namespace NzbDrone.Core.Providers nzb.Quality = Parser.ParseQuality(nzb.Title); //Loop through the list of the episodeParseResults to ensure that all the episodes are needed - foreach (var episode in episodeParseResults) + foreach (var episode in episodeParseResults.Episodes) { //IsEpisodeWanted? var episodeModel = new EpisodeModel(); @@ -145,13 +146,13 @@ namespace NzbDrone.Core.Providers episodeModel.SeriesId = series.SeriesId; episodeModel.SeriesTitle = series.Title; episodeModel.Quality = nzb.Quality; - episodeModel.SeasonNumber = episode.SeasonNumber; - episodeModel.EpisodeNumber = episode.EpisodeNumber; + episodeModel.SeasonNumber = episodeParseResults.SeasonNumber; + episodeModel.EpisodeNumber = episode; if (!_episodeProvider.IsNeeded(episodeModel)) return; - var titleFix = GetTitleFix(new List { episode }, episodeModel.SeriesId); + var titleFix = GetTitleFix(episodeParseResults, episodeModel.SeriesId); titleFix = String.Format("{0} [{1}]", titleFix, nzb.Quality); //Add Quality to the titleFix //If it is a PROPER we want to put PROPER in the titleFix @@ -172,15 +173,15 @@ namespace NzbDrone.Core.Providers if (Convert.ToBoolean(_configProvider.GetValue("UseBlackHole", true, true))) { - if (DownloadNzb(nzb)) - AddToHistory(episodeParseResults, series, nzb, indexer); + //if (DownloadNzb(nzb)) + //AddToHistory(episodeParseResults, nzb, indexer); } - + //Send it to SABnzbd else { //Only need to do this check if it contains more than one episode (because we already checked individually before) - if (episodeParseResults.Count > 1) + if (episodeParseResults.Episodes.Count > 1) { if (_sabProvider.IsInQueue(nzb.TitleFix)) return; @@ -188,15 +189,11 @@ namespace NzbDrone.Core.Providers if (indexer.IndexerName != "Newzbin") { - if (_sabProvider.AddByUrl(nzb.Link.ToString(), nzb.TitleFix)) - AddToHistory(episodeParseResults, series, nzb, indexer); - } - - else - { - if (_sabProvider.AddById(nzb.Id, nzb.TitleFix)) - AddToHistory(episodeParseResults, series, nzb, indexer); + //if (_sabProvider.AddByUrl(nzb.Link.ToString(), nzb.TitleFix)) + //AddToHistory(_episodeProvider.GetEpisode(episodeParseResults.), series, nzb, indexer); } + + } } @@ -285,8 +282,7 @@ namespace NzbDrone.Core.Providers { if (DownloadNzb(nzb)) { - var episodeParseResults = GetEpisodeParseList(season.Episodes); - AddToHistory(episodeParseResults, series, nzb, indexer); + AddToHistory(season.Episodes, nzb, indexer); } } @@ -300,54 +296,26 @@ namespace NzbDrone.Core.Providers { if (_sabProvider.AddByUrl(nzb.Link.ToString(), nzb.TitleFix)) { - var episodeParseResults = GetEpisodeParseList(season.Episodes); - AddToHistory(episodeParseResults, series, nzb, indexer); + AddToHistory(season.Episodes, nzb, indexer); } - - } - else - { - if (_sabProvider.AddById(nzb.Id, nzb.TitleFix)) - { - var episodeParseResults = GetEpisodeParseList(season.Episodes); - AddToHistory(episodeParseResults, series, nzb, indexer); - } } + } } //Possibly grab the whole season if a certain % of the season is missing, rather than for 1 or 2 episodes } - private List GetEpisodeParseList(List episodes) + private void AddToHistory(IEnumerable episodes, NzbInfoModel nzb, Indexer indexer) { - var episodeParseResults = new List(); - episodeParseResults.AddRange( - episodes.Select( - e => - new EpisodeParseResult { EpisodeNumber = e.EpisodeNumber, SeasonNumber = e.SeasonNumber })); + //Set episode status to grabbed + //episode.Status = EpisodeStatusType.Grabbed; - return episodeParseResults; - } + //Add to History - private void AddToHistory(List episodeParseResults, Series series, NzbInfoModel nzb, Indexer indexer) - { - //We need to loop through the episodeParseResults so each episode in the NZB is properly handled - foreach (var epr in episodeParseResults) + foreach (var episode in episodes) { - var episode = _episodeProvider.GetEpisode(series.SeriesId, epr.SeasonNumber, epr.EpisodeNumber); - - if (episode == null) - { - //Not sure how we got this far, so lets throw an exception - throw new ArgumentOutOfRangeException(); - } - - //Set episode status to grabbed - episode.Status = EpisodeStatusType.Grabbed; - - //Add to History var history = new History(); history.Date = DateTime.Now; history.EpisodeId = episode.EpisodeId; @@ -376,7 +344,7 @@ namespace NzbDrone.Core.Providers var filename = path + Path.DirectorySeparatorChar + nzb.TitleFix + ".nzb"; if (_httpProvider.DownloadFile(nzb.Link.ToString(), filename)) - return true; + return true; } Logger.Error("Blackhole Directory doesn't exist, not saving NZB: '{0}'", path); diff --git a/NzbDrone.Core/Providers/RssSyncProvider.cs b/NzbDrone.Core/Providers/RssSyncProvider.cs index d73e73024..43858b834 100644 --- a/NzbDrone.Core/Providers/RssSyncProvider.cs +++ b/NzbDrone.Core/Providers/RssSyncProvider.cs @@ -7,6 +7,7 @@ using NLog; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using Rss; diff --git a/NzbDrone.Core/Providers/SabProvider.cs b/NzbDrone.Core/Providers/SabProvider.cs index 9d49a76f8..d74b731c3 100644 --- a/NzbDrone.Core/Providers/SabProvider.cs +++ b/NzbDrone.Core/Providers/SabProvider.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Web; using System.Xml.Linq; using NLog; +using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers { diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index 2e94a0430..767eabcc1 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; using NLog; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using SubSonic.Repository; diff --git a/NzbDrone.Core/Providers/SyncProvider.cs b/NzbDrone.Core/Providers/SyncProvider.cs index 2a9d44203..fa8bf8a18 100644 --- a/NzbDrone.Core/Providers/SyncProvider.cs +++ b/NzbDrone.Core/Providers/SyncProvider.cs @@ -7,6 +7,7 @@ using System.Threading; using NLog; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers { diff --git a/NzbDrone.Core/Providers/XbmcProvider.cs b/NzbDrone.Core/Providers/XbmcProvider.cs index 9f7bac7f0..688e4933d 100644 --- a/NzbDrone.Core/Providers/XbmcProvider.cs +++ b/NzbDrone.Core/Providers/XbmcProvider.cs @@ -6,6 +6,7 @@ using System.Text; using System.Xml.Linq; using NLog; using NzbDrone.Core.Helpers; +using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers { diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index b82656232..0f4a4a6c1 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Web; using System.Web.Mvc; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Web.Models; namespace NzbDrone.Web.Controllers diff --git a/NzbDrone.Web/Controllers/ApiController.cs b/NzbDrone.Web/Controllers/ApiController.cs index ebacc4d6b..7edaa0a65 100644 --- a/NzbDrone.Web/Controllers/ApiController.cs +++ b/NzbDrone.Web/Controllers/ApiController.cs @@ -7,6 +7,7 @@ using System.Xml.Linq; using NLog; using NzbDrone.Core; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; namespace NzbDrone.Web.Controllers { diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 49f910f84..07dfa4a7b 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -8,6 +8,7 @@ using System.Web; using System.Web.Mvc; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Web.Models; diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 7e9a95add..4e6a9856e 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -9,6 +9,7 @@ using NzbDrone.Core; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Web.Models; diff --git a/NzbDrone.sln b/NzbDrone.sln index 038273ff3..c15d4b924 100644 --- a/NzbDrone.sln +++ b/NzbDrone.sln @@ -27,7 +27,6 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Any CPU.ActiveCfg = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Mixed Platforms.Build.0 = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x64.ActiveCfg = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x86.ActiveCfg = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x86.Build.0 = Debug|x86 @@ -56,7 +55,6 @@ Global {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Any CPU.Build.0 = Debug|Any CPU {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x64.ActiveCfg = Debug|Any CPU {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x86.ActiveCfg = Debug|Any CPU {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x86.Build.0 = Debug|Any CPU @@ -69,7 +67,6 @@ Global {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x64.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x86.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x86.Build.0 = Debug|Any CPU @@ -81,7 +78,6 @@ Global {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Release|x86.ActiveCfg = Release|Any CPU {0C679573-736D-4F77-B934-FD8931AC1AA1}.Debug|Any CPU.ActiveCfg = Debug|x86 {0C679573-736D-4F77-B934-FD8931AC1AA1}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {0C679573-736D-4F77-B934-FD8931AC1AA1}.Debug|Mixed Platforms.Build.0 = Debug|x86 {0C679573-736D-4F77-B934-FD8931AC1AA1}.Debug|x64.ActiveCfg = Debug|x86 {0C679573-736D-4F77-B934-FD8931AC1AA1}.Debug|x86.ActiveCfg = Debug|x86 {0C679573-736D-4F77-B934-FD8931AC1AA1}.Debug|x86.Build.0 = Debug|x86