Fixed trakt searching, cleaned up indexer/notification modules

pull/4/head
Mark McDowall 12 years ago
parent 9181b1bb91
commit f21a235c00

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Api.ClientSchema; using NzbDrone.Api.ClientSchema;
using NzbDrone.Api.Mapping;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using Omu.ValueInjecter; using Omu.ValueInjecter;
@ -46,7 +47,7 @@ namespace NzbDrone.Api.Indexers
if (indexer == null) if (indexer == null)
{ {
throw new BadRequestException("Invalid Notification Implementation"); throw new BadRequestException("Invalid Indexer Implementation");
} }
indexer.Name = indexerResource.Name; indexer.Name = indexerResource.Name;
@ -55,11 +56,10 @@ namespace NzbDrone.Api.Indexers
indexer = _indexerService.Create(indexer); indexer = _indexerService.Create(indexer);
var responseResource = new IndexerResource(); var response = indexer.InjectTo<IndexerResource>();
responseResource.InjectFrom(indexer); response.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
responseResource.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
return responseResource; return response;
} }
} }
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Api.ClientSchema; using NzbDrone.Api.ClientSchema;
using NzbDrone.Api.Mapping;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
using NzbDrone.Core.Notifications; using NzbDrone.Core.Notifications;
using Omu.ValueInjecter; using Omu.ValueInjecter;
@ -47,11 +48,10 @@ namespace NzbDrone.Api.Notifications
notification = _notificationService.Create(notification); notification = _notificationService.Create(notification);
notificationResource.Id = notification.Id; notificationResource.Id = notification.Id;
var responseResource = new NotificationResource(); var response = notification.InjectTo<NotificationResource>();
responseResource.InjectFrom(notification); response.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
responseResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
return responseResource; return response;
} }
private NotificationResource Update(NotificationResource notificationResource) private NotificationResource Update(NotificationResource notificationResource)
@ -60,11 +60,10 @@ namespace NzbDrone.Api.Notifications
notification.Id = notificationResource.Id; notification.Id = notificationResource.Id;
notification = _notificationService.Update(notification); notification = _notificationService.Update(notification);
var responseResource = new NotificationResource(); var response = notification.InjectTo<NotificationResource>();
responseResource.InjectFrom(notification); response.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
responseResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
return responseResource; return response;
} }
private void DeleteNotification(int id) private void DeleteNotification(int id)

@ -15,8 +15,8 @@ namespace NzbDrone.Common
return string.Format(format, formattingArgs.Cast<object>()); return string.Format(format, formattingArgs.Cast<object>());
} }
private static readonly Regex InvalidCharRegex = new Regex(@"[^a-z0-9\s-]", RegexOptions.Compiled | RegexOptions.IgnoreCase); 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); private static readonly Regex CollapseSpace = new Regex(@"\s+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static string ToSlug(this string phrase) public static string ToSlug(this string phrase)
@ -30,6 +30,18 @@ namespace NzbDrone.Common
return phrase; 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) public static string RemoveAccent(this string txt)
{ {
var bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt); var bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);

@ -11,16 +11,18 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
[TestFixture] [TestFixture]
public class TraktProxyFixture : CoreTest<TraktProxy> public class TraktProxyFixture : CoreTest<TraktProxy>
{ {
[TestCase("The Simpsons")] [TestCase("The Simpsons", "The Simpsons")]
[TestCase("South Park")] [TestCase("South Park", "South Park")]
[TestCase("Franklin & Bash")] [TestCase("Franklin & Bash", "Franklin & Bash")]
public void successful_search(string title) [TestCase("Mr. D", "Mr. D")]
[TestCase("Rob & Big", "Rob and Big")]
public void successful_search(string title, string expected)
{ {
var result = Subject.SearchForNewSeries(title); var result = Subject.SearchForNewSeries(title);
result.Should().NotBeEmpty(); result.Should().NotBeEmpty();
result[0].Title.Should().Be(title); result[0].Title.Should().Be(expected);
} }

@ -192,7 +192,7 @@
<Compile Include="ProviderTests\MisnamedProviderTest.cs" /> <Compile Include="ProviderTests\MisnamedProviderTest.cs" />
<Compile Include="ProviderTests\EventClientProviderTest.cs" /> <Compile Include="ProviderTests\EventClientProviderTest.cs" />
<Compile Include="ProviderTests\XbmcProviderTest.cs" /> <Compile Include="ProviderTests\XbmcProviderTest.cs" />
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" /> <Compile Include="SeriesStatsTests\EpisodeProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\ImportFileFixture.cs" /> <Compile Include="ProviderTests\DiskScanProviderTests\ImportFileFixture.cs" />
<Compile Include="FluentTest.cs" /> <Compile Include="FluentTest.cs" />
<Compile Include="InstrumentationTests\DatabaseTargetFixture.cs" /> <Compile Include="InstrumentationTests\DatabaseTargetFixture.cs" />
@ -204,7 +204,7 @@
<Compile Include="HistoryTests\HistoryRepositoryFixture.cs" /> <Compile Include="HistoryTests\HistoryRepositoryFixture.cs" />
<Compile Include="MediaFileTests\MediaFileServiceTest.cs" /> <Compile Include="MediaFileTests\MediaFileServiceTest.cs" />
<Compile Include="Configuration\ConfigServiceFixture.cs" /> <Compile Include="Configuration\ConfigServiceFixture.cs" />
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest.cs" /> <Compile Include="SeriesStatsTests\EpisodeProviderTests\EpisodeProviderTest.cs" />
<Compile Include="Framework\TestDbHelper.cs" /> <Compile Include="Framework\TestDbHelper.cs" />
<Compile Include="ParserTests\ParserFixture.cs" /> <Compile Include="ParserTests\ParserFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

@ -20,7 +20,6 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
} }
} }
public override IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) public override IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{ {
var searchUrls = new List<string>(); var searchUrls = new List<string>();
@ -68,7 +67,5 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
return searchUrls; return searchUrls;
} }
} }
} }

@ -17,7 +17,7 @@ namespace NzbDrone.Core.MetadataSource
public List<Series> SearchForNewSeries(string title) public List<Series> SearchForNewSeries(string title)
{ {
var client = BuildClient("search", "shows"); var client = BuildClient("search", "shows");
var restRequest = new RestRequest(title.ToSlug().Replace("-", "+")); var restRequest = new RestRequest(title.ToSearchTerm());
var response = client.Execute<List<Show>>(restRequest); var response = client.Execute<List<Show>>(restRequest);
return response.Data.Select(MapSeries).ToList(); return response.Data.Select(MapSeries).ToList();

Loading…
Cancel
Save