I usually write a blurb here about why I created this and what its useful for, but this time I'm just going to keep it simple.
<script type='text/javascript' src='{your_path_to}/jQuery.jQTubeUtil.js'></script>
<script type="text/javascript">
jQTubeUtil.init({
key: "[insert your key here]",
orderby: "viewCount", // *optional -- "viewCount" is set by default
time: "this_month", // *optional -- "this_month" is set by default
maxResults: 10 // *optional -- defined as 10 results by default
});
</script>
jQTubeUtil.search("[keywords]", callbackFunction); // basic: just specify the callback function jQTubeUtil.search(parametersObject, callbackFunction); // advanced: fine tune the search
jQTubeUtil.mostViewed(callbackFunction); // basic: just specify the callback function jQTubeUtil.mostViewed(parametersObject, callbackFunction); // advanced: fine tune the search jQTubeUtil.mostRecent(callbackFunction); // basic: just specify the callback function jQTubeUtil.mostRecent(parametersObject, callbackFunction); // advanced: fine tune the search jQTubeUtil.mostPopular(callbackFunction); // basic: just specify the callback function jQTubeUtil.mostPopular(parametersObject, callbackFunction); // advanced: fine tune the search jQTubeUtil.topRated(callbackFunction); // basic: just specify the callback function jQTubeUtil.topRated(parametersObject, callbackFunction); // advanced: fine tune the search jQTubeUtil.topFavs(callbackFunction); // basic: just specify the callback function jQTubeUtil.topFavs(parametersObject, callbackFunction); // advanced: fine tune the search
jQTubeUtil.video(videoId, callbackFunction);
jQTubeUtil.suggest("[keywords]", callbackFunction);
callbackFunction = function(response){ var html = ""; for(vid in response.videos){ var video = response.videos[vid]; html += "Video : " + video.title; } alert(html); }
callbackFunction = function(response){ var html = ""; var vid = response.videos[0]; html = "Video : " + vid.title; alert(html); }
callbackFunction = function(response){ var html = ""; for(sug in response.suggestions){ var suggestion = response.suggestions[sug]; html += "Suggested : " + } alert(html); }
The Free Text search can be simply passed a string argument, and it'll use the defaults when the jQTubeUtil was initialized. If, however, you want to specify more details in a specific search you can pass an object, and pass the string in as a parameter, "q".
The additional parameters you can override, are "time", "orderby" and "max-results". To simplify the selecting of time and orderby, the jQTubeUtil utility provides public getters - getTimes() and getOrders(). All you need to do is select which item of that you want, and pass it with the parametersObject. Max-results is a number and defines the max number of videos you want in the response.
parametersObject = {
"q": "search query",
"time": jQTubeUtil.getTimes()[pick an index],
"orderby": jQTubeUtil.getOrders()[pick an index],
"max-results": 20
}
The three parameters you can override are "time", "orderby" and "max-results". Again, as detailed above, use jQTubeUtil's public getter methods for time.
parametersObject = {
"time": jQTubeUtil.getTimes()[pick an index],
"orderby": jQTubeUtil.getOrders()[pick an index],
"max-results": 20
}
var SearchDefaults = { "q": "", "orderby": jQTubeUtil.getOrders()[2], "time": jQTubeUtil.getTimes()[3], "max-results": 10 });
var CoreDefaults = { "key": "<the key that you pass in>", "format": 5, "alt": "json", "callback": "?" });
var SuggestDefaults = { "hl": "en", "ds": "yt", "client": "youtube", "hjson": "t", "cp": 1 });
The jQTubeUtil's aim is to simplify searching YouTube. There are parameters that the YouTube API specifies and requires as options for particular request params. The two parameters that jQTubeUtil currently support retrieving the options out of, are "orderby" and "time". In an effort to simplify the selection process, the utility provides public getters to retrieve them so you can select an option.
jQTubeUtil.getOrders() = ["relevance", "published", "viewCount", "rating"];
jQTubeUtil.getTimes() = ["today","this_week","this_month","all_time"],
The jQTubeUtil object is a singleton. It has methods that you can use by passing callbacks along with params (if any).
jQTubeUtil.init({
key: "my key",
orderby: jQTubeUtil.getOrders()[#],
time: jQTubeUtil.getTimes()[#],
maxResults: #,
lang: "en"
});
jQTubeUtil.search("family guy",function(response){ /* The response */ });
jQTubeUtil.search({
"q": "family guy",
"time": jQTubeUtil.getTimes()[#],
"orderby": jQTubeUtil.getOrders()[#],
"max-results": 25
},function(response){
/* The response */
});
jQTubeUtil.video("videoId",function(response){ /* The response object */ });
jQTubeUtil.suggest("family guy", function(response){ /* response = { suggestions:[], searchURL: String } */ });
jQTubeUtil.search(jQuery('[name=free_text_1]').val(), function(response){ var html = ""; for(v in response.videos){ var video = response.videos[v]; // this is a 'friendly' YouTubeVideo object html += (parseInt(v)+1) + " : " + video.title + " <br/>"; } jQuery("#basic_search_response_itemsPerPage").html(response.itemsPerPage); jQuery("#basic_search_response_searchURL").html(response.searchURL); jQuery("#basic_search_response_startIndex").html(response.startIndex); jQuery("#basic_search_response_totalResults").html(response.totalResults); jQuery("#basic_search_response_version").html(response.version); jQuery("#basic_search_response").html(html); });
jQTubeUtil[jQuery('[name=feed_selector] option:selected').val()](function(response){ var html = ""; for(v in response.videos){ var video = response.videos[s]; // this is a 'friendly' YouTubeVideo object html += (parseInt(v)+1) + " : " + video.title + " <br/>"; } jQuery("#feed_search_response_itemsPerPage").html(response.itemsPerPage); jQuery("#feed_search_response_searchURL").html(response.searchURL); jQuery("#feed_search_response_startIndex").html(response.startIndex); jQuery("#feed_search_response_totalResults").html(response.totalResults); jQuery("#feed_search_response_version").html(response.version); jQuery("#feed_search_response").html(html); });
jQTubeUtil.video("videoId", function(response){ var html = ""; var video = response.videos[0]; // this is a 'friendly' YouTubeVideo object html = /* personal show object function */; jQuery("#video_fetch_response").html(html); });
jQuery('[name=suggest_search_1]').keyup(function(){ jQTubeUtil.suggest($(this).val(), function(response){ var html = ""; for(s in response.suggestions){ var sug = response.suggestions[s]; html += (parseInt(s)+1) + " : " + sug + " <br/>"; } jQuery("#suggest_search_response_url").html(response.searchURL); jQuery("#suggest_search_response_length").html(response.suggestions.length); jQuery("#suggest_search_response").html(html); }); });
Next up..
» Regional search
» All Feeds
v0.9.0 - Sept 11, 2010
jQuery 1.3.2+
As long as you have a Developer Key you should be all set.
Nirvana Tikku, Tikku.com © 2010-2012