From d754eda21618cfe9fd856590fb2acc92d475ff2e Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 17 Feb 2014 16:31:29 +0100 Subject: [PATCH] respect multipage limit --- ReadSharp/Reader.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ReadSharp/Reader.cs b/ReadSharp/Reader.cs index 46a4eec..d824bfe 100644 --- a/ReadSharp/Reader.cs +++ b/ReadSharp/Reader.cs @@ -34,6 +34,11 @@ namespace ReadSharp /// protected NReadabilityTranscoder _transcoder; + /// + /// The HTTP options + /// + protected HttpOptions _options; + /// /// Redirect faulty mobile URIs to desktop equivalents /// @@ -66,6 +71,8 @@ namespace ReadSharp options = HttpOptions.CreateDefault(); } + _options = options; + // initialize custom encoder _encoder = new Encodings.Encoder(true); @@ -133,10 +140,9 @@ namespace ReadSharp // get images from article int id = 1; - - List images = response.TranscodingResult.Images.Select(image => + List images = response.TranscodingResult.Images.Select(image => { - Uri imageUri; + Uri imageUri = null; Uri.TryCreate(image.GetAttributeValue("src", null), UriKind.Absolute, out imageUri); return new ArticleImage() @@ -146,7 +152,7 @@ namespace ReadSharp Title = image.GetAttributeValue("title", null), AlternativeText = image.GetAttributeValue("alt", null) }; - }).ToList(); + }).GroupBy(image => image.Uri).Select(g => g.First()).Where(image => image.Uri != null).ToList(); // get word count and plain text string plainContent; @@ -349,7 +355,7 @@ namespace ReadSharp // multiple pages are available try { - if (options.MultipageDownload && transcodingResult.NextPageUrl != null && (previousResponse == null || (previousResponse != null && previousResponse.PageCount < 10))) + if (options.MultipageDownload && transcodingResult.NextPageUrl != null && (previousResponse == null || (previousResponse != null && previousResponse.PageCount < _options.MultipageLimit))) { return await Request(new Uri(transcodingResult.NextPageUrl), new ReadOptions() {