Comments (6)
Hi Armin,
What i have done is the following:
XDocument xdoc = XDocument.Parse(reader.OriginalDocument);
XNamespace xns = xdoc.Root.GetDefaultNamespace();
string Image = "";
BaseFeedItem bfi = item.SpecificItem;
if (bfi.Element.Descendants().Any(x => x.Name.LocalName == xns + "content"))
{
Image = bfi.Element.Descendants().First(x => x.Name.LocalName == xns + "content").Attribute("url").Value;
}
else if (bfi.Element.Descendants().Any(x => x.Name.LocalName == "enclosure"))
{
Image = bfi.Element.Descendants().First(x => x.Name.LocalName == "enclosure").Attribute("url").Value;
}
The parsing to XDocument is necessary to get the XNamespace that is needed to find media:content.
And thanks for the great Library!
Regards,
Erwin
from feedreader.
Hello @tustc79,
the reason for that is, that there is a RSS 2.0 standard and there are many extensions.
The RSS 2.0 standard says, that the image is stored in the enclosure tag.
But as already mentioned, there are extensions (tags). E.g. the itunes feeds have some extensions to store additional information like the ItunesOwner. The media tag that is used in the second RSS feed is such an extension. Most of the RSS 2.0 feeds use the enclosure tag, but there are also some that use one of the available exensions.
For such cases, each item has a property Element which contains all tags of the item. You can use that to read the image, but you have to select it on your own.
So to solve it, there are different ways:
1.) use the Element property and check it on your own
2.) extend the FeedReader so that it supports the media namespace and implement the image selection mode outside
3.) extend the FeedReader so that it supports the media namespace and extend it by the image selection (but please be aware that there are many feeds and those must still be supported).
I'll leave this issue open as I'll probably find some time in the future to find a solution for it and implement it.
best regards,
Armin
from feedreader.
Another addition I made is the following snippet. In one aspnet application ReadAsync(string url) was working fine, while in another it resulted in a deadlock? (site never stopped loading).
/// <summary>
/// reads a feed from an url, not in async to escape possible deadlock. the url must be a feed. Use ParseFeedUrlsFromHtml to
/// parse the feeds from a url which is not a feed.
/// </summary>
/// <param name="url">the url to a feed</param>
/// <returns>parsed feed</returns>
public static Feed ReadNotAsync(string url)
{
string feedContent = string.Empty;
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = client.GetAsync(new Uri(url)).Result;
if (response.IsSuccessStatusCode)
{
feedContent = response.Content.ReadAsStringAsync().Result;
}
}
return FeedParser.GetFeed(feedContent);
}
from feedreader.
I've raised a PR for this issue https://github.com/codehollow/FeedReader/pull/12.
Please review
from feedreader.
thanks to @ceemafour for fixing this issue. Updated NuGet package 1.1.1.1 contains the fixes.
from feedreader.
Hi Armin,
What i have done is the following:
XDocument xdoc = XDocument.Parse(reader.OriginalDocument); XNamespace xns = xdoc.Root.GetDefaultNamespace(); string Image = ""; BaseFeedItem bfi = item.SpecificItem; if (bfi.Element.Descendants().Any(x => x.Name.LocalName == xns + "content")) { Image = bfi.Element.Descendants().First(x => x.Name.LocalName == xns + "content").Attribute("url").Value; } else if (bfi.Element.Descendants().Any(x => x.Name.LocalName == "enclosure")) { Image = bfi.Element.Descendants().First(x => x.Name.LocalName == "enclosure").Attribute("url").Value; }
The parsing to XDocument is necessary to get the XNamespace that is needed to find media:content.
And thanks for the great Library!
Regards,
Erwin
Hi, Can you please explain how you made this work? Cheers
from feedreader.
Related Issues (20)
- Expose Extensions
- Espose Element to MRSS Media Class HOT 2
- How to find item thumbnail of Youtube Feed? HOT 2
- What is the best way to get media enclosure details from a podcast’s RSS feed? HOT 1
- Why doesn't this also have a way to GENERATE rss? HOT 1
- Examples out of date? CS0618: 'FeedReader.Read(string)' is obsolete: 'Use ReadAsync method' HOT 1
- Atom - categories parsing approach incorrect? HOT 1
- Null reference exception in FeedReader.ReadAsync
- Proxy Support HOT 1
- Automatic HTTP decompression should be enabled
- Extension for iTunes
- FeedItem.Link returns incorrect link for AtomItems with multiple links
- Problem with charset
- AutoRedirect: Also handle relative location path correctly
- Custom extension for specific tags
- Thumbnail from feed HOT 1
- Bad usage of the HttpClient
- Different behaviors will occur under RSS and Atom with `FeedItem.Categories`.
- iTunes Keywords
- [Feature Request] Separate downloading and parsing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feedreader.