Showing posts with label rss. Show all posts
Showing posts with label rss. Show all posts

Sunday, October 7, 2018

MRSS - Display poster/background image on audio-only feed

Leave a Comment

Not sure if this is possible, but I need to display a poster/background image in an MRSS feed where I am playing audio only, not sure if this can be done. As at the moment, when the player accesses this feed, it plays the audio, but with a black background. I am hoping to add an image there, but not sure what element to use. I have checked the MRSS specs here http://www.rssboard.org/media-rss, but it doesn't look like they've been updated for a while and I cannot find how to add such a background image.

<item>          <title>My Title</title>          <link></link>          <description>My Description</description>          <guid isPermaLink="false"></guid>          <media:category>All</media:category>          <media:category>Music</media:category>          <media:content url="http://linktoaudiofile.mp3 language="en-us" medium="audio" isDefault="true">             <media:title type="plain">Title</media:title>             <media:description type="html">Description</media:description>             <media:thumbnail url="icon_large.png" />             <media:credit role="author" scheme="urn:ebu">Author</media:credit>             <media:copyright url="coprightURL" />          </media:content>       </item> 

Any ideas? Thank you.

Happy to also understand if this can be done a different way, such as using a player with the element instead?

0 Answers

Read More

Monday, August 13, 2018

How to parse an RSS feed using JavaScript (External Domain)?

Leave a Comment

Question

I need to parse an RSS feed and display the parsed details in an HTML page.

Solution I Found

How to parse an RSS feed using JavaScript? is a very similar question and I followed it.

Using above question, I build the following code.

 <script>   $(document).ready(function() {     //feed to parse     var feed = "https://feeds.feedburner.com/raymondcamdensblog?format=xml";      $.ajax(feed, {         accepts:{             xml:"application/rss+xml"         },         dataType:"xml",         success:function(data) {             //Credit: http://stackoverflow.com/questions/10943544/how-to-parse-an-rss-feed-using-javascript              $(data).find("item").each(function () { // or "item" or whatever suits your feed                 var el = $(this);                 document.write("------------------------");                 document.write("title      : " + el.find("title").text());                 document.write("link       : " + el.find("link").text());                 document.write("description: " + el.find("description").text());             });           }        });  }); </script> 

The Error

Failed to load https://feeds.feedburner.com/raymondcamdensblog?format=xml: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

What I need

How can I change my code to read RSS feeds using JavaScript without getting above error?

3 Answers

Answers 1

You're getting that error because of the same-origin policy. See below and/or read the full article at MDN:

For security reasons, browsers restrict cross-origin HTTP requests initiated from within scripts. For example, XMLHttpRequest and the Fetch API follow the same-origin policy. This means that a web application using those APIs can only request HTTP resources from the same origin the application was loaded from, unless the response from the other origin includes the right CORS headers.

So your script is making a cross-origin HTTP request (which uses XMLHttpRequest through jQuery.ajax()) to https://feeds.feedburner.com/raymondcamdensblog?format=xml, but the CORS header of Access-Control-Allow-Origin is not being set by FeedBurner, therefore you get the "Failed to load ..." error. (But even if the header was set, if it didn't include your origin (localhost or some-domain.com), you'd still get the same error.)

So how can you change your code to read the RSS feeds using JavaScript without getting that error?

  1. Use a third-party web service, just like what @Saeed suggested.

  2. Create a server-side script (e.g. using PHP) that fetches the feed content and make AJAX requests to that script instead of directly requesting it from FeedBurner, or the actual source URL. See below for a simple example.

  3. If I really had to, I'd probably ask FeedBurner to set the appropriate CORS headers...


Sample of a very simple PHP script for fetching the feed content:

<?php // Set the feed URL. $feed_url = 'https://feeds.feedburner.com/raymondcamdensblog?format=xml';  // Fetch the content. // See http://php.net/manual/en/function.file-get-contents.php for more // information about the file_get_contents() function. $content = file_get_contents( $feed_url );  // Set the Content-Type header. header( 'Content-Type: application/rss+xml' );  // Display the content and exit. echo $content; exit; ?> 

So for example, you could save that to fetch-feed.php, and then in your JavaScript/jQuery script code, change the value of the feed variable like so:

var feed = "http://localhost/path/to/fetch-feed.php"; 

That way (i.e. using your own server-side script), you could at least be sure that the browser would always grant your XMLHttpRequest (or AJAX) request. (i.e. you wouldn't get the "No 'Access-Control-Allow-Origin' header" error)

Answers 2

You could use something like https://rss2json.com. It parses the feed to json for javascript:

var feedURL = "https://feeds.feedburner.com/raymondcamdensblog?format=xml"; $.ajax({   type: 'GET',   url: "https://api.rss2json.com/v1/api.json?rss_url=" + feedURL,   dataType: 'jsonp',   success: function(result) {     console.log(result);   } }); 

Answers 3

It's a CORS related error. You are getting that error because the URL from where you are requesting data does not have CORS enabled. CORS stands for 'Cross-Origin Resource Sharing'. If CORS is enabled on a server, your browser will let you make requests to that server. Otherwise, it will not.

https://feeds.feedburner.com/raymondcamdensblog?format=xml does not have CORS enabled, that's why your browser will not allow you to make ajax requests to that server. You can get around it by making the requests on your server and provide the data to the browser from your own server or a server that has CORS enabled.

Read More

Friday, April 29, 2016

get image url of rss with rome library

Leave a Comment

I having a rss file in following :

<?xml version="1.0" encoding="UTF-8" ?>   <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">    <channel>      <title> سایپا نیوز </title>      <link>http://www.saipanews.com/</link>      <description></description>      <language>fa</language>         <item>         <author></author>         <pretitle></pretitle>         <title>پیام تبریک دکتر جمالی به مناسبت فرارسیدن سالروز ولادت حضرت علی(ع) و روز پدر</title>         <link>http://www.saipanews.com/view-6751.html</link>         <pubdate>2016-04-20 10:58:00</pubdate>         <description>سایپا نیوز: مدیرعامل گروه خودروسازی سایپا همزمان با فرارسیدن سالروز میلاد باسعادت حضرت علی(ع) و روز پدر، طی پیامی به تمامی پدران متعهد و پرتلاش ایران زمین تبریک گفت.</description>         <secid>0</secid>         <typid>8</typid>         <image>http://www.saipanews.com/media/image/jamali/jmali.JPG</image>     </item>      <item>         <author></author>         <pretitle></pretitle>         <title>فرهنگ رانندگی بین خطوط در معابر شهری در حال گسترش است </title>         <link>http://www.saipanews.com/view-6748.html</link>         <pubdate>2016-04-19 11:27:00</pubdate>         <description>سایپا نیوز: به گزارش سایپا نیوز و به نقل از فرارو، از آنجایی که فرهنگ رانندگی مجموعه ای از رفتارهای درست رانندگی و آداب زندگی اجتماعی بهنگام تردد در شهرها و جاده ها است، رانندگی در بین خطوط معابر شهری یکی از نمادهای فرهنگ رانندگی در کشورهای درحال توسعه و توسعه یافته می باشد.</description>         <secid>0</secid>         <typid>8</typid>         <image>http://www.saipanews.com/media/image/farhang%20ranandegi/252887_331.jpg</image>      </item>   </channel>  </rss> 

I want to get image's urls.
I use Rome library but not found any solution.
how to get image's url in item with Rome library ?

2 Answers

Answers 1

I for that get image tag , build new rss parser on the following:

public class NewRssParser extends RSS094Parser implements WireFeedParser {  public NewRssParser() {     this("rss_2.0"); }  protected NewRssParser(String type) {     super(type); }  protected String getRSSVersion() {     return "2.0"; }  protected boolean isHourFormat24(Element rssRoot) {     return false; }  protected Description parseItemDescription(Element rssRoot, Element eDesc) {     Description desc = super.parseItemDescription(rssRoot, eDesc);     desc.setType("text/html"); // change as per                                 // https://rome.dev.java.net/issues/show_bug.cgi?id=26     return desc; }  public boolean isMyType(Document document) {     boolean ok;     Element rssRoot = document.getRootElement();     ok = rssRoot.getName().equals("rss");     if (ok) {         ok = false;         Attribute version = rssRoot.getAttribute("version");         if (version != null) {             // At this point, as far ROME is concerned RSS 2.0, 2.00 and             // 2.0.X are all the same, so let's use startsWith for leniency.             ok = version.getValue().startsWith(getRSSVersion());         }     }     return ok; }  @Override public Item parseItem(Element arg0, Element arg1) {     Item item = super.parseItem(arg0, arg1);      Element imageElement = arg1.getChild("image", getRSSNamespace());     if (imageElement != null) {         String imageUrl = imageElement.getText();          Element urlElement = imageElement.getChild("url");         imageUrl = urlElement != null ? urlElement.getText() : imageUrl;          Enclosure enc = new Enclosure();         enc.setType("image");         enc.setUrl(imageUrl);          item.getEnclosures().add(enc);     }      return item; }  } 

in the class override parseItem method and add code for get image element and add image's url to Enclosures.

then add following line to rome.properties file :

WireFeedParser.classes=[packge name].NewRssParser

Example :

WireFeedParser.classes=ir.armansoft.newscommunity.newsgathering.parser.impl.NewRssParser

Answers 2

Rome wont provide the <image> tag because it does not belong to the namespace it is in. So the feed isn't valid:

line 18, column 3: Undefined item element: image (29 occurrences) [help]             <image>http://www.saipanews.com/media/image/%D8%AA%D9%88%D9%84%D9%8A%D8%A ... 

If the image tag would be in a different namespace, like this:

<image:image>http://www.saipanews.com/media/image/%D8%AA%D9%88%D9%84%D9%8A%D8%AF/2.jpg</image:image> 

You could get foreing markup in this way:

for(SyndEntry entry : feed.getEntries()) {     for (Element element : entry.getForeignMarkup()) {         System.out.println("element: " + element.toString());     } } 

And the result would be

element: [Element: <image:image [Namespace: http://purl.org/rss/1.0/modules/image/]/>] 

Unless the feed is fixed, It seems that there isn't a way to get the image url with Rome library at the moment.

Read More

Monday, April 18, 2016

Display an image from within an RSS Feed Asp.Net

Leave a Comment

I'm trying to display an image from an RSS Feed. At the moment I am displaying the Title, Date, and Description by using the code:

<asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1"> <ItemTemplate>     <div class="jumbotron">     <h2><%# XPath("title") %></h2><br />     <h3><%# XPath("pubDate") %></h3><br />     <h3><%# XPath("description") %></h3><br />     <a class ="btn btn-primary btn-lg" Target="_blank" href="<%# XPath("link") %>">Read More On This Story</a>         </div>     <hr /> </ItemTemplate> 

<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://feeds.bbci.co.uk/news/education/rss.xml" XPath="rss/channel/item"> 

After I add this image, I am looking to display each story within the page itself. To at the moment, it is opening up a new tab. I am looking to use possibly an iframe or a modal. Thanks in advance!

1 Answers

Answers 1

Here is a complete solution to showing images from your rss feed:

<asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1">   <ItemTemplate>   <div class="jumbotron">     <h2><%# XPath("title") %></h2>     <br />     <h3><%# XPath("pubDate") %></h3>     <br />     <h3><%# XPath("description") %></h3>     <br />     <asp:Repeater runat="server" ID="_subitemsRepeater"       EnableViewState="false"       DataSource='<%# XPathSelect("media:thumbnail", XmlNamespaceManager) %>'>       <ItemTemplate>         <img src="<%# ((System.Xml.XmlNode)Container.DataItem).Attributes["url"].Value %>" />         <br />       </ItemTemplate>       </asp:Repeater>       <br />       <a class="btn btn-primary btn-lg" target="_blank" href="<%# XPath("link") %>">Read More On This Story</a>       </div>       <hr /> </ItemTemplate> </asp:DataList> <asp:XmlDataSource ID="XmlDataSource1" runat="server"   DataFile="http://feeds.bbci.co.uk/news/education/rss.xml"   XPath="rss/channel/item" /> 

In code behind:

public partial class _Default : Page {   protected XmlNamespaceManager XmlNamespaceManager { get; set; }    protected void Page_Load(object sender, EventArgs e)   {      XmlNamespaceManager = new XmlNamespaceManager(XmlDataSource1.GetXmlDocument().NameTable);      XmlNamespaceManager.AddNamespace("media", "http://search.yahoo.com/mrss/");   }  } 

If your feed don't have multiple images you can replace repeater with a single image tag like this:

<img src="<%# XPath("media:thumbnail/@url", XmlNamespaceManager) %>" /> 
Read More

Sunday, March 13, 2016

RSS feed doesn't validate

Leave a Comment

I get this error on my default WordPress feed: pubDate must be an RFC-822 date-time: Mon, 30 Nov -0001 00:00:00 +0000

Anything inherently evil in pubDate? And if so how to solve the problem?

3 Answers

Answers 1

If you look at the two occurrences of the error from Feed Validator, it's only happening because of the oldest two posts in the feed. Every post after that has the correct pubdate specification. WordPress itself follows the specification, but those two posts are missing the year.

This answer might be of use, as it's what's occurring in your posts

There are 4 dates stored for each WP post: Post_date, post_date_gmt, post_modified and post_modified_gmt. I recommend you to insert the same date for both post_date and post_modified and see if it works.

That worked, thanks! It was just the post_date_gmt field that needed to be set.

If it's just those two, you can manually edit them in the wp_posts table in your database if you feel comfortable doing so, or there are various plugins available that can help with doing such a thing.

PSA: Always have a backup of your database before fiddling with it.

Answers 2

Upgrage your plugins with newer version here https://wordpress.org/plugins/wordpress-seo/ because there is a bug https://github.com/Yoast/wordpress-seo/issues/525

but if it has not been solve your problems, then better you remove this two post your.url/cliff-diving-boracay-philippines your.url/bora-bora-activities-snorkeling-hibiscus

or make new version of those.

Answers 3

Try this .. might work

Go into your wp-includes directory and edit the feed-rss2.php file.

Replace this (line no : 89):

<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> 

With this:

<pubDate><?php echo mysql2date('r', get_the_time('Y-m-d H:i:s')); ?></pubDate> 

And also try to update the Post for which the date is wrong : post ID = 17624 and 17637 or see the published date of these posts in edit screen

enter image description here

Read More