Dumbo
Dumbo

Reputation: 14142

Having a custom xml from youtube channel

I want to show say last 5 videos that I have uploaded in my youtube channel in a block in my site. I currently have this url that produces a xml file.

I dont know where should I go in youtube to customize this xml file lets say I only want it return only the last 5 videos.

Alos, it returns in entry tags some sort of html formatted stuff for the description I had written in youtube for the uploaded file. for example for one of my videos it shows like this:

<div style="color: #000000;font-family: Arial, Helvetica, sans-serif;     font-size:12px; font-size: 12px; width: 555px;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td width="140" valign="top" rowspan="2"><div style="border: 1px solid #999999; margin: 0px 10px 5px 0px;"><a href="http://www.youtube.com/watch?v=Ihy785MpH7g&amp;feature=youtube_gdata"><img alt="" src="http://i.ytimg.com/vi/Ihy785MpH7g/0.jpg"></a></div></td>
<td width="256" valign="top"><div style="font-size: 12px; font-weight: bold;"><a style="font-size: 15px; font-weight: bold;                  font-decoration: none;" href="http://www.youtube.com/watch?v=Ihy785MpH7g&amp;feature=youtube_gdata">TinyOS Tutorial #3 - Quick overview and HelloWorld application!</a>
<br></div>
<div style="font-size: 12px; margin: 3px 0px;"><span>Topics:
-Quick overview of TinyOS
-Application Structure in TinyOS
-Simple HelloWorld application
-Extending HelloWorld applications with timers</span></div></td>
<td style="font-size: 11px; line-height: 1.4em; padding-left: 20px;             padding-top: 1px;" width="146" valign="top"><div><span style="color: #666666; font-size: 11px;">From:</span>
<a href="http://www.youtube.com/channel/UCJ61QPujJj-3E113XXIpRQg">ElectronicsPubVideos</a></div>
<div><span style="color: #666666; font-size: 11px;">Views:</span>
37</div>
<div style="white-space: nowrap;text-align: left"><img style="border: 0px none; margin: 0px; padding: 0px;                    vertical-align: middle; font-size: 11px;" align="top" alt="" src="http://gdata.youtube.com/static/images/icn_star_full_11x11.gif"> <img style="border: 0px none; margin: 0px; padding: 0px;                    vertical-align: middle; font-size: 11px;" align="top" alt="" src="http://gdata.youtube.com/static/images/icn_star_full_11x11.gif"> <img style="border: 0px none; margin: 0px; padding: 0px;                    vertical-align: middle; font-size: 11px;" align="top" alt="" src="http://gdata.youtube.com/static/images/icn_star_full_11x11.gif"> <img style="border: 0px none; margin: 0px; padding: 0px;                    vertical-align: middle; font-size: 11px;" align="top" alt="" src="http://gdata.youtube.com/static/images/icn_star_full_11x11.gif"> <img style="border: 0px none; margin: 0px; padding: 0px;                    vertical-align: middle; font-size: 11px;" align="top" alt="" src="http://gdata.youtube.com/static/images/icn_star_full_11x11.gif"></div>
<div style="font-size: 11px;">1
<span style="color: #666666; font-size: 11px;">ratings</span></div></td></tr>
<tr><td><span style="color: #666666; font-size: 11px;">Time:</span>
<span style="color: #000000; font-size: 11px; font-weight: bold;">42:52</span></td>
<td style="font-size: 11px; padding-left: 20px;"><span style="color: #666666; font-size: 11px;">More in</span>
<a href="http://www.youtube.com/videos?c=28">Science &amp; Technology</a></td></tr></tbody></table></div>

What I need is just few things: Title, link, screenshot of the video(That I have selected in youtube itself) and raw description text. So that I can put them nicely in my website with my own style.

Upvotes: 0

Views: 288

Answers (1)

user1190992
user1190992

Reputation: 669

This works for me

$string = file_get_contents('https://gdata.youtube.com/feeds/api/users/USER_NAME/uploads?v=2&alt=json&max-results=5&orderby=published');

if($result = json_decode($string, true)) {
    foreach($result['feed']['entry'] as $entry) {
        echo "Title: ".$entry['title']['$t']."<br />";
        echo "Description: ".$entry['media$group']['media$description']['$t']."<br />";
        echo "Published: ".$entry['published']['$t']."<br />";
        echo "Link: ".$entry['link'][0]["href"]."<br />";
        echo "Thumb: ".$entry['media$group']['media$thumbnail'][0]['url']."<br />";
        echo "<hr />";
    }
} else{
    echo "<h1>Problem with service</h1><br />";
    echo $output;
}

Hope that helps.

Upvotes: 1

Related Questions