Youtube Thumbnails for Video module (parsing xml help)

mudanoman - July 21, 2006 - 02:52

Hello,

I would like to try to add automatic youtube thumbnailing for the video module when a user submits a youtube video. I am stuck on how to parse the thumbnail url (URL) in the XML file. Here is an example of the xml file: http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_i... . There seems like there are multiple ways to do this, but what is the most effective assuming I just want to extract just the thumbnail url from the xml file. Any help much appreciated.

TIA,

Ivan

You don't have to parse the

erdemkose - July 21, 2006 - 07:20

You don't have to parse the whole XML. Just find the position of <thumbnail_url> and </thumbnail_url>. So you can get the URL by using substr function.

<?php
$youtube_XML
= getXMLofYouTube();

$begin = strpos($youtube_XML, '<thumbnail_url>');
$end = strpos($youtube_XML, '</thumbnail_url>', $begin);

if(
$begin !== FALSE && $end !== FALSE ) {
 
// numbers may be wrong, change them if you get wrong URL.
 
$thumbnail_url = substr( $youtube_XML, $begin+15, $end-$begin-15 );
}
?>

You can also use Regular Expression. RegExp has less code but it may be slower.

<?php
if (preg_match('/<thumbnail_url>([^<]*)<\/thumbnail_url>/', getXMLofYouTube(), $matches)) {
 
$thumbnail_url = $matches[1];
}
else {
 
//no thumbnail URL
}
?>

--------------------------------------------------------------
http://erdemkose.com/

Thank you!

mudanoman - July 21, 2006 - 20:32

Thank you!

This is what i'm after!

Jboo - March 22, 2007 - 12:29

Can anyone point out how to get this to work? Where do I place the code that erdemkose has suggested?

Thanks for any help.

I am searching for this

911 - March 3, 2007 - 13:26

I am searching for this feature too. Can you please share your hack?

Also looking for this, can

teamrob - April 11, 2007 - 16:08

Also looking for this, can you please share how you did it, thanks.

 
 

Drupal is a registered trademark of Dries Buytaert.