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

Comments

erdemkose’s picture

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.


$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.


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

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

mudanoman’s picture

Thank you!

Jboo’s picture

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

Thanks for any help.

My new EasySnoozing, Nursing and BusinessEgghead websites on D7!

911’s picture

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

teamrob’s picture

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