Jump to content

Import rss feed thumbnail problem


manlio
 Share

Recommended Posts

Hi I'm trying to show a youtube rss feed in a frontend page. I have used the MarkupLoadRSS module.

Everything works perfectly but I don't know how to retrieve video thumbnails.

$rss->load("https://url_to_my_feed");
foreach($rss as $item) { 
echo "<p>";
echo "<a href='{$item->url}'>{$item->title}</a> ";

/***Until this point everything works perfectly. The next line I just guessing with no success***/

echo "<img src='".$item->thumbnail."'>"

I tried with the last line in several different ways with no success. I don't know how to exactly call thumbnails and what I have found didn't help me.

Any help is really appreciated.

Thank you!

Link to comment
Share on other sites

Please provide more details on what exactly is not working. There's a missing semicolon on the last line, but I guess that's not the problem.

Have you set $config->debug to true? That might help if the output is just failing silently.

Does the thumbnails xml node actually exist?

I could ask more questions to find out what your problem is, but you could also provide a detailed description :)

Link to comment
Share on other sites

Thanks owzim, I was tired and wasn't quite clear, sorry :-)

My problem is that I'm not able to see the node in the xml that identifies thumbnails and I don't know how to recall them.

If I paste the feed in Firefox, it is able to retrieve thumbnails. To me seems that thumbnails are contained in the "description" node, but if I use that in my script no image appears, but only other text information.

For testing purpouse you can try this feed (or any other youtube user)

http://gdata.youtube.com/feeds/base/users/disney/uploads?orderby=updated&v=2&client=ytapi-youtube-rss-redirect&alt=rss

 

This is the first time I deal with rss feed, so I apologize for my low skill.

Thank you very much!

Link to comment
Share on other sites

The node that contains an image is not there. The images are in a blob of HTML so it's hard to get those out. If you really want to get those out you could build the url to the image your self. The easiest way I see now is:

Filter the video id out of the:

// 76UvX8EKNZ8 is the ID
<guid ispermalink='false'>
    tag:youtube.com,2008:video:76UvX8EKNZ8
</guid>

Then use that id to build the url with:

// Default image (small)
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

// high quality
http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

// medium quality
http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

// standard definition
http://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg

// max resolution
http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

Keep in mind that not all images are available so propably you'll need a loop till you have an image and use a fallback if nothing is found.

Second way:

A second way I see is to search the <description> with PHP DOMDocument.

  • Like 3
Link to comment
Share on other sites

Thanks for replies!

This links is perfect!

http://gdata.youtube.com/feeds/api/users/disney/uploads?orderby=updated&v=2&client=ytapi-youtube-rss-redirect&alt=rss

But still I have a doubt. How can I access <media:thumbnail> through my php script

Obviously, something like 

echo "<img src='".$item->media:thumbnail."'>";

will not work.

Any ideas?

Link to comment
Share on other sites

Looking into it further, this isn't supported in MarkupLoadRSS.

It would be possible to extend it to do this, or you could consider some alternatives, like Martijn's approach above, or use Simplepie which is awesome :)

http://simplepie.org/wiki/tutorial/how_do_i_get_a_thumbnail_from_a_youtube_feed

http://simplepie.org/wiki/addons/youtube

  • Like 1
Link to comment
Share on other sites

Finally, thanks to various advices I found that for me the easiest way to accomplish this was to use MarkupLoadRSS module and retrieve the youtube ID from the link.

I post here the code for future reference:

$rss = $modules->get("MarkupLoadRSS");
$rss->load("https://url_to_my_feed");

foreach($rss as $item) { 
$url = $item->link; // link to youtube video provided by MarkupLoadRSS
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array ); //create a array with values contained in the URL
$youtubeID= $my_array['v']; //$youtubeID is the youtube ID

echo "<img src='http://i.ytimg.com/vi/".$youtubeID."/mqdefault.jpg' alt='".$item->title."'/>";// img url reconstruction
}//foreach end
  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...