mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Fixed trakt searching, cleaned up indexer/notification modules
This commit is contained in:
parent
9181b1bb91
commit
f21a235c00
@ -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 @@ private IndexerResource Create(IndexerResource indexerResource)
|
||||
|
||||
if (indexer == null)
|
||||
{
|
||||
throw new BadRequestException("Invalid Notification Implementation");
|
||||
throw new BadRequestException("Invalid Indexer Implementation");
|
||||
}
|
||||
|
||||
indexer.Name = indexerResource.Name;
|
||||
@ -55,11 +56,10 @@ private IndexerResource Create(IndexerResource indexerResource)
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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 @@ private NotificationResource Create(NotificationResource notificationResource)
|
||||
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 @@ private NotificationResource Update(NotificationResource notificationResource)
|
||||
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)
|
||||
|
@ -15,8 +15,8 @@ public static string Inject(this string format, params string[] formattingArgs)
|
||||
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 @@ public static string ToSlug(this string 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)
|
||||
{
|
||||
var bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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" />
|
||||
|
@ -20,7 +20,6 @@ public override IEnumerable<string> RecentFeed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
||||
{
|
||||
var searchUrls = new List<string>();
|
||||
@ -68,7 +67,5 @@ public override IEnumerable<string> GetPartialSeasonSearchUrls(string seriesTitl
|
||||
|
||||
return searchUrls;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class TraktProxy : ISearchForNewSeries, IProvideSeriesInfo, IProvideEpiso
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user