From f21a235c001c331dfc85b012b62c4712bd4144ff Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 29 May 2013 20:26:47 -0700 Subject: [PATCH] Fixed trakt searching, cleaned up indexer/notification modules --- NzbDrone.Api/Indexers/IndexerModule.cs | 10 +++++----- NzbDrone.Api/Notifications/NotificationModule.cs | 15 +++++++-------- NzbDrone.Common/StringExtensions.cs | 14 +++++++++++++- .../MetadataSourceTests/TracktProxyFixture.cs | 12 +++++++----- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 4 ++-- NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs | 3 --- NzbDrone.Core/MetadataSource/TraktProxy.cs | 2 +- 7 files changed, 35 insertions(+), 25 deletions(-) diff --git a/NzbDrone.Api/Indexers/IndexerModule.cs b/NzbDrone.Api/Indexers/IndexerModule.cs index a85a1e7fc..e08f74e74 100644 --- a/NzbDrone.Api/Indexers/IndexerModule.cs +++ b/NzbDrone.Api/Indexers/IndexerModule.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Api.ClientSchema; +using NzbDrone.Api.Mapping; using NzbDrone.Api.REST; using NzbDrone.Core.Indexers; using Omu.ValueInjecter; @@ -46,7 +47,7 @@ namespace NzbDrone.Api.Indexers if (indexer == null) { - throw new BadRequestException("Invalid Notification Implementation"); + throw new BadRequestException("Invalid Indexer Implementation"); } indexer.Name = indexerResource.Name; @@ -55,11 +56,10 @@ namespace NzbDrone.Api.Indexers indexer = _indexerService.Create(indexer); - var responseResource = new IndexerResource(); - responseResource.InjectFrom(indexer); - responseResource.Fields = SchemaBuilder.GenerateSchema(indexer.Settings); + var response = indexer.InjectTo(); + response.Fields = SchemaBuilder.GenerateSchema(indexer.Settings); - return responseResource; + return response; } } } \ No newline at end of file diff --git a/NzbDrone.Api/Notifications/NotificationModule.cs b/NzbDrone.Api/Notifications/NotificationModule.cs index 8e47057da..fb667a38a 100644 --- a/NzbDrone.Api/Notifications/NotificationModule.cs +++ b/NzbDrone.Api/Notifications/NotificationModule.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Api.ClientSchema; +using NzbDrone.Api.Mapping; using NzbDrone.Api.REST; using NzbDrone.Core.Notifications; using Omu.ValueInjecter; @@ -47,11 +48,10 @@ namespace NzbDrone.Api.Notifications notification = _notificationService.Create(notification); notificationResource.Id = notification.Id; - var responseResource = new NotificationResource(); - responseResource.InjectFrom(notification); - responseResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings); + var response = notification.InjectTo(); + response.Fields = SchemaBuilder.GenerateSchema(notification.Settings); - return responseResource; + return response; } private NotificationResource Update(NotificationResource notificationResource) @@ -60,11 +60,10 @@ namespace NzbDrone.Api.Notifications notification.Id = notificationResource.Id; notification = _notificationService.Update(notification); - var responseResource = new NotificationResource(); - responseResource.InjectFrom(notification); - responseResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings); + var response = notification.InjectTo(); + response.Fields = SchemaBuilder.GenerateSchema(notification.Settings); - return responseResource; + return response; } private void DeleteNotification(int id) diff --git a/NzbDrone.Common/StringExtensions.cs b/NzbDrone.Common/StringExtensions.cs index 59dd08478..9cfa71e4b 100644 --- a/NzbDrone.Common/StringExtensions.cs +++ b/NzbDrone.Common/StringExtensions.cs @@ -15,8 +15,8 @@ namespace NzbDrone.Common return string.Format(format, formattingArgs.Cast()); } - private static readonly Regex InvalidCharRegex = new Regex(@"[^a-z0-9\s-]", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly Regex InvalidSearchCharRegex = new Regex(@"[^a-z0-9\s-\.]", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex CollapseSpace = new Regex(@"\s+", RegexOptions.Compiled | RegexOptions.IgnoreCase); public static string ToSlug(this string phrase) @@ -30,6 +30,18 @@ namespace NzbDrone.Common return phrase; } + public static string ToSearchTerm(this string phrase) + { + phrase = phrase.RemoveAccent().ToLower(); + + phrase = phrase.Replace("&", "and"); + phrase = InvalidSearchCharRegex.Replace(phrase, string.Empty); + phrase = CollapseSpace.Replace(phrase, " ").Trim(); + phrase = phrase.Replace(" ", "+"); + + return phrase; + } + public static string RemoveAccent(this string txt) { var bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt); diff --git a/NzbDrone.Core.Test/MetadataSourceTests/TracktProxyFixture.cs b/NzbDrone.Core.Test/MetadataSourceTests/TracktProxyFixture.cs index 0a73855b4..62987173a 100644 --- a/NzbDrone.Core.Test/MetadataSourceTests/TracktProxyFixture.cs +++ b/NzbDrone.Core.Test/MetadataSourceTests/TracktProxyFixture.cs @@ -11,16 +11,18 @@ namespace NzbDrone.Core.Test.MetadataSourceTests [TestFixture] public class TraktProxyFixture : CoreTest { - [TestCase("The Simpsons")] - [TestCase("South Park")] - [TestCase("Franklin & Bash")] - public void successful_search(string title) + [TestCase("The Simpsons", "The Simpsons")] + [TestCase("South Park", "South Park")] + [TestCase("Franklin & Bash", "Franklin & Bash")] + [TestCase("Mr. D", "Mr. D")] + [TestCase("Rob & Big", "Rob and Big")] + public void successful_search(string title, string expected) { var result = Subject.SearchForNewSeries(title); result.Should().NotBeEmpty(); - result[0].Title.Should().Be(title); + result[0].Title.Should().Be(expected); } diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 5ce1f8026..ffef89a10 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -192,7 +192,7 @@ - + @@ -204,7 +204,7 @@ - + diff --git a/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs b/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs index 1da8456e6..a25478659 100644 --- a/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs +++ b/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs @@ -20,7 +20,6 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs } } - public override IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { var searchUrls = new List(); @@ -68,7 +67,5 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs return searchUrls; } - - } } diff --git a/NzbDrone.Core/MetadataSource/TraktProxy.cs b/NzbDrone.Core/MetadataSource/TraktProxy.cs index b017126b1..e2b325677 100644 --- a/NzbDrone.Core/MetadataSource/TraktProxy.cs +++ b/NzbDrone.Core/MetadataSource/TraktProxy.cs @@ -17,7 +17,7 @@ namespace NzbDrone.Core.MetadataSource public List SearchForNewSeries(string title) { var client = BuildClient("search", "shows"); - var restRequest = new RestRequest(title.ToSlug().Replace("-", "+")); + var restRequest = new RestRequest(title.ToSearchTerm()); var response = client.Execute>(restRequest); return response.Data.Select(MapSeries).ToList();