﻿/*
* jTube
* http://jtube.monkeecreate.com
* 
* jQuery Youtube API Feed Plugin
* 
* Developed by John Hoover <john@defvayne23.com>
* Another project from monkeeCreate <http://monkeecreate.com>
*
* Version 2.0.0 - Last updated: September 13, 2010
*/
(function ($) { $.extend({ jTube: function (j) { var j = $.extend({ request: '', requestValue: '', requestOption: '', format: 'flash', order: 'published', time: 'all_time', limit: 5, page: 1, success: function (a, b) { }, error: function (a) { } }, j); var k = 'http://gdata.youtube.com/feeds/api/'; var l = this; var m = ''; var n = new Date(); function parseISO8601(a) { var b = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" + "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" + "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"; var d = a.match(new RegExp(b)); var c = 0; var e = new Date(d[1], 0, 1); if (d[3]) { e.setMonth(d[3] - 1) } if (d[5]) { e.setDate(d[5]) } if (d[7]) { e.setHours(d[7]) } if (d[8]) { e.setMinutes(d[8]) } if (d[10]) { e.setSeconds(d[10]) } if (d[12]) { e.setMilliseconds(Number("0." + d[12]) * 1000) } if (d[14]) { c = (Number(d[16]) * 60) + Number(d[17]); c *= ((d[15] == '-') ? 1 : -1) } c -= e.getTimezoneOffset(); time = (Number(e) + (c * 60 * 1000)); return new Date(Number(time)) } if (j.request == 'user') { if (j.requestOption == "profile") { k += 'users/' + j.requestValue + '?' } else { if (j.requestOption == '') { j.error("Request option for 'users' was not passed.") } else { k += 'users/' + j.requestValue + '/' + j.requestOption + '?' } } } else if (j.request == 'search') { k += 'videos?q=' + j.requestValue + '&' } else if (j.request == 'feed') { k += 'standardfeeds/' + j.requestValue + '?' } else if (j.request == 'playlist') { k += 'playlists/' + j.requestValue + '?' } else if (j.request == 'video') { if (j.requestOption == "info") { k += 'videos/' + j.requestValue + '?' } else { if (j.requestOption == '') { j.error("Request option for 'videos' was not passed.") } else { k += 'videos/' + j.requestValue + '/' + j.requestOption + '?' } } } else { j.error('No feed choices given.'); return false } k += 'alt=json-in-script&v=2'; if ((j.request == 'user' && j.requestOption == "profile") || (j.request == 'videos' && j.requestOption == "info")) { } else { if (j.request == 'video' && (j.requestOption == 'info')) { } else { k += '&max-results=' + j.limit; k += '&start-index=' + (((j.page * j.limit) - j.limit) + 1); k += '&orderby=' + j.order } if (j.request == 'feed' && (j.requestValue == 'most_recent' || j.requestValue == 'recently_featured' || j.requestValue == 'watch_on_mobile')) { } else { k += '&time=' + j.time } if (j.format == "mpeg") { k += '&format=6' } else if (j.format == "h263") { k += '&format=1' } else { k += '&format=5' } } k += '&callback=?'; $.getJSON(k, function (b) { if (b != '' && b != null) { if (j.request == 'user' && j.requestOption == 'playlists') { var c = []; $(b.feed.entry).each(function () { var a = { id: this.yt$playlistId.$t, title: this.title.$t, summary: this.summary.$t, link: this.link[1].href, hits: this.yt$countHint.$t, published: parseISO8601(this.published.$t), updated: parseISO8601(this.updated.$t) }; c[c.length] = a }); var d = c; if (b.feed) { var e = Math.ceil(b.feed.openSearch$totalResults.$t / j.limit) } else { var e = 0 } } else if (j.request == 'user' && j.requestOption == 'subscriptions') { var f = []; $(b.feed.entry).each(function () { var a = { title: this.title.$t, username: this.yt$username.$t, link: this.link[1].href, published: parseISO8601(this.published.$t), updated: parseISO8601(this.updated.$t) }; f[f.length] = a }); var d = f; if (b.feed) { var e = Math.ceil(b.feed.openSearch$totalResults.$t / j.limit) } else { var e = 0 } } else if (j.request == 'user' && j.requestOption == 'contacts') { var g = []; $(b.feed.entry).each(function () { var a = { username: this.yt$username.$t, status: this.yt$status.$t, link: this.link[1].href, published: parseISO8601(this.published.$t), updated: parseISO8601(this.updated.$t) }; g[g.length] = a }); var d = g; if (b.feed) { var e = Math.ceil(b.feed.openSearch$totalResults.$t / j.limit) } else { var e = 0 } } else if (j.request == 'user' && j.requestOption == 'profile') { var d = { username: b.entry.yt$username.$t, thumbnail: b.entry.media$thumbnail.url, views: b.entry.yt$statistics.viewCount, uploadViews: b.entry.yt$statistics.videoWatchCount, subscribers: b.entry.yt$statistics.subscriberCount, lastLogin: parseISO8601(b.entry.yt$statistics.lastWebAccess), location: b.entry.yt$location.$t, age: b.entry.yt$age.$t, link: b.entry.link[1].href, title: b.entry.title.$t, published: parseISO8601(b.entry.published.$t), updated: parseISO8601(b.entry.updated.$t) }; if (b.entry.yt$aboutMe.$t) { d.about = b.entry.yt$aboutMe.$t } if (b.entry.yt$gender) { d.gender = b.entry.yt$gender.$t } var e = 0 } else if (j.request == 'video' && j.requestOption == 'comments') { var h = []; $(b.feed.entry).each(function () { var a = { author: this.author[0].name.$t, comment: this.content.$t, published: parseISO8601(this.published.$t), updated: parseISO8601(this.updated.$t) }; h[h.length] = a }); var d = h; if (b.feed) { var e = Math.ceil(b.feed.openSearch$totalResults.$t / j.limit) } else { var e = 0 } } else { var i = []; if (j.request == 'video' && j.requestOption == 'info') { entry = b.entry } else { entry = b.feed.entry } $(entry).each(function () { var a = { id: this.media$group.yt$videoid.$t, title: this.media$group.media$title.$t, description: this.media$group.media$description.$t, category: this.media$group.media$category[0].label, keywords: this.media$group.media$keywords.$t, link: this.link[0].href, author: { name: this.author[0].name.$t, link: this.author[0].uri.$t} }; if (this.media$group.yt$aspectRatio) { a.aspect = this.media$group.yt$aspectRatio.$t } if (this.yt$statistics) { a.views = this.yt$statistics.viewCount; a.favorites = this.yt$statistics.favoriteCount } if (this.gd$comments) { a.comments = this.gd$comments.gd$feedLink.countHint } if (this.gd$rating) { a.rating = this.gd$rating.average; a.raters = this.gd$rating.numRaters } if (this.yt$rating) { a.likes = this.yt$rating.numLikes; a.dislikes = this.yt$rating.numDisLikes } if (this.media$group.media$thumbnail) { a.thumbnail = this.media$group.media$thumbnail[3].url } videoFormats = []; $(this.media$group.media$content).each(function () { videoFormats[this.yt$format] = this.url }); if (j.format == "mpeg") { a.video = videoFormats[6] } else if (j.format == "h263") { a.video = videoFormats[1] } else { a.video = videoFormats[5] } if (this.published) { a.published = parseISO8601(this.published.$t) } if (this.published) { a.updated = parseISO8601(this.updated.$t) } if (this.media$group.yt$duration) { duration = this.media$group.yt$duration.seconds; hours = 0; minutes = 0; seconds = 0; while (duration >= 3600) { hours = hours + 1; duration = duration - 3600 } while (duration >= 60) { minutes = minutes + 1; duration = duration - 60 } seconds = duration; if (seconds < 10) { seconds = '0' + seconds } a.length = minutes + ':' + seconds; if (hours > 0) { a.length = hours + ':' + a.length } } i[i.length] = a }); if (j.request == 'video' && j.requestOption == 'info') { d = i[0]; var e = 0 } else { d = i; if (b.feed.openSearch$totalResults) { var e = Math.ceil(b.feed.openSearch$totalResults.$t / j.limit) } else { var e = 0 } } } j.success(d, e) } else { j.error("Bad request.") } }); return this }, jTubeEmbed: function (a, b) { var b = $.extend({ width: 560, height: 340, autoplay: false, fullscreen: false, related: true, loop: false, keyboard: true, genie: false, border: false, highdef: true, start: 0 }, b); var c = a + "&"; c += 'autoplay=' + (b.autoplay ? 1 : 0); c += '&fs=' + (b.fullscreen ? 1 : 0); c += '&rl=1' + (b.related ? 1 : 0); c += '&loop=1' + (b.loop ? 1 : 0); c += '&disablekb=0' + (b.keyboard ? 0 : 1); c += '&egm=1' + (b.genie ? 1 : 0); c += '&border=1' + (b.border ? 1 : 0); c += '&hd=1' + (b.highdef ? 1 : 0); c += '&start=' + b.start; var d = '<object width="' + b.width + '" height="' + b.height + '">'; d += '<param name="movie" value="' + c + '"</param>'; d += '<param name="allowScriptAccess" value="always"></param>'; if (b.fullscreen == true) { d += '<param name="allowFullScreen" value="true"></param>' } d += '<embed src="' + c + '"'; d += '    type="application/x-shockwave-flash"'; if (b.fullscreen == true) { d += '    allowfullscreen="true"' } d += '    allowscriptaccess="always"'; d += '    width="' + b.width + '" height="' + b.height + '">'; d += '    </embed>'; d += '</object>'; return d } }) })(jQuery);
