Media RSS

Topics: ASP.NET 2.0, Controls
Apr 1, 2009 at 9:04 PM
Hye guys,

Is there any way to implement media RSS in blogengine code. Can anyone guide me through the procedure? I have implemented media RSS tage like
<media:thumbnail> and <media:group> tags using

eg 

writer.WriteElementString(

"media","thumbnail","http://search.yahoo.com/mrss/",content);...for thumbnail tag

but i want all the media elements to come under media group tag how do i do it? i get the media:group tag but separately.
also my output on XML page of RSS has the thumbnail tag displayed as 
 <media:thumbnail><img src="http://localhost:1674/BlogEngine.Web/image.axd?picture=2009%2f4%2fmovies1.jpg" alt="" /></media:thumbnail>
where as it should be < url =.....>


In my project i am only uploading an image through posts no text. so is there any image tag for media RSS or should i pass it in content tag??? please elaborate. I am new to programming and RSS both.


Thanx

Bacca.

 

Apr 1, 2009 at 9:13 PM
Just to elaborate what exactly i ma trying to:

using the add entry page i will only upload an image which will be my post on RSS feed page. i have disabled the text input area for HTML editor. Now i want the image that i upload to be uploaded using media RSS so image shoudl go as media RSS element.When the image is added to the RSS feed it need to be its own element in the Schema. The Media RSS specification is perfect for this.So how do i do this.?

Bacca
Coordinator
Apr 2, 2009 at 7:30 AM
Regarding outputting the correct markup in the RSS feed, here's how I think it should be done (based on how the other markup is outputted).

I should say that I haven't used the RSS media tags, but found information on it here.  According to this site, the <media:group> tag is "useful for more complex publishing setups".  I'm not sure if you need an advanced tag such as <media:group> based on the examples they give.

In SyndicationGenerator.cs, there's a SupportedNamespaces property where a bunch of namespaces are registered.  If you use the namespace listed at that reference above, then you would want to add it like this inside the "SupportedNamespaces" property:

xmlNamespaces.Add("media", "http://search.yahoo.com/mrss/");

Then, towards the end of the WriteRssItem() method, I added this code before the closing </item> element is written:

string mediaNamespace = "http://search.yahoo.com/mrss/";

// Open <media:content>
writer.WriteStartElement("media", "content", mediaNamespace);

writer.WriteStartElement("media", "thumbnail", mediaNamespace);
writer.WriteAttributeString("url", "http://www.example.com/");
writer.WriteEndElement();  // close <media:thumbnail>

// Close <media:content>
writer.WriteEndElement();


//------------------------------------------------------------
//    Write </item> element
//------------------------------------------------------------
writer.WriteEndElement();

**** The new stuff is bolded.  This produced the following snippet in the RSS feed:

<item>
  <title>some title</title>
  <description>...</description>
  ...... snipped ......
  <media:content>
    <media:thumbnail url="http://www.example.com/" />
  </media:content>
</item>

You might want to add something similar for the Atom feed (BE supports both an RSS feed and an Atom feed).

I obviously didn't put a real thumbnail URL in there.  That's a different issue ... just wanted to tackle this one problem.
Apr 2, 2009 at 2:34 PM
Edited Apr 2, 2009 at 3:19 PM

Hye Ben,

Is it wrong to add the media tag near opening on Item element.
Also right now the image is comming throug the description tag, is that right way of doing it?

When the image is added to the RSS feed it needs to be its own element in the Schema. Is this statement supported in the code that I/we  have put in???

This is what i understand about above statement .....i am uploading only images through add_entry page which will be displayed as posts (thats what i want to do) and i want the images to come in through media elements. i think now they are comming thru description tag as content. how do i modify code to get this done?

As i wrote the thing in following manner 

 / Modify post content to make references absolute   

//-----------------------------------------------------------   

string content = ConvertPathsToAbsolute(arg.Body);    

if (comment != null) content = content.Replace(Environment.NewLine, "<br />");

 

writer.WriteStartElement(

"item");  

//---------------------------  

// Write required channel item elements 

//------------------------------------------------------------ 

writer.WriteElementString("media","title", "http://search.yahoo.com/mrss/", publishable.Title);

writer.WriteElementString(

"description",content);

writer.WriteElementString(

"media","group","http://search.yahoo.com/mrss/",content);

writer.WriteElementString("media","thumbnail","http://search.yahoo.com/mrss/",content);
writer.WriteElementString("media","link","http://search.yahoo.com/mrss/", Utils.ConvertToAbsolute(publishable.RelativeLink).ToString());

Sorry I am bothering you but i really need some1 to guide me as i am kind of stuck. I really appreciate your quick an accurate replies.

Apr 2, 2009 at 4:49 PM
Also can u tell me what url should i point the image to? the images are getting stored in this path  folder BlogEngine.Web\App_Data\files\2009\3. Sorry this question might sound really silly but still asking as i ma not able to figure it out.

Thanx
Coordinator
Apr 2, 2009 at 8:09 PM
You can have the <media:content> element near the opening Item element.  That was just an example I had.

When you upload an image on the Add Entry tab, it goes into the App_Data\files folder.  The publically accessible URL to those images are URLs like:

http://localhost:1674/BlogEngine.Web/image.axd?picture=2009%2f4%2fmovies1.jpg

That URL above was when you were running the blog on your localhost.  Once the blog is on a public server, the URLs will look something like:

http://www.example.com/image.axd?picture=2009%2f4%2fmovies1.jpg

All that's needed is to extract those URLs from Post.Content -- and to remove the <img> tags from Post.Content so the images only show up in the <media:thumbnail> elements.

Here's what my latest code in WriteRssItem() looks like.  The bolded code is new and starts a little after the "content" variable is declared.  Please note that the opening <item> tag is in the middle of the code.

string content = ConvertPathsToAbsolute(arg.Body);

if (comment != null)
    content = content.Replace(Environment.NewLine, "<br />");

string imageRegex = "<img.*?src=\"(.*?)\".*?\\/>";

// Get all <img> tags out of content
MatchCollection images = Regex.Matches(content, imageRegex);

// Remove <img> tags out of content
content = Regex.Replace(content, imageRegex, string.Empty);

writer.WriteStartElement("item");

if (images.Count > 0)
{
    string mediaNamespace = "http://search.yahoo.com/mrss/";

    // Open <media:content>
    writer.WriteStartElement("media", "content", mediaNamespace);

    // Create a <media:thumbnail> element for each image.
    // The actual "SRC" of the image is in the
    // 2nd group (match.Groups[1].Value)
    foreach (Match match in images)
    {
        writer.WriteStartElement("media", "thumbnail", mediaNamespace);
        writer.WriteAttributeString("url", match.Groups[1].Value);
        writer.WriteEndElement();  // close <media:thumbnail>
    }

    // Close <media:content>
    writer.WriteEndElement();
}

***** This code will extract all the <img> tags in your post.  If there's more than one <img> tag, then there will be multiple <media:thumbnail> tags.  Here's what the RSS will look like (this example has two thumbnail tags):

<item>
  <media:content>
    <media:thumbnail url="http://localhost/blog/image.axd?picture=2009%2f4%2fimage1.png" />
    <media:thumbnail url="http://localhost/blog/image.axd?picture=2009%2f4%2fimage2.png" />
  </media:content>
  <title>test 1</title>
  ........ snipped ........
</item>
Apr 2, 2009 at 8:59 PM
Edited Apr 2, 2009 at 9:20 PM

Hey Ben ,

Thanks for your answer.

Butwhen i implement this code, i dont see my uploaded image anywhere on Feeds page as the code is striping the image. i want the image to be displayed as well.

Only type of data i will have in my post is images which will come in the feeds and when they will go on devices they will e displayed as advertisement with time intervals. SO i want those images to come in by a media RSS tag, i belive right now they are comming in through description tag via  this statement writer.WriteElementString("description",content);

So i want them to come as media RSS elements.

I want somethign like this
<item>
<title>
FeedForAll's Show Tunes and Song</title>
<link>http://www.feedforall.com/songs.htm</link>
<description>FeedForAll cool show tunes and lyrics. </description>
<media:group>
<media:content url=        (IF I AM NOT WRONG HERE I WANT MY IMAGES TO COME IN)     "http://www.feedorall.com/sample.mp3" fileSize="122345" type="audio/mpeg" isDefault="true" expression="sample" bitrate="128" framerate="24" duration="98" height="220" width="300" />

BELOW TAGS ARE NOT REQUIRED...THIS IS JUST AN EXAMPLE


<media:adult> false </media:adult>
<media:title>
FeedForAll file sample </media:title>
<media:hash> dfdec888b72151965a34b4b59031290a </media:hash>
<media:player
url="http://www.feedforall.com/player" height="220" width="300" />
<media:credit role="author">
J Housley </media:credit>
<media:text type="plain">
FeedForAll supports name space extentions, specifically Yahoo's media RSS </media:text>
</media:group>
</item>


SO I WANT MY XML PAGE TO LOOK LIKE PROFESSIONAL MEDIA RSS PAGE. At this point of time lets not think about thumbnail. I just want the image to come in by media RSS element.

Also i wanted to ask where is the XML schema for RSS feed page located?? Like if anyone asks me to show my RSS schema what part should i show?



Thanks a lot Ben and sooooooooooooorrry for bothering you so much.

 

 

 

Coordinator
Apr 2, 2009 at 9:13 PM
So, you want the Image to continue to be in the <description> tag?  And you don't want a <media:thumbnail> tag?  Where is the MP3 file coming from?  When you create the post, are you uploading the MP3 file, or are you including a reference to the MP3 file in the post somewhere?  Do you have both an Image and an MP3 file for each post -- or just one of them?
Apr 2, 2009 at 9:29 PM
Well i want the image to come in through media tag not through description tag. It would be good to have thumbnail tag also would be good if possible. So if possible i want both image and thumbnail tag. Lemme ask you Can a image come in through media tag  in the same way as the mp3 file that i showed in example.( so its like normal uploaded image instead of a video)?? i want that to happen. If not possible then let it come through description tag and i would also want thumbnail tag if possible( desirable but optional).

About the Mp3 file... there is No mp3 file. Image is the only type of Data i have.

How it works is: I upload the image through add_entry page. the image will go to RSS feeds as posts. There is a device we have where this feeds data will go and then teh images would show up with start and end time as advertisements.

Bacca
 Thanx
Coordinator
Apr 2, 2009 at 9:38 PM
If you don't have a media file (MP3, MPG, SWF, etc), then are you sure you can use any of the RSS media tags?

Looking at the examples on that page, it appears the purpose of the media tags is for high-end media -- not simple JPGs, PNGs or GIFs.  The media tags are for playing/streaming videos.  The examples they have include attributes for fileSze, type, duration, etc.  Even your example has <media:player> etc.  But you don't have any media.  Unless you have something else in mind?
Apr 2, 2009 at 9:51 PM
Edited Apr 2, 2009 at 10:23 PM
yeah thats true...how bout if we have the thumbnail to come in thru media tag?? keeping the image to come in thru description tag. Is that possible?? With the code you gave me earlier the image was getting stripped so no image was being displayed on RSS feeds. So is it possible to have image and thumbnail both functionalities?? i mean getting the <media:thumbnail> in  the <media:content> tag?

Also when i have both of them. the image will be displayed in RSS feeds. But where will the thumbnail be displayed??? where can i see the thumbnail??

Just for reference : I found this where they have used image in media tag. But his is really basic... :(

The <Media> tag is an optional top-level tag that can specify properties of the media being generated - properties like the frame rate, native size, background color or compression settings. The next example shows a <Media> tag specifying a native size of 400 x 300 against a blue background:

<Media width="400" height="300" color="#0000ff">

  <Image src="image.png"/>

</Media>

Most of the attributes available on the <Media> tag map into the {Media.*} special variables.

Coordinator
Apr 2, 2009 at 10:05 PM
Edited Apr 2, 2009 at 10:06 PM
In the code I posted a little earlier today, if you remove the part below, then the <img> will continue to be in the <description> tag.  The image will also be in the <media:thumbnail> element too (if you use that code I posted earlier today).

// Remove <img> tags out of content
content = Regex.Replace(content, imageRegex, string.Empty);

I'm not familiar with the RSS media tags, however, I'm pretty sure you would need an RSS reader that is "RSS media tag AWARE" to see the <media> tags and child elements.  Probably most RSS readers don't support (basically ignore) the RSS media tags.  Some do probably support it though.  I'm not sure which ones.

----

Regarding that link you posted with the <Media> tag.  That <Media> tag is a proprietary <Media> tag for that person's product.  It's funny, because a few years ago, I was looking at his product.  But his "Turbine" product uses proprietary "Turbine Media Markup Language" or MML.  This is NOT the same thing as the standard RSS media tags we've been talking about and the rest of the world is aware of.
Coordinator
Apr 2, 2009 at 10:41 PM
Incidentally, you can still use the <media:thumbnail> tags, however I'm not sure if RSS Media is intended for there to be a thumbnail without an actual media resource (MP3, MPG, SWF, etc).  My guess is that it's designed so you have a main video and the thumbnail is a thumbnail image of that video.  Without a video (or some other media), the thumbnail is sort of stranded.

Just a thought ...
Apr 2, 2009 at 10:49 PM
Hye Ben ,

I really agree with what you are saying as i have searched lot of material on this RSS media and i cudnt find a single instance where an image is used thru media tag....everywhere there is a audio or a video and then a supporting thumbnail image for that audio/video.

But the i have been told toi implement wht i was discussing with you.

The statement mentioned to me by my user said:

When the image is added to the RSS feed it need to be its own element in the Schema. The Media RSS specification is perfect for this.

so what i assumed from that statement that i discussed with you. But let me know what you understand from above statement.

Thanks a lot.
Apr 2, 2009 at 10:51 PM
Also please letme know when somebody does ask me to show the XML schema for the RSS feeds page in blogengine.net, what do i show?? As i didnto find any xsd files in the solutions.

OR if i have to implement start/end time for the postd to show using dublin core elements in my XML schema how do i do it???
Coordinator
Apr 2, 2009 at 11:07 PM
According to this link, there is an <image> element for an RSS feed.  The <image> element would go into each <item>.  So it doesn't involve using RSS media.

You could output the <image> tag in the RSS feed like this (using the same basic code as before):

string content = ConvertPathsToAbsolute(arg.Body);

if (comment != null)
    content = content.Replace(Environment.NewLine, "<br />");

string imageRegex = "<img.*?src=\"(.*?)\".*?\\/>";

// Get all <img> tags out of content
MatchCollection images = Regex.Matches(content, imageRegex);

// Remove <img> tags out of content
content = Regex.Replace(content, imageRegex, string.Empty);


writer.WriteStartElement("item");

if (images.Count > 0)
{
    writer.WriteElementString("image", images[0].Groups[1].Value);
}


**** I'm not sure if all RSS readers will recognize and display the <image> tag.  The image does NOT show up when viewing the RSS feed in IE and Firefox.  It may show up in some other RSS readers, however.