Parsing the Youtube API with DOM
- by Kirk
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.