Most recent:
http://gdata.youtube.com/feeds/api/standardfeeds/most_recent
etc.
You can cache the requested data. Optional tag's attribute ttl describes a caching time in seconds. So all the subsequent requests (it is an application level
cache) for the same url will be served right from cache.
Now you can loop over the requested data and do some processing.
Tag ForEachVide iterates over the requested data. On the each loop's step you can access to the page scope variable
described in the parameter video. This variable describes one entry in YouTube data feed.
The following code demonstrates access to the various attributes of video entries:
<y:ForEachVideo data="A" id="vb">
<p><b>Id: <%=vb.getId()%></b>
<br>Published: <%=vb.getPublished()%>
<br>Updated: <%=vb.getUpdated()%>
<br>Recorded: <%=vb.getRecorded()%>
<br>Location: <%=vb.getLocation()%>
<br>Geo Data: <%=vb.getPoint().getLatitude()%> <%=vb.getPoint().getLongitude()%>
<br>Author: <%=vb.getAuthor().getName()%> <%=vb.getAuthor().getUri()%>
<br>Duration: <%=vb.getDuration()%>
<br>Statistics: <%=vb.getStatistics()%>
<br>Comments: <%=vb.getComment().getFeedLink()%> <%=vb.getComment().getCountHint()%>
<br>Title: <%=vb.getTitle()%>
<br>Content: <%=vb.getContent()%>
<br>Rating: <%=vb.getRating().getMin()%> <%=vb.getRating().getMax()%> <%=vb.getRating().getNumRaters()%> <%=vb.getRating().getAverage()%>
<br>Links:
<% for (int j=0; j<vb.getLink().size(); j++) {
com.cj.youtube.LinkBean lb = (com.cj.youtube.LinkBean)vb.getLink().elementAt(j);
%>
<br> <%=lb.getRel()%> <%=lb.getType()%> <%=lb.getHref()%>
<% } %>
<br>Categories:
<% for (int k=0; k<vb.getCategory().size(); k++) {
com.cj.youtube.CategoryBean cb = (com.cj.youtube.CategoryBean)vb.getCategory().elementAt(k);
%>
<br> <%=cb.getScheme()%> <%=cb.getLabel()%> <%=cb.getTerm()%> <%=cb.getValue()%>
<% } %>
<br>Player: <%=vb.getMedia().getPlayer()%>
<br>Media title: <%=vb.getMedia().getTitle()%>
<br>Media description: <%=vb.getMedia().getDescription()%>
<br>Media keywords: <%=vb.getMedia().getKeywords()%>
<br>Media Categories:
<% for (int l=0; l<vb.getMedia().getCategory().size(); l++) {
com.cj.youtube.CategoryBean cb = (com.cj.youtube.CategoryBean)vb.getMedia().getCategory().elementAt(l);
%>
<br> <%=cb.getScheme()%> <%=cb.getLabel()%> <%=cb.getTerm()%> <%=cb.getValue()%>
<% } %>
<br>Thumbnails:
<% for (int m=0; m<vb.getMedia().getThumbnail().size(); m++) {
com.cj.youtube.ThumbnailBean tb = (com.cj.youtube.ThumbnailBean)vb.getMedia().getThumbnail().elementAt(m);
%>
<br> <%=tb.getUrl()%> <%=tb.getWidth()%> <%=tb.getHeight()%> <%=tb.getTime()%>
<% } %>
<br>Media content:
<% for (int n=0; n<vb.getMedia().getContent().size(); n++) {
com.cj.youtube.ContentBean cb = (com.cj.youtube.ContentBean)vb.getMedia().getContent().elementAt(n);
%>
<br> <%=cb.getUrl()%> <%=cb.getType()%> <%=cb.getMedium()%> <%=cb.getIsDefault()%> <%=cb.getExpression()%> <%=cb.getDuration()%> <%=cb.getFormat()%>
<% } %>
</y:ForEachVideo>
the code above just prints all the data from YouTube feed. You can use this as example and request by the similar manner the attributes you need in your application. The names for functions are
mnemonically, so getPlayer() returns URL for the player, getTitle() returns title for the video etc.
Tags are:
YouTubeData
Tag lets you request and parse YouTube data feed. Attributes are:
1) url Describes a data feed url
2) id Describes a name for your page scope variable (type is
com.cj.youtube.FeedLink). This object will keep the requested data.
2) ttl Optional attribute. Describes a caching time for the requested data.
Without this parameter (or if its value is negative) tag does not use cache.
ForEachVideo
Body tag evaluates own body for the each entry in the given YouTube data feed. Attributes are:
1) data Describes a name for page scope variable with the parsed data feed
2) id Describes a name for your page scope variable (type is
com.cj.youtube.VideoBean). This object will keep the current entity.
2) count Optional attribute. Lets you limit the iterations in your loop.
By default the loop will iterate over the all entries in the feed.
for downloading:
Library: youtubemashtag.jar Description: taglib.tld
© Coldbeans
Comments?
See also Coldtags suite - the largest collection of custom JSP tags.