article images to IEnumerable
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ReadSharp.Tests
|
||||
{
|
||||
@@ -9,8 +11,7 @@ namespace ReadSharp.Tests
|
||||
private Reader reader;
|
||||
|
||||
|
||||
public ReadTests()
|
||||
: base()
|
||||
public ReadTests() : base()
|
||||
{
|
||||
reader = new Reader();
|
||||
}
|
||||
@@ -44,9 +45,10 @@ namespace ReadSharp.Tests
|
||||
public async Task ReadArticleWithImagesTest()
|
||||
{
|
||||
Article result = await reader.Read(new Uri("https://hacks.mozilla.org/2013/12/application-layout-with-css3-flexible-box-module/"));
|
||||
Assert.True(result.Images.Count >= 3);
|
||||
Assert.True(result.Images[0].Uri.ToString().StartsWith("https://hacks.mozilla.org"));
|
||||
Assert.True(result.Images[1].Uri.ToString().EndsWith(".gif"));
|
||||
List<ArticleImage> images = result.Images.ToList();
|
||||
Assert.True(images.Count >= 3);
|
||||
Assert.True(images[0].Uri.ToString().StartsWith("https://hacks.mozilla.org"));
|
||||
Assert.True(images[1].Uri.ToString().EndsWith(".gif"));
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +56,7 @@ namespace ReadSharp.Tests
|
||||
public async Task ReadArticleWithNoImagesTest()
|
||||
{
|
||||
Article result = await reader.Read(new Uri("http://getpocket.com/hits/awards/2013/"));
|
||||
Assert.True(result.Images == null || result.Images.Count < 1);
|
||||
Assert.True(result.Images == null || result.Images.Count() < 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +197,7 @@ namespace ReadSharp.Tests
|
||||
|
||||
result = await reader.Read(new Uri("http://arstechnica.com/apple/2014/01/two-steps-forward-a-review-of-the-2013-mac-pro/"), options);
|
||||
Assert.Equal(result.PageCount, 7);
|
||||
Assert.True(result.WordCount > 13000 && result.Images.Count > 10);
|
||||
Assert.True(result.WordCount > 13000 && result.Images.Count() > 10);
|
||||
|
||||
result = await reader.Read(new Uri("http://www.sueddeutsche.de/wirtschaft/netzbetreiber-und-die-energiewende-im-kampf-gegen-blackouts-und-buergerproteste-1.1880754"), options);
|
||||
Assert.Equal(result.PageCount, 2);
|
||||
@@ -217,10 +219,10 @@ namespace ReadSharp.Tests
|
||||
Assert.NotEmpty(result.Content);
|
||||
|
||||
result = await reader.Read(new Uri("http://www.nytimes.com/2014/01/31/world/europe/ukraine-unrest.html?hp&_r=0"));
|
||||
Assert.True(result.Images != null && result.Images.Count > 0);
|
||||
Assert.True(result.Images != null && result.Images.Count() > 0);
|
||||
|
||||
result = await reader.Read(new Uri("http://www.polygon.com/2013/2/25/4026668/tomb-raider-review"));
|
||||
Assert.True(result.Images != null && result.Images.Count > 3 && result.Content.Contains("For a reboot of a series that had lost its focus and purpose"));
|
||||
Assert.True(result.Images != null && result.Images.Count() > 3 && result.Content.Contains("For a reboot of a series that had lost its focus and purpose"));
|
||||
|
||||
result = await reader.Read(new Uri("http://www.polygon.com/2014/1/31/5364728/super-bowl-xlviii-xbox-activities-new-york"));
|
||||
Assert.True(result.Content.Contains("week for Super Bowl XLVIII") && result.Content.Contains("two tickets to the Super Bowl."));
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace ReadSharp
|
||||
/// <value>
|
||||
/// The images.
|
||||
/// </value>
|
||||
public List<ArticleImage> Images { get; set; }
|
||||
public IEnumerable<ArticleImage> Images { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the next page URL.
|
||||
|
||||
@@ -97,19 +97,19 @@
|
||||
<HintPath>..\packages\HtmlAgilityPack-PCL.1.4.6\lib\HtmlAgilityPack-PCL.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.166\lib\portable-net40+sl4+win8+wp71+wpa81\Microsoft.Threading.Tasks.dll</HintPath>
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\portable-net45+win8+wp8+wpa81\Microsoft.Threading.Tasks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks.Extensions">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.166\lib\portable-net40+sl4+win8+wp71+wpa81\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\portable-net45+win8+wp8+wpa81\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http">
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.19\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll</HintPath>
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Extensions">
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.19\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll</HintPath>
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Primitives">
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.19\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll</HintPath>
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
+16
-12
@@ -147,19 +147,23 @@ namespace ReadSharp
|
||||
|
||||
// get images from article
|
||||
int id = 1;
|
||||
List<ArticleImage> images = response.TranscodingResult.Images.Select(image =>
|
||||
{
|
||||
Uri imageUri = null;
|
||||
Uri.TryCreate(image.GetAttributeValue("src", null), UriKind.Absolute, out imageUri);
|
||||
|
||||
return new ArticleImage()
|
||||
IEnumerable<ArticleImage> images = response.TranscodingResult.Images
|
||||
.Select(image =>
|
||||
{
|
||||
ID = (id++).ToString(),
|
||||
Uri = imageUri,
|
||||
Title = image.GetAttributeValue("title", null),
|
||||
AlternativeText = image.GetAttributeValue("alt", null)
|
||||
};
|
||||
}).GroupBy(image => image.Uri).Select(g => g.First()).Where(image => image.Uri != null).ToList();
|
||||
Uri imageUri = null;
|
||||
Uri.TryCreate(image.GetAttributeValue("src", null), UriKind.Absolute, out imageUri);
|
||||
|
||||
return new ArticleImage()
|
||||
{
|
||||
ID = (id++).ToString(),
|
||||
Uri = imageUri,
|
||||
Title = image.GetAttributeValue("title", null),
|
||||
AlternativeText = image.GetAttributeValue("alt", null)
|
||||
};
|
||||
})
|
||||
.GroupBy(image => image.Uri)
|
||||
.Select(g => g.First())
|
||||
.Where(image => image.Uri != null);
|
||||
|
||||
// get word count and plain text
|
||||
string plainContent;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="HtmlAgilityPack-PCL" version="1.4.6" targetFramework="portable-win+net403+sl40+wp71" />
|
||||
<package id="Microsoft.Bcl" version="1.1.7" targetFramework="portable-net403+sl50+win+wp80" requireReinstallation="True" />
|
||||
<package id="Microsoft.Bcl.Async" version="1.0.166" targetFramework="portable-net403+sl50+win+wp80" requireReinstallation="True" />
|
||||
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="portable-net45+win+wpa81+wp80" />
|
||||
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="portable-net45+win+wpa81+wp80" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="portable-net403+sl50+win+wp80" />
|
||||
<package id="Microsoft.Net.Http" version="2.2.19" targetFramework="portable-net403+sl50+win+wp80" />
|
||||
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="portable-net45+win+wpa81+wp80" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user