Oh hai search!

This commit is contained in:
kay.one 2011-05-26 23:03:57 -07:00
parent ac2d33443b
commit cbbb6e2b18
11 changed files with 96 additions and 14 deletions

View File

@ -80,7 +80,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries())
.Returns(series.AsQueryable());
.Returns(series);
mocker.GetMock<MediaFileProvider>()
.Setup(s => s.Scan(series[0]))
@ -109,7 +109,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries())
.Returns(series.AsQueryable());
.Returns(series);
mocker.GetMock<MediaFileProvider>()
.Setup(s => s.Scan(series[0]))
@ -140,7 +140,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries())
.Returns(series.AsQueryable());
.Returns(series);
mocker.GetMock<MediaFileProvider>()
.Setup(s => s.Scan(series[0]))

View File

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries())
.Returns(series.AsQueryable());
.Returns(series);
mocker.GetMock<DiskScanJob>()
@ -95,7 +95,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries())
.Returns(series.AsQueryable());
.Returns(series);
mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[0].SeriesId))

View File

@ -187,8 +187,31 @@ namespace NzbDrone.Core.Test
Assert.ForAll(result, r => r.CleanTitle == "simpsons");
Assert.ForAll(result, r => r.SeasonNumber == 21);
Assert.ForAll(result, r => r.EpisodeNumbers.Contains(23));
}
[Test]
public void nzbsorg_multi_word_search_returns_valid_results()
{
var mocker = new AutoMoqer();
mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbsOrgUId)
.Returns("43516");
mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbsOrgHash)
.Returns("bc8edb4cc49d4ae440775adec5ac001f");
mocker.Resolve<HttpProvider>();
var result = mocker.Resolve<NzbsOrg>().FetchEpisode("Blue Bloods", 1, 19);
Assert.IsNotEmpty(result);
Assert.ForAll(result, r => r.CleanTitle == "bluebloods");
Assert.ForAll(result, r => r.SeasonNumber == 1);
Assert.ForAll(result, r => r.EpisodeNumbers.Contains(19));
}
}
}

View File

@ -324,10 +324,10 @@ namespace NzbDrone.Core.Test
public void scan_media_job_should_not_scan_new_series()
{
var mocker = new AutoMoqer();
IQueryable<Series> fakeSeries = Builder<Series>.CreateListOfSize(2)
var fakeSeries = Builder<Series>.CreateListOfSize(2)
.WhereTheFirst(1).Has(c => c.Episodes = new List<Episode>())
.AndTheNext(1).Has(c => c.Episodes = Builder<Episode>.CreateListOfSize(10).Build())
.Build().AsQueryable();
.Build();
mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries()).Returns(fakeSeries);

View File

@ -110,6 +110,9 @@ namespace NzbDrone.Core
_kernel.Bind<IndexerBase>().To<NzbMatrix>().InSingletonScope();
_kernel.Bind<IndexerBase>().To<NzbsRUs>().InSingletonScope();
_kernel.Bind<IndexerBase>().To<Newzbin>().InSingletonScope();
var indexers = _kernel.GetAll<IndexerBase>();
_kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
}
private static void BindJobs()
@ -119,6 +122,7 @@ namespace NzbDrone.Core
_kernel.Bind<IJob>().To<UpdateInfoJob>().InTransientScope();
_kernel.Bind<IJob>().To<DiskScanJob>().InTransientScope();
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InTransientScope();
_kernel.Bind<IJob>().To<EpisodeSearchJob>().InTransientScope();
_kernel.Get<JobProvider>().Initialize();
_kernel.Get<WebTimer>().StartTimer(30);

View File

@ -25,7 +25,7 @@ namespace NzbDrone.Core.Providers.Indexer
public IndexerBase()
{
}
/// <summary>
@ -96,7 +96,7 @@ namespace NzbDrone.Core.Providers.Indexer
public virtual IList<EpisodeParseResult> FetchEpisode(string seriesTitle, int seasonNumber, int episodeNumber)
{
_logger.Debug("Searching {0} for {1}-S{2}E{3:00}", Name, seriesTitle, seasonNumber, episodeNumber);
_logger.Debug("Searching {0} for {1}-S{2:00}E{3:00}", Name, seriesTitle, seasonNumber, episodeNumber);
var result = new List<EpisodeParseResult>();
@ -162,5 +162,10 @@ namespace NzbDrone.Core.Providers.Indexer
return CustomParser(item, episodeParseResult);
}
protected static string GetQueryTitle(string title)
{
return title.Trim().Replace(' ', '+');
}
}
}

View File

@ -11,7 +11,8 @@ namespace NzbDrone.Core.Providers.Indexer
{
public class NzbsOrg : IndexerBase
{
public NzbsOrg(HttpProvider httpProvider, ConfigProvider configProvider) : base(httpProvider, configProvider)
public NzbsOrg(HttpProvider httpProvider, ConfigProvider configProvider)
: base(httpProvider, configProvider)
{
}
@ -43,11 +44,11 @@ namespace NzbDrone.Core.Providers.Indexer
foreach (var url in Urls)
{
searchUrls.Add(String.Format("{0}&action=search&q={1}+s{2}e{3:00}", url, seriesTitle, seasonNumber, episodeNumber));
searchUrls.Add(String.Format("{0}&action=search&q={1}+s{2:00}e{3:00}", url, GetQueryTitle(seriesTitle), seasonNumber, episodeNumber));
}
return searchUrls;
}
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
@ -33,9 +34,9 @@ namespace NzbDrone.Core.Providers
{
}
public virtual IQueryable<Series> GetAllSeries()
public virtual IList<Series> GetAllSeries()
{
return _repository.All<Series>();
return _repository.All<Series>().ToList();
}
public virtual Series GetSeries(int seriesId)

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Mvc;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Controllers
{
public class EpisodeController : Controller
{
private readonly JobProvider _jobProvider;
public EpisodeController(JobProvider jobProvider)
{
_jobProvider = jobProvider;
}
public JsonResult Search(int episodeId)
{
_jobProvider.QueueJob(typeof(EpisodeSearchJob), episodeId);
return new JsonResult { Data = "ok" };
}
}
}

View File

@ -215,6 +215,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>UploadLocalization.en-US.resx</DependentUpon>
</Compile>
<Compile Include="Controllers\EpisodeController.cs" />
<Compile Include="Controllers\HealthController.cs" />
<Compile Include="Controllers\HistoryController.cs" />
<Compile Include="Controllers\LogController.cs" />

View File

@ -78,6 +78,8 @@
columns.Bound(c => c.AirDate).Format("{0:d}").Width(0);
columns.Bound(c => c.Quality).Width(0);
columns.Bound(c => c.Status).Width(0);
columns.Bound(o => o.EpisodeId).Title("")
.ClientTemplate("<a href='#Search' onClick=\"return searchForEpisode('<#= EpisodeId #>')\" >Search</a>");
})
.DetailView(detailView => detailView.ClientTemplate("<div><#= Overview #> </br><#= Path #> </div>"))
.ClientEvents(clientEvents =>
@ -150,5 +152,18 @@
function episodeDetailExpanded(e) {
$console.log("OnDetailViewExpand :: " + e.masterRow.cells[1].innerHTML);
}
var searchUrl = '@Url.Action("Search", "Episode")';
function searchForEpisode(id) {
$.ajax({
type: "POST",
url: searchUrl,
data: jQuery.param({ episodeId: id }),
error: function (req, status, error) {
alert("Sorry! We could search for " + id + " at this time. " + error);
}
});
}
</script>
}