From 401ed9a8f619d466c741446f16c89d8293b05651 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 7 Apr 2013 15:40:13 -0700 Subject: [PATCH] more project cleanup. --- .../IndexerTests/BasicRssParserFixture.cs | 37 +++++++++ NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + .../ParserTests/ParserFixture.cs | 20 +---- .../ParserTests/QualityParserFixture.cs | 13 +-- NzbDrone.Core/Configuration/ConfigService.cs | 1 + NzbDrone.Core/Configuration/IConfigService.cs | 1 + .../Clients}/ConnectionInfoModel.cs | 2 +- .../{Model => Download}/DownloadClientType.cs | 2 +- NzbDrone.Core/Indexers/BasicRssParser.cs | 59 ++++++++++++- NzbDrone.Core/Indexers/Newznab/Newznab.cs | 26 ++---- .../Indexers/NzbClub/NzbClubParser.cs | 4 +- .../Indexers/NzbIndex/NzbIndexParser.cs | 8 +- .../Indexers/NzbsRUs/NzbsrusParser.cs | 2 +- NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs | 1 - .../Nzbx/NzbxRecentItem.cs | 6 +- .../Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs | 2 +- .../Indexers/SyndicationFeedXmlReader.cs | 2 +- .../JsonConverter/EpochDateTimeConverter.cs | 47 ----------- NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs | 56 ------------- NzbDrone.Core/Model/Nzbx/NzbxVotesModel.cs | 13 --- NzbDrone.Core/Model/SeasonParseResult.cs | 18 ---- NzbDrone.Core/Model/StatsModel.cs | 35 -------- NzbDrone.Core/NzbDrone.Core.csproj | 11 +-- NzbDrone.Core/Parser.cs | 82 ++++--------------- NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs | 8 +- .../Unity/AutoMockingBuilderStrategy.cs | 2 +- .../Unity/AutoMockingContainerExtension.cs | 2 +- .../ServiceInstall/ServiceHelper.cs | 4 +- .../ServiceUninstall/ServiceHelper.cs | 4 +- 29 files changed, 154 insertions(+), 315 deletions(-) create mode 100644 NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs rename NzbDrone.Core/{Model => Download/Clients}/ConnectionInfoModel.cs (76%) rename NzbDrone.Core/{Model => Download}/DownloadClientType.cs (79%) rename NzbDrone.Core/{Model => Indexers}/Nzbx/NzbxRecentItem.cs (89%) delete mode 100644 NzbDrone.Core/Model/Nzbx/JsonConverter/EpochDateTimeConverter.cs delete mode 100644 NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs delete mode 100644 NzbDrone.Core/Model/Nzbx/NzbxVotesModel.cs delete mode 100644 NzbDrone.Core/Model/SeasonParseResult.cs delete mode 100644 NzbDrone.Core/Model/StatsModel.cs diff --git a/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs b/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs new file mode 100644 index 000000000..0fbdab47e --- /dev/null +++ b/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs @@ -0,0 +1,37 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.IndexerTests +{ + public class BasicRssParserFixture : CoreTest + { + + [TestCase("Castle.2009.S01E14.English.HDTV.XviD-LOL", "LOL")] + [TestCase("Castle 2009 S01E14 English HDTV XviD LOL", "LOL")] + [TestCase("Acropolis Now S05 EXTRAS DVDRip XviD RUNNER", "RUNNER")] + [TestCase("Punky.Brewster.S01.EXTRAS.DVDRip.XviD-RUNNER", "RUNNER")] + [TestCase("2020.NZ.2011.12.02.PDTV.XviD-C4TV", "C4TV")] + [TestCase("The.Office.S03E115.DVDRip.XviD-OSiTV", "OSiTV")] + public void parse_releaseGroup(string title, string expected) + { + BasicRssParser.ParseReleaseGroup(title).Should().Be(expected); + } + + + [TestCase("5.64 GB", 6055903887)] + [TestCase("5.54 GiB", 5948529705)] + [TestCase("398.62 MiB", 417983365)] + [TestCase("7,162.1MB", 7510006170)] + [TestCase("162.1MB", 169974170)] + [TestCase("398.62 MB", 417983365)] + public void parse_size(string sizeString, long expectedSize) + { + var result = BasicRssParser.GetReportSize(sizeString); + + result.Should().Be(expectedSize); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 139dd1129..71d72793a 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -134,6 +134,7 @@ + diff --git a/NzbDrone.Core.Test/ParserTests/ParserFixture.cs b/NzbDrone.Core.Test/ParserTests/ParserFixture.cs index 4d49733bd..448f8c0bf 100644 --- a/NzbDrone.Core.Test/ParserTests/ParserFixture.cs +++ b/NzbDrone.Core.Test/ParserTests/ParserFixture.cs @@ -4,6 +4,7 @@ using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Contract; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Model; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; @@ -325,8 +326,8 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase("Burn.Notice.S04E15.Brotherly.Love.GERMAN.DUBBED.WS.WEBRiP.XviD.REPACK-TVP", LanguageType.German)] public void parse_language(string postTitle, LanguageType language) { - var result = Parser.ParseLanguage(postTitle); - result.Should().Be(language); + var result = Parser.ParseTitle(postTitle); + result.Language.Should().Be(language); } [TestCase("Hawaii Five 0 S01 720p WEB DL DD5 1 H 264 NT", "Hawaii Five", 1)] @@ -346,19 +347,6 @@ namespace NzbDrone.Core.Test.ParserTests result.OriginalString.Should().Be(postTitle); } - [TestCase("5.64 GB", 6055903887)] - [TestCase("5.54 GiB", 5948529705)] - [TestCase("398.62 MiB", 417983365)] - [TestCase("7,162.1MB", 7510006170)] - [TestCase("162.1MB", 169974170)] - [TestCase("398.62 MB", 417983365)] - public void parse_size(string sizeString, long expectedSize) - { - var result = Parser.GetReportSize(sizeString); - - result.Should().Be(expectedSize); - } - [TestCase("Acropolis Now S05 EXTRAS DVDRip XviD RUNNER")] [TestCase("Punky Brewster S01 EXTRAS DVDRip XviD RUNNER")] [TestCase("Instant Star S03 EXTRAS DVDRip XviD OSiTV")] @@ -392,7 +380,7 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase("[ 21154 ] - [ TrollHD ] - [ 00/73 ] - \"MythBusters S03E20 Escape Slide Parachute 1080i HDTV-UPSCALE DD5.1 MPEG2-TrollHD.nzb\" yEnc", "MythBusters S03E20 Escape Slide Parachute 1080i HDTV-UPSCALE DD5.1 MPEG2-TrollHD.nzb")] public void parse_header(string title, string expected) { - Parser.ParseHeader(title).Should().Be(expected); + BasicRssParser.ParseHeader(title).Should().Be(expected); } [TestCase("password - \"bdc435cb-93c4-4902-97ea-ca00568c3887.337\" yEnc")] diff --git a/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs b/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs index 188684785..ae2914fb4 100644 --- a/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs +++ b/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs @@ -4,13 +4,14 @@ using System; using System.Linq; using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.Model; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.ParserTests { [TestFixture] - + public class QualityParserFixture : CoreTest { public static object[] QualityParserCases = @@ -96,17 +97,17 @@ namespace NzbDrone.Core.Test.ParserTests [Test, TestCaseSource("QualityParserCases")] public void quality_parse(string postTitle, Quality quality, bool proper) { - var result = Parser.ParseQuality(postTitle); - result.Quality.Should().Be(quality); - result.Proper.Should().Be(proper); + var result = Parser.ParseTitle(postTitle); + result.Quality.Quality.Should().Be(quality); + result.Quality.Proper.Should().Be(proper); } [Test, TestCaseSource("SelfQualityParserCases")] public void parsing_our_own_quality_enum(Quality quality) { var fileName = String.Format("My series S01E01 [{0}]", quality); - var result = Parser.ParseQuality(fileName); - result.Quality.Should().Be(quality); + var result = Parser.ParseTitle(fileName); + result.Quality.Quality.Should().Be(quality); } } } diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index cf9c33587..31f32234e 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Core.Download; using NzbDrone.Core.Model; using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Sabnzbd; diff --git a/NzbDrone.Core/Configuration/IConfigService.cs b/NzbDrone.Core/Configuration/IConfigService.cs index 6e7e18b74..c430297e1 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using NzbDrone.Core.Download; using NzbDrone.Core.Model; using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Sabnzbd; diff --git a/NzbDrone.Core/Model/ConnectionInfoModel.cs b/NzbDrone.Core/Download/Clients/ConnectionInfoModel.cs similarity index 76% rename from NzbDrone.Core/Model/ConnectionInfoModel.cs rename to NzbDrone.Core/Download/Clients/ConnectionInfoModel.cs index f73ae174b..5ee05103e 100644 --- a/NzbDrone.Core/Model/ConnectionInfoModel.cs +++ b/NzbDrone.Core/Download/Clients/ConnectionInfoModel.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Core.Model +namespace NzbDrone.Core.Download.Clients { public class ConnectionInfoModel { diff --git a/NzbDrone.Core/Model/DownloadClientType.cs b/NzbDrone.Core/Download/DownloadClientType.cs similarity index 79% rename from NzbDrone.Core/Model/DownloadClientType.cs rename to NzbDrone.Core/Download/DownloadClientType.cs index 31fb01c0d..a1d67fe23 100644 --- a/NzbDrone.Core/Model/DownloadClientType.cs +++ b/NzbDrone.Core/Download/DownloadClientType.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Core.Model +namespace NzbDrone.Core.Download { public enum DownloadClientType { diff --git a/NzbDrone.Core/Indexers/BasicRssParser.cs b/NzbDrone.Core/Indexers/BasicRssParser.cs index 58547addc..c7c59524e 100644 --- a/NzbDrone.Core/Indexers/BasicRssParser.cs +++ b/NzbDrone.Core/Indexers/BasicRssParser.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.ServiceModel.Syndication; +using System.Text.RegularExpressions; using NLog; using NzbDrone.Core.Model; @@ -63,7 +65,7 @@ namespace NzbDrone.Core.Indexers protected virtual string GetNzbInfoUrl(SyndicationItem item) { - return string.Empty; + return String.Empty; } protected virtual IndexerParseResult PostProcessor(SyndicationItem item, IndexerParseResult currentResult) @@ -89,7 +91,7 @@ namespace NzbDrone.Core.Indexers return PostProcessor(item, episodeParseResult); } - private static string ParseReleaseGroup(string title) + public static string ParseReleaseGroup(string title) { title = title.Trim(); var index = title.LastIndexOf('-'); @@ -102,10 +104,59 @@ namespace NzbDrone.Core.Indexers var group = title.Substring(index + 1); - if (group.Length == title.Length) + if (@group.Length == title.Length) return String.Empty; - return group; + return @group; + } + + private static readonly Regex[] HeaderRegex = new[] + { + new Regex(@"(?:\[.+\]\-\[.+\]\-\[.+\]\-\[)(?.+)(?:\]\-.+)", + RegexOptions.IgnoreCase | RegexOptions.Compiled), + + new Regex(@"(?:\[.+\]\W+\[.+\]\W+\[.+\]\W+\"")(?.+)(?:\"".+)", + RegexOptions.IgnoreCase | RegexOptions.Compiled), + + new Regex(@"(?:\[)(?.+)(?:\]\-.+)", + RegexOptions.IgnoreCase | RegexOptions.Compiled), + }; + + public static string ParseHeader(string header) + { + foreach (var regex in HeaderRegex) + { + var match = regex.Matches(header); + + if (match.Count != 0) + return match[0].Groups["nzbTitle"].Value.Trim(); + } + + return header; + } + + private static readonly Regex ReportSizeRegex = new Regex(@"(?\d+\.\d{1,2}|\d+\,\d+\.\d{1,2})\W?(?GB|MB|GiB|MiB)", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + + public static long GetReportSize(string sizeString) + { + var match = ReportSizeRegex.Matches(sizeString); + + if (match.Count != 0) + { + var cultureInfo = new CultureInfo("en-US"); + var value = Decimal.Parse(Regex.Replace(match[0].Groups["value"].Value, "\\,", ""), cultureInfo); + + var unit = match[0].Groups["unit"].Value; + + if (unit.Equals("MB", StringComparison.InvariantCultureIgnoreCase) || unit.Equals("MiB", StringComparison.InvariantCultureIgnoreCase)) + return Convert.ToInt64(value * 1048576L); + + if (unit.Equals("GB", StringComparison.InvariantCultureIgnoreCase) || unit.Equals("GiB", StringComparison.InvariantCultureIgnoreCase)) + return Convert.ToInt64(value * 1073741824L); + } + return 0; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 23e43ea40..77a776197 100644 --- a/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace NzbDrone.Core.Indexers.Newznab { @@ -20,39 +21,22 @@ namespace NzbDrone.Core.Indexers.Newznab public override IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { - foreach (var url in RecentFeed) - { - yield return String.Format("{0}&limit=100&q={1}&season={2}&ep={3}", url, NewsnabifyTitle(seriesTitle), seasonNumber, episodeNumber); - } + return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}&season={2}&ep={3}", url, NewsnabifyTitle(seriesTitle), seasonNumber, episodeNumber)); } public override IEnumerable GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date) { - var searchUrls = new List(); - - foreach (var url in RecentFeed) - { - searchUrls.Add(String.Format("{0}&limit=100&q={1}&season={2:yyyy}&ep={2:MM/dd}", url, NewsnabifyTitle(seriesTitle), date)); - } - - return searchUrls; + return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}&season={2:yyyy}&ep={2:MM/dd}", url, NewsnabifyTitle(seriesTitle), date)).ToList(); } public override IEnumerable GetSeasonSearchUrls(string seriesTitle, int seasonNumber) { - foreach (var url in RecentFeed) - { - yield return String.Format("{0}&limit=100&q={1}&season={2}", url, NewsnabifyTitle(seriesTitle), seasonNumber); - } + return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}&season={2}", url, NewsnabifyTitle(seriesTitle), seasonNumber)); } public override IEnumerable GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard) { - foreach (var url in RecentFeed) - { - yield return - String.Format("{0}&limit=100&q={1}+S{2:00}E{3}", url, NewsnabifyTitle(seriesTitle), seasonNumber, episodeWildcard); - } + return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}+S{2:00}E{3}", url, NewsnabifyTitle(seriesTitle), seasonNumber, episodeWildcard)); } public override string Name diff --git a/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs b/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs index 2ef956064..ab3970caf 100644 --- a/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs +++ b/NzbDrone.Core/Indexers/NzbClub/NzbClubParser.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Indexers.NzbClub if (currentResult != null) { var sizeString = Regex.Match(item.Summary.Text, @"Size:\s\d+\.\d{1,2}\s\w{2}\s", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value; - currentResult.Size = Parser.GetReportSize(sizeString); + currentResult.Size = GetReportSize(sizeString); } return currentResult; @@ -20,7 +20,7 @@ namespace NzbDrone.Core.Indexers.NzbClub protected override string GetTitle(SyndicationItem syndicationItem) { - var title = Parser.ParseHeader(syndicationItem.Title.Text); + var title = ParseHeader(syndicationItem.Title.Text); if (String.IsNullOrWhiteSpace(title)) return syndicationItem.Title.Text; diff --git a/NzbDrone.Core/Indexers/NzbIndex/NzbIndexParser.cs b/NzbDrone.Core/Indexers/NzbIndex/NzbIndexParser.cs index 3af292b1e..8dc386e51 100644 --- a/NzbDrone.Core/Indexers/NzbIndex/NzbIndexParser.cs +++ b/NzbDrone.Core/Indexers/NzbIndex/NzbIndexParser.cs @@ -23,18 +23,18 @@ namespace NzbDrone.Core.Indexers.NzbIndex if (currentResult != null) { var sizeString = Regex.Match(item.Summary.Text, @"\d+\.\d{1,2}\s\w{2}", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value; - currentResult.Size = Parser.GetReportSize(sizeString); + currentResult.Size = GetReportSize(sizeString); } return currentResult; } - protected override string GetTitle(SyndicationItem item) + protected override string GetTitle(SyndicationItem syndicationItem) { - var title = Parser.ParseHeader(item.Title.Text); + var title = ParseHeader(syndicationItem.Title.Text); if (String.IsNullOrWhiteSpace(title)) - return item.Title.Text; + return syndicationItem.Title.Text; return title; } diff --git a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs b/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs index 87d935e55..4ad848966 100644 --- a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs +++ b/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Indexers.NzbsRUs if (currentResult != null) { var sizeString = Regex.Match(item.Summary.Text, @"\d+\.\d{1,2} \w{3}", RegexOptions.IgnoreCase).Value; - currentResult.Size = Parser.GetReportSize(sizeString); + currentResult.Size = GetReportSize(sizeString); } return currentResult; diff --git a/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs b/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs index 2584b967d..f5a30ef80 100644 --- a/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs +++ b/NzbDrone.Core/Indexers/Nzbx/NzbxParser.cs @@ -4,7 +4,6 @@ using System.IO; using NLog; using Newtonsoft.Json; using NzbDrone.Core.Model; -using NzbDrone.Core.Model.Nzbx; namespace NzbDrone.Core.Indexers.Nzbx { diff --git a/NzbDrone.Core/Model/Nzbx/NzbxRecentItem.cs b/NzbDrone.Core/Indexers/Nzbx/NzbxRecentItem.cs similarity index 89% rename from NzbDrone.Core/Model/Nzbx/NzbxRecentItem.cs rename to NzbDrone.Core/Indexers/Nzbx/NzbxRecentItem.cs index d07dcf97d..eeb291299 100644 --- a/NzbDrone.Core/Model/Nzbx/NzbxRecentItem.cs +++ b/NzbDrone.Core/Indexers/Nzbx/NzbxRecentItem.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -namespace NzbDrone.Core.Model.Nzbx +namespace NzbDrone.Core.Indexers.Nzbx { public class NzbxRecentItem { @@ -42,6 +39,5 @@ namespace NzbDrone.Core.Model.Nzbx public int RageId { get; set; } public int Comments { get; set; } public int Downloads { get; set; } - public NzbxVotesModel Votes { get; set; } } } diff --git a/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs b/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs index 16deb8ca9..284d56a57 100644 --- a/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs +++ b/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs if (currentResult != null) { var sizeString = Regex.Match(item.Summary.Text, @"Size:\<\/b\>\s\d+\.\d{1,2}\s\w{2}\
", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value; - currentResult.Size = Parser.GetReportSize(sizeString); + currentResult.Size = GetReportSize(sizeString); } return currentResult; diff --git a/NzbDrone.Core/Indexers/SyndicationFeedXmlReader.cs b/NzbDrone.Core/Indexers/SyndicationFeedXmlReader.cs index addbe4959..a72c5242d 100644 --- a/NzbDrone.Core/Indexers/SyndicationFeedXmlReader.cs +++ b/NzbDrone.Core/Indexers/SyndicationFeedXmlReader.cs @@ -72,7 +72,7 @@ namespace NzbDrone.Core.Indexers return dateVal; } - internal void CheckForError() + public void CheckForError() { if (this.MoveToContent() == XmlNodeType.Element) { diff --git a/NzbDrone.Core/Model/Nzbx/JsonConverter/EpochDateTimeConverter.cs b/NzbDrone.Core/Model/Nzbx/JsonConverter/EpochDateTimeConverter.cs deleted file mode 100644 index a79540a24..000000000 --- a/NzbDrone.Core/Model/Nzbx/JsonConverter/EpochDateTimeConverter.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace NzbDrone.Core.Model.Nzbx.JsonConverter -{ - public class EpochDateTimeConverter : DateTimeConverterBase - { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - long ticks; - if (value is DateTime) - { - var epoch = new DateTime(1970, 1, 1); - var delta = ((DateTime)value) - epoch; - if (delta.TotalSeconds < 0) - { - throw new ArgumentOutOfRangeException("value", - "Unix epoc starts January 1st, 1970"); - } - ticks = (long)delta.TotalSeconds; - } - else - { - throw new Exception("Expected date object value."); - } - writer.WriteValue(ticks); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.Integer) - { - throw new Exception( - String.Format("Unexpected token parsing date. Expected Integer, got {0}.", - reader.TokenType)); - } - - var ticks = (long)reader.Value; - - var date = new DateTime(1970, 1, 1); - date = date.AddSeconds(ticks); - - return date; - } - } -} diff --git a/NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs b/NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs deleted file mode 100644 index 522a10a56..000000000 --- a/NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json; -using NzbDrone.Core.Model.Nzbx.JsonConverter; - -namespace NzbDrone.Core.Model.Nzbx -{ - public class NzbxSearchItem - { - //"name": "30.Rock.S06E06E07.HDTV.XviD-LOL", - //"fromname": "teevee@4u.tv (teevee)", - //"size": 418067671, - //"groupid": 4, - //"categoryid": 5030, - //"totalpart": 36, - //"completion": 100, - //"rageid": "-1", - //"imdbid": "", - //"comments": "0", - //"guid": "97be14dbf1776eec4fb8f2bb835935c0", - //"adddate": 1355343562, - //"postdate": 1328839361, - //"downloads": "0", - //"votes": { - - // "upvotes": 0, - // "downvotes": 0 - - //}, - //"nzb": "https://nzbx.co/nzb?97be14dbf1776eec4fb8f2bb835935c0*|*30.Rock.S06E06E07.HDTV.XviD-LOL - - public string Name { get; set; } - public int TotalPart { get; set; } - public int GroupId { get; set; } - public long Size { get; set; } - - [JsonConverter(typeof(EpochDateTimeConverter))] - public DateTime AddDate { get; set; } - - [JsonConverter(typeof(EpochDateTimeConverter))] - public DateTime PostDate { get; set; } - - public string Guid { get; set; } - public string FromName { get; set; } - public int Completion { get; set; } - public int CategoryId { get; set; } - public string ImdbId { get; set; } - public int RageId { get; set; } - public int Comments { get; set; } - public int Downloads { get; set; } - public NzbxVotesModel Votes { get; set; } - public string Nzb { get; set; } - } -} diff --git a/NzbDrone.Core/Model/Nzbx/NzbxVotesModel.cs b/NzbDrone.Core/Model/Nzbx/NzbxVotesModel.cs deleted file mode 100644 index 9563a5213..000000000 --- a/NzbDrone.Core/Model/Nzbx/NzbxVotesModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NzbDrone.Core.Model.Nzbx -{ - public class NzbxVotesModel - { - public int Up { get; set; } - public int Down { get; set; } - } -} diff --git a/NzbDrone.Core/Model/SeasonParseResult.cs b/NzbDrone.Core/Model/SeasonParseResult.cs deleted file mode 100644 index 464a27abf..000000000 --- a/NzbDrone.Core/Model/SeasonParseResult.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Model -{ - public class SeasonParseResult - { - internal string SeriesTitle { get; set; } - internal int SeasonNumber { get; set; } - internal int Year { get; set; } - - public QualityModel Quality { get; set; } - - public override string ToString() - { - return string.Format("Series:{0} Season:{1}", SeriesTitle, SeasonNumber); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Model/StatsModel.cs b/NzbDrone.Core/Model/StatsModel.cs deleted file mode 100644 index a5d5fca9f..000000000 --- a/NzbDrone.Core/Model/StatsModel.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; - -namespace NzbDrone.Core.Model -{ - public class StatsModel - { - [DisplayName("Number of Series")] - public int SeriesTotal { get; set; } - - [DisplayName("Number of Series Countinuing")] - public int SeriesContinuing { get; set; } - - [DisplayName("Number of Series Ended")] - public int SeriesEnded { get; set; } - - [DisplayName("Number of Episodes")] - public int EpisodesTotal { get; set; } - - [DisplayName("Number of Episodes On Disk")] - public int EpisodesOnDisk { get; set; } - - [DisplayName("Number of Episodes Missing")] - public int EpisodesMissing { get; set; } - - [DisplayName("Downloaded in the Last Week")] - public int DownloadLastWeek { get; set; } - - [DisplayName("Downloaded in the Last 30 days")] - public int DownloadedLastMonth { get; set; } - } -} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 351d49dee..cfa9cdb65 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -230,16 +230,17 @@ + + - @@ -321,11 +322,9 @@ - - @@ -336,9 +335,7 @@ - - - + @@ -363,7 +360,6 @@ - @@ -512,7 +508,6 @@ - diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index be3015dfa..71f948c49 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -53,7 +53,7 @@ namespace NzbDrone.Core new Regex(@"^(?.+?)?(?:\W?(?<season>(?<!\d+)\d{1})(?<episode>\d{2}(?!p|i|\d+)))+\W?(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), - //Mini-Series, treated as season 1, episodes are labeled as Part01, Part 01, Part.1 + //Mini-Series, treated as season 1, episodes are labelled as Part01, Part 01, Part.1 new Regex(@"^(?<title>.+?)(?:\W+(?:(?:Part\W?|(?<!\d+\W+)e)(?<episode>\d{1,2}(?!\d+)))+)\W?(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), @@ -72,26 +72,13 @@ namespace NzbDrone.Core private static readonly Regex SimpleTitleRegex = new Regex(@"480[i|p]|720[i|p]|1080[i|p]|[x|h|x\s|h\s]264|DD\W?5\W1|\<|\>|\?|\*|\:|\||""", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex ReportSizeRegex = new Regex(@"(?<value>\d+\.\d{1,2}|\d+\,\d+\.\d{1,2})\W?(?<unit>GB|MB|GiB|MiB)", - RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex[] HeaderRegex = new[] - { - new Regex(@"(?:\[.+\]\-\[.+\]\-\[.+\]\-\[)(?<nzbTitle>.+)(?:\]\-.+)", - RegexOptions.IgnoreCase | RegexOptions.Compiled), - - new Regex(@"(?:\[.+\]\W+\[.+\]\W+\[.+\]\W+\"")(?<nzbTitle>.+)(?:\"".+)", - RegexOptions.IgnoreCase | RegexOptions.Compiled), - - new Regex(@"(?:\[)(?<nzbTitle>.+)(?:\]\-.+)", - RegexOptions.IgnoreCase | RegexOptions.Compiled), - }; private static readonly Regex MultiPartCleanupRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled); private static readonly Regex LanguageRegex = new Regex(@"(?:\W|_)(?<italian>ita|italian)|(?<german>german\b)|(?<flemish>flemish)|(?<greek>greek)(?:\W|_)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - internal static FileNameParseResult ParsePath(string path) + public static FileNameParseResult ParsePath(string path) { var fileInfo = new FileInfo(path); @@ -115,7 +102,7 @@ namespace NzbDrone.Core return result; } - internal static T ParseTitle<T>(string title) where T : ParseResult, new() + public static T ParseTitle<T>(string title) where T : ParseResult, new() { try { @@ -158,12 +145,12 @@ namespace NzbDrone.Core { var seriesName = matchCollection[0].Groups["title"].Value.Replace('.', ' '); - int airyear; - Int32.TryParse(matchCollection[0].Groups["airyear"].Value, out airyear); + int airYear; + Int32.TryParse(matchCollection[0].Groups["airyear"].Value, out airYear); - T parsedIndexer; + T result; - if (airyear < 1900) + if (airYear < 1900) { var seasons = new List<int>(); @@ -182,7 +169,7 @@ namespace NzbDrone.Core if (seasons.Distinct().Count() > 1) return null; - parsedIndexer = new T + result = new T { SeasonNumber = seasons.First(), EpisodeNumbers = new List<int>() @@ -197,7 +184,7 @@ namespace NzbDrone.Core { var first = Convert.ToInt32(episodeCaptures.First().Value); var last = Convert.ToInt32(episodeCaptures.Last().Value); - parsedIndexer.EpisodeNumbers = Enumerable.Range(first, last - first + 1).ToList(); + result.EpisodeNumbers = Enumerable.Range(first, last - first + 1).ToList(); } else { @@ -206,7 +193,7 @@ namespace NzbDrone.Core if (!String.IsNullOrWhiteSpace(matchCollection[0].Groups["extras"].Value)) return null; - parsedIndexer.FullSeason = true; + result.FullSeason = true; } } } @@ -225,17 +212,17 @@ namespace NzbDrone.Core airmonth = tempDay; } - parsedIndexer = new T + result = new T { - AirDate = new DateTime(airyear, airmonth, airday).Date, + AirDate = new DateTime(airYear, airmonth, airday).Date, }; } - parsedIndexer.SeriesTitle = seriesName; + result.SeriesTitle = seriesName; - Logger.Trace("Episode Parsed. {0}", parsedIndexer); + Logger.Trace("Episode Parsed. {0}", result); - return parsedIndexer; + return result; } public static string ParseSeriesName(string title) @@ -250,7 +237,7 @@ namespace NzbDrone.Core return parseResult.CleanTitle; } - internal static QualityModel ParseQuality(string name) + private static QualityModel ParseQuality(string name) { Logger.Trace("Trying to parse quality for {0}", name); @@ -399,7 +386,7 @@ namespace NzbDrone.Core return result; } - internal static LanguageType ParseLanguage(string title) + private static LanguageType ParseLanguage(string title) { var lowerTitle = title.ToLower(); @@ -484,40 +471,7 @@ namespace NzbDrone.Core return NormalizeRegex.Replace(title, String.Empty).ToLower(); } - public static long GetReportSize(string sizeString) - { - var match = ReportSizeRegex.Matches(sizeString); - - if (match.Count != 0) - { - var cultureInfo = new CultureInfo("en-US"); - var value = Decimal.Parse(Regex.Replace(match[0].Groups["value"].Value, "\\,", ""), cultureInfo); - - var unit = match[0].Groups["unit"].Value; - - if (unit.Equals("MB", StringComparison.InvariantCultureIgnoreCase) || unit.Equals("MiB", StringComparison.InvariantCultureIgnoreCase)) - return Convert.ToInt64(value * 1048576L); - - if (unit.Equals("GB", StringComparison.InvariantCultureIgnoreCase) || unit.Equals("GiB", StringComparison.InvariantCultureIgnoreCase)) - return Convert.ToInt64(value * 1073741824L); - } - return 0; - } - - internal static string ParseHeader(string header) - { - foreach (var regex in HeaderRegex) - { - var match = regex.Matches(header); - - if (match.Count != 0) - return match[0].Groups["nzbTitle"].Value.Trim(); - } - - return header; - } - - internal static string CleanupEpisodeTitle(string title) + public static string CleanupEpisodeTitle(string title) { //this will remove (1),(2) from the end of multi part episodes. return MultiPartCleanupRegex.Replace(title, string.Empty).Trim(); diff --git a/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs b/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs index 59411b743..35f24ff92 100644 --- a/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs +++ b/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs @@ -18,8 +18,8 @@ namespace NzbDrone.Test.Common.AutoMoq [DebuggerStepThrough] public class AutoMoqer { - internal readonly MockBehavior DefaultBehavior = MockBehavior.Default; - internal Type ResolveType; + public readonly MockBehavior DefaultBehavior = MockBehavior.Default; + public Type ResolveType; private IUnityContainer container; private IDictionary<Type, object> registeredMocks; @@ -35,7 +35,7 @@ namespace NzbDrone.Test.Common.AutoMoq } - internal AutoMoqer(IUnityContainer container) + public AutoMoqer(IUnityContainer container) { SetupAutoMoqer(container); } @@ -73,7 +73,7 @@ namespace NzbDrone.Test.Common.AutoMoq return mock; } - internal virtual void SetMock(Type type, Mock mock) + public virtual void SetMock(Type type, Mock mock) { if (registeredMocks.ContainsKey(type) == false) registeredMocks.Add(type, mock); diff --git a/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs b/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs index d0a1186ea..b586a3416 100644 --- a/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs +++ b/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs @@ -10,7 +10,7 @@ using Moq; namespace NzbDrone.Test.Common.AutoMoq.Unity { - internal class AutoMockingBuilderStrategy : BuilderStrategy + public class AutoMockingBuilderStrategy : BuilderStrategy { private readonly IUnityContainer _container; private readonly MockRepository _mockFactory; diff --git a/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs b/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs index 0e468c6a6..9606c9a99 100644 --- a/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs +++ b/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs @@ -8,7 +8,7 @@ using Microsoft.Practices.Unity.ObjectBuilder; namespace NzbDrone.Test.Common.AutoMoq.Unity { - internal class AutoMockingContainerExtension : UnityContainerExtension + public class AutoMockingContainerExtension : UnityContainerExtension { private readonly IList<Type> registeredTypes = new List<Type>(); diff --git a/ServiceHelpers/ServiceInstall/ServiceHelper.cs b/ServiceHelpers/ServiceInstall/ServiceHelper.cs index c066a4b18..f43207427 100644 --- a/ServiceHelpers/ServiceInstall/ServiceHelper.cs +++ b/ServiceHelpers/ServiceInstall/ServiceHelper.cs @@ -7,7 +7,7 @@ using System.Security.Principal; namespace ServiceInstall { - internal static class ServiceHelper + public static class ServiceHelper { private static string NzbDroneExe { @@ -23,7 +23,7 @@ namespace ServiceInstall return principal.IsInRole(WindowsBuiltInRole.Administrator); } - internal static void Run(string arg) + public static void Run(string arg) { if (!File.Exists(NzbDroneExe)) { diff --git a/ServiceHelpers/ServiceUninstall/ServiceHelper.cs b/ServiceHelpers/ServiceUninstall/ServiceHelper.cs index f20f08c75..f8992f497 100644 --- a/ServiceHelpers/ServiceUninstall/ServiceHelper.cs +++ b/ServiceHelpers/ServiceUninstall/ServiceHelper.cs @@ -7,7 +7,7 @@ using System.Security.Principal; namespace ServiceUninstall { - internal static class ServiceHelper + public static class ServiceHelper { private static string NzbDroneExe { @@ -23,7 +23,7 @@ namespace ServiceUninstall return principal.IsInRole(WindowsBuiltInRole.Administrator); } - internal static void Run(string arg) + public static void Run(string arg) { if (!File.Exists(NzbDroneExe)) {