Fixed trakt searching, cleaned up indexer/notification modules

This commit is contained in:
Mark McDowall 2013-05-29 20:26:47 -07:00
parent 9181b1bb91
commit f21a235c00
7 changed files with 35 additions and 25 deletions

View File

@ -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<IndexerResource>();
response.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
return responseResource;
return response;
}
}
}

View File

@ -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<NotificationResource>();
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<NotificationResource>();
response.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
return responseResource;
return response;
}
private void DeleteNotification(int id)

View File

@ -15,8 +15,8 @@ namespace NzbDrone.Common
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 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);

View File

@ -11,16 +11,18 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
[TestFixture]
public class TraktProxyFixture : CoreTest<TraktProxy>
{
[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);
}

View File

@ -192,7 +192,7 @@
<Compile Include="ProviderTests\MisnamedProviderTest.cs" />
<Compile Include="ProviderTests\EventClientProviderTest.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="FluentTest.cs" />
<Compile Include="InstrumentationTests\DatabaseTargetFixture.cs" />
@ -204,7 +204,7 @@
<Compile Include="HistoryTests\HistoryRepositoryFixture.cs" />
<Compile Include="MediaFileTests\MediaFileServiceTest.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="ParserTests\ParserFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

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

View File

@ -17,7 +17,7 @@ namespace NzbDrone.Core.MetadataSource
public List<Series> 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<List<Show>>(restRequest);
return response.Data.Select(MapSeries).ToList();