Skip to content

Commit

Permalink
If a feed can't be downloaded, ignore the error and try the rest of t…
Browse files Browse the repository at this point in the history
…he feeds.
  • Loading branch information
yodax committed Jul 18, 2015
1 parent dbb3556 commit ba56e77
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
27 changes: 27 additions & 0 deletions Subtitle.Downloader.Tests/WhenDownloadingFromAFaultyFeed.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using FluentAssertions;
using NSubstitute;
using NUnit.Framework;
using Subtitle.Common;
using Subtitle.Provider.Addic7ed;

namespace Subtitle.Downloader.Tests
Expand All @@ -26,5 +28,30 @@ public void TheFaultyItemShouldBeIgnored()

foundLinks.Count.Should().Be(6);
}

[Test]
public void IfTheDownloadFailsTheExceptionShouldBeEaten()
{
var foundLinks = new List<FoundLink>();

var feedLinks = new List<string>
{
"Exception.xml",
"FaultyRss.xml",
};

var download = Substitute.For<IDownload>();

download.From("FaultyRss.xml")
.Returns(new ResourceDownload().From("FaultyRss.xml"));
download.From("Exception.xml")
.Returns(d => { throw new System.Net.WebException(); });

var linkFinder = new LinkFinder(foundLinks, download);

linkFinder.LookForLinksFromFeeds(feedLinks);

foundLinks.Count.Should().Be(6);
}
}
}
2 changes: 1 addition & 1 deletion Subtitle.Provider.Addic7ed/AddictedFeedReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Subtitle.Provider.Addic7ed
{
public class AddictedFeedReader
public static class AddictedFeedReader
{
public static IEnumerable<string> GetAllLinksFrom(string feedContent)
{
Expand Down
23 changes: 15 additions & 8 deletions Subtitle.Provider.Addic7ed/LinkFinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Subtitle.Common;

namespace Subtitle.Provider.Addic7ed
Expand All @@ -21,14 +22,20 @@ public void LookForLinksFromFeeds(IEnumerable<string> feedLinks)
var linksFoundFromFeeds = new List<FoundLink>();
foreach (var feedLink in feedLinks)
{
linksFoundFromFeeds.AddRange(AddictedFeedReader
.GetAllLinksFrom(_download.From(feedLink))
.Where(l => l.Contains("/serie/"))
.Select(s => new FoundLink
{
Link = s,
FoundOn = DateTime.Now
}));
try
{
var feedContent = _download.From(feedLink);
linksFoundFromFeeds.AddRange(AddictedFeedReader
.GetAllLinksFrom(feedContent)
.Where(l => l.Contains("/serie/"))
.Select(s => new FoundLink
{
Link = s,
FoundOn = DateTime.Now
}));
}
catch (WebException){}

}

AddFoundLinksToStore(linksFoundFromFeeds);
Expand Down

0 comments on commit ba56e77

Please sign in to comment.