Fixed network auth issue, custom parser issue

pull/3113/head
kay.one 14 years ago
parent eb48a7eff8
commit b65fe99b30

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.ServiceModel.Syndication;
using System.Xml;
using AutoMoq;
@ -11,6 +12,7 @@ using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
@ -29,7 +31,7 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>()))
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
@ -47,6 +49,63 @@ namespace NzbDrone.Core.Test
Assert.IsEmpty(exceptions);
}
[Test]
[Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)]
public void parse_feed_test_success(string title, int season, int episode, QualityTypes quality)
{
var mocker = new AutoMoqer();
var summary = "My fake summary";
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
mocker.GetMock<SeriesProvider>()
.Setup(c => c.FindSeries(It.IsAny<String>()))
.Returns(Builder<Series>.CreateNew().Build());
var fakeRssItem = Builder<SyndicationItem>.CreateNew()
.With(c => c.Title = new TextSyndicationContent(title))
.With(c => c.Summary = new TextSyndicationContent(summary))
.Build();
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
Assert.IsNotNull(result);
Assert.AreEqual(summary, result.EpisodeTitle);
}
[Test]
[Row("Adventure.Inc.DVDRip.XviD-OSiTV")]
public void parse_feed_test_fail(string title)
{
var mocker = new AutoMoqer();
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
mocker.GetMock<SeriesProvider>(MockBehavior.Strict);
var fakeRssItem = Builder<SyndicationItem>.CreateNew()
.With(c => c.Title = new TextSyndicationContent(title))
.Build();
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
Assert.IsNull(result);
}
[Test]
public void downloadFeed()
{
@ -102,6 +161,11 @@ namespace NzbDrone.Core.Test
get { return new[] { "www.google.com" }; }
}
protected override NetworkCredential Credentials
{
get { return null; }
}
public override string Name
{
get { return "Mocked Indexer"; }
@ -137,4 +201,33 @@ namespace NzbDrone.Core.Test
}
}
public class CustomParserIndexer : IndexerProviderBase
{
public CustomParserIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider)
: base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
{
}
public override string Name
{
get { return "Custom parser"; }
}
protected override string[] Urls
{
get { return new[] { "http://www.google.com" }; }
}
protected override string NzbDownloadUrl(SyndicationItem item)
{
return "http://www.google.com";
}
protected override Model.EpisodeParseResult CustomParser(SyndicationItem item, Model.EpisodeParseResult currentResult)
{
currentResult.EpisodeTitle = item.Summary.Text;
return currentResult;
}
}
}

@ -166,6 +166,7 @@
<Compile Include="Instrumentation\SubsonicTarget.cs" />
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />
<Compile Include="Instrumentation\NlogWriter.cs" />
<Compile Include="Model\SabnzbdInfoModel.cs" />
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
<Compile Include="Providers\AutoConfigureProvider.cs" />
<Compile Include="Providers\Indexer\NzbMatrixProvider.cs" />

@ -40,10 +40,11 @@ namespace NzbDrone.Core.Providers.Core
}
}
public virtual Stream DownloadStream(string url)
public virtual Stream DownloadStream(string url, NetworkCredential credential)
{
var request = WebRequest.Create(url);
request.Credentials = credential;
var response = request.GetResponse();
return response.GetResponseStream();

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.ServiceModel.Syndication;
using NLog;
using NzbDrone.Core.Model;
@ -48,6 +49,15 @@ namespace NzbDrone.Core.Providers.Indexer
protected abstract string[] Urls { get; }
/// <summary>
/// Gets the credential.
/// </summary>
protected virtual NetworkCredential Credentials
{
get { return null; }
}
public IndexerSetting Settings
{
get
@ -70,7 +80,7 @@ namespace NzbDrone.Core.Providers.Indexer
{
_logger.Trace("Downloading RSS " + url);
var reader = new SyndicationFeedXmlReader(_httpProvider.DownloadStream(url));
var reader = new SyndicationFeedXmlReader(_httpProvider.DownloadStream(url, Credentials));
var feed = SyndicationFeed.Load(reader).Items;
foreach (var item in feed)
@ -168,10 +178,10 @@ namespace NzbDrone.Core.Providers.Indexer
/// </summary>
/// <param name = "item">RSS feed item to parse</param>
/// <returns>Detailed episode info</returns>
protected EpisodeParseResult ParseFeed(SyndicationItem item)
public EpisodeParseResult ParseFeed(SyndicationItem item)
{
var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text);
if (episodeParseResult == null) return CustomParser(item, null);
if (episodeParseResult == null) return null;
var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);
@ -185,7 +195,7 @@ namespace NzbDrone.Core.Providers.Indexer
}
_logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.CleanTitle);
return CustomParser(item, episodeParseResult);
return null;
}
/// <summary>

@ -1,4 +1,7 @@
using System.ServiceModel.Syndication;
using System;
using System.Net;
using System.ServiceModel.Syndication;
using System.Web;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using SubSonic.Repository;
@ -7,7 +10,8 @@ namespace NzbDrone.Core.Providers.Indexer
{
public class NewzbinProvider : IndexerProviderBase
{
public NewzbinProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
public NewzbinProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider)
: base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
{
}
@ -17,11 +21,16 @@ namespace NzbDrone.Core.Providers.Indexer
{
return new[]
{
string.Format("http://{0}:{1}@www.newzbin.com/browse/category/p/tv?feed=rss&hauth=1", _configProvider.NewzbinUsername, _configProvider.NewzbinPassword)
"http://www.newzbin.com/browse/category/p/tv?feed=rss&hauth=1"
};
}
}
protected override NetworkCredential Credentials
{
get { return new NetworkCredential(_configProvider.NewzbinUsername, _configProvider.NewzbinPassword); }
}
public override string Name
{
get { return "Newzbin"; }

@ -1,4 +1,6 @@
using System.ServiceModel.Syndication;
using System;
using System.Net;
using System.ServiceModel.Syndication;
using NzbDrone.Core.Providers.Core;
using SubSonic.Repository;
@ -6,7 +8,8 @@ namespace NzbDrone.Core.Providers.Indexer
{
public class NzbMatrixProvider : IndexerProviderBase
{
public NzbMatrixProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
public NzbMatrixProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider)
: base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
{
}
@ -23,7 +26,6 @@ namespace NzbDrone.Core.Providers.Indexer
};
}
}
public override string Name
{

@ -1,4 +1,5 @@
using System.ServiceModel.Syndication;
using System.Net;
using System.ServiceModel.Syndication;
using NzbDrone.Core.Providers.Core;
using SubSonic.Repository;
@ -6,7 +7,8 @@ namespace NzbDrone.Core.Providers.Indexer
{
public class NzbsOrgProvider : IndexerProviderBase
{
public NzbsOrgProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
public NzbsOrgProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider)
: base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
{
}
@ -26,7 +28,6 @@ namespace NzbDrone.Core.Providers.Indexer
get { return "Nzbs.org"; }
}
protected override string NzbDownloadUrl(SyndicationItem item)
{
return item.Id;

@ -1,4 +1,5 @@
using System.ServiceModel.Syndication;
using System.Net;
using System.ServiceModel.Syndication;
using NzbDrone.Core.Providers.Core;
using SubSonic.Repository;
@ -6,7 +7,8 @@ namespace NzbDrone.Core.Providers.Indexer
{
public class NzbsRUsProvider : IndexerProviderBase
{
public NzbsRUsProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
public NzbsRUsProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider)
: base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider)
{
}

Loading…
Cancel
Save