Giter Site home page Giter Site logo

Comments (6)

VDWWD avatar VDWWD commented on August 15, 2024 3

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.

arminreiter avatar arminreiter commented on August 15, 2024

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.

VDWWD avatar VDWWD commented on August 15, 2024

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.

ceemafour avatar ceemafour commented on August 15, 2024

I've raised a PR for this issue https://github.com/codehollow/FeedReader/pull/12.
Please review

from feedreader.

arminreiter avatar arminreiter commented on August 15, 2024

thanks to @ceemafour for fixing this issue. Updated NuGet package 1.1.1.1 contains the fixes.

from feedreader.

aliusman avatar aliusman commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.