Parsing the Youtube API with DOM

Posted by Kirk on Stack Overflow See other posts from Stack Overflow or by Kirk
Published on 2010-06-10T16:29:27Z Indexed on 2010/06/10 16:32 UTC
Read the original article Hit count: 254

Filed under:
|
|

I'm using the Youtube API and I can retrieve the date information without a problem, but don't know how to retrieve the description information.

My Code:

<?php
$v = "dQw4w9WgXcQ";
$url = "http://gdata.youtube.com/feeds/api/videos/". $v;
$doc = new DOMDocument;
$doc->load($url);
$pub = $doc->getElementsByTagName("published")->item(0)->nodeValue;
$desc = $doc->getElementsByTagName("media:description")->item(0)->nodeValue;
echo "<b>Video Uploaded:</b> ";
echo date( "F jS, Y", strtotime( $pub ) );
echo '<br>';
if (isset ($desc))
{
echo "<b>Description:</b> ";
echo $desc;
echo '<br>';
}
?>

Here's a link to the feed:
http://gdata.youtube.com/feeds/api/videos/dQw4w9WgXcQ?prettyprint=true

And the excerpt of code I don't know how to retrieve data from:

<media:group>
<media:description type='plain'>Music video by Rick Astley performing Never Gonna Give You Up. (C) 1987 PWL</media:description>
</media:group>

Thanks in advance.

© Stack Overflow or respective owner

Related posts about dom

Related posts about youtube-api