You can create your own Youtube widgets using its API search method in ASP.Net C# code. You can pass your favorite keyword to the Youtube API search function. XmlDataSource control can be used in ASP.Net to bind the Youtube API RSS response to display the Youtube videos. ASP.Net Repeater control is the best option here to display the Youtube API search results for videos by binding the XmlDataSource with it. Initially you have to create Youtube API search method URL to retrieve the desired result from Youtube in the form RSS Feed. Use of XmlNamespaceManager is also required to read the Youtube RSS feed having media namespace that provides the syndication content about Youtube videos retrieved in the form of RSS feed response for Youtube API Search method.
You can get Youtube API Search method documentation at Google Code for Youtube API and Tools
http://code.google.com/apis/youtube/
developers_guide_protocol.html#Searching_for_Videos
Youtube API Search Method URL
http://gdata.youtube.com/feeds/api/videos
?vq=comedy&orderby=relevance&start-index=1&max-results=12
&alt=rss&format=5
Above URL is built up for Youtube API search method. Following query variables are used to retrieve the managed response of API in RSS format
vq: it specifies the search keyword for videos
orderby: it specifies the sort order. You can pass relevance, published, viewCount and rating according to your requirement.
start-index: It specifies the starting index for the matched item from the number of results found on Youtube. By Default its value is 1.
max-results: It specifies the number results to be retrieved in an API call.
alt: It specifies the format of API response. E.g.: "rss" is used here to retrieve the result as RSS feed.
format: Format parameter specifies type of video format to be retrieved in the API response. E.g.: "5" is used here to retrieve the videos in flash format that could be embedded using flash player.
ASP.Net XmlDataSource Control and Youtube API Search URL
<asp:XmlDataSource
ID="XmlDataSource1"
runat="server"
DataFile="http://gdata.youtube.com/feeds/api/videos
?vq=comedy&orderby=relevance&start-index=1
&max-results=12&alt=rss&format=5">
</asp:XmlDataSource>
ASP.Net Repeater Control Databinding with Youtube API Search Results
<asp:Repeater ID="Repeater1" runat="server" EnableViewState="false">
<ItemTemplate>
<div class="container">
<h4>
<%#XPath("media:title", xmlN) %>
</h4>
<p align="left">
<img src="<%#XPath("media:thumbnail/@url", xmlN) %>" alt="<%#XPath("media:title", xmlN) %>" hspace="10" />
<%#XPath("media:description", xmlN) %>
<br /><br />
<b>Tag(s): </b>
<%#XPath("media:keywords", xmlN)%>
<br /><br />
<b>Category(s): </b>
<%#XPath("media:category", xmlN)%>
</p>
<div class="clear">
<hr noshade="noshade" />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
C# code for Databinding with Youtube API Search Results
// public object for XmlNamespaceManager
public XmlNamespaceManager xmlN;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// XmlNamespaceManager initialized by passing the Xml Document NameTable
xmlN = new XmlNamespaceManager(XmlDataSource1.GetXmlDocument().NameTable);
xmlN.AddNamespace("media", "http://search.yahoo.com/mrss/");
// XmlNodeList generated by passing XPath expression and XmlNamespaceManager Object
XmlNodeList xmlNodes = XmlDataSource1.GetXmlDocument().SelectNodes("rss/channel/item/media:group", xmlN);
Repeater1.DataSource = xmlNodes;
Repeater1.DataBind();
}
}
Output:

Download free ASP.Net C# source code for Youtube API Search
youtube-search.zip (1.66 kb)