Last active
August 29, 2015 13:57
-
-
Save lukasharing/9687807 to your computer and use it in GitHub Desktop.
Easy Youtube Js Library, new Youtube(+URLVideo)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function(){ | |
function Youtube(urlYoutube) | |
{ | |
var urlClear = urlYoutube; | |
if(urlYoutube.lastIndexOf("?v=") != -1) | |
{ | |
urlClear = urlYoutube.substring(urlYoutube.lastIndexOf("?v=") + 3); | |
if(urlClear.indexOf("&") != -1); | |
urlClear = urlClear.substring(0, urlClear.indexOf("&")); | |
} | |
url = 'http://gdata.youtube.com/feeds/api/videos/'+urlClear+'?v=2&alt=jsonc'; | |
var JsonArray = []; | |
var http_request = new XMLHttpRequest(); | |
try | |
{ | |
http_request = new XMLHttpRequest(); | |
} | |
catch (e) | |
{ | |
try | |
{ | |
http_request = new ActiveXObject("Msxml2.XMLHTTP"); | |
}catch (e) { | |
try{ | |
http_request = new ActiveXObject("Microsoft.XMLHTTP"); | |
}catch (e){ | |
alert("Too Old Browser or you are a wizzard!"); | |
return false; | |
} | |
} | |
} | |
http_request.onreadystatechange = function(){ | |
if (http_request.readyState == 4 ) | |
{ | |
var json = JSON.parse(http_request.responseText); | |
JsonArray.push(json.data.title); //YtVideo | |
JsonArray.push(json.data.uploader); //YtUserUpload | |
JsonArray.push(json.data.uploaded); //YtPublished | |
JsonArray.push(json.data.updated); //YtUpdated | |
JsonArray.push(json.data.duration); //YtDutation | |
JsonArray.push(json.data.category); //YtCategory | |
JsonArray.push(json.data.description); //description | |
JsonArray.push(json.data.thumbnail.sqDefault); //YtSmallImg | |
JsonArray.push(json.data.thumbnail.hqDefault); //YtBigImg | |
JsonArray.push(json.data.likeCount); //YtNumLikes | |
JsonArray.push(parseInt(json.data.ratingCount) - parseInt(json.data.likeCount)); // Dislikes | |
JsonArray.push(json.data.ratingCount); // TotalRate | |
JsonArray.push(json.data.viewCount); //YtViewsTotal | |
JsonArray.push(json.data.favoriteCount); //YtFavCount | |
JsonArray.push(json.data.commentCount); //YtCommentCount | |
} | |
} | |
http_request.open("GET", url, false); | |
http_request.send(); | |
this.Title = JsonArray[0]; | |
this.UserUpload = JsonArray[1]; | |
this.Uploaded = JsonArray[2]; | |
this.Updated = JsonArray[3]; | |
this.Duration = JsonArray[4]; | |
this.Category = JsonArray[5]; | |
this.Description = JsonArray[6]; | |
this.SmallThumb = JsonArray[7]; | |
this.BigThumb = JsonArray[8]; | |
this.Likes = JsonArray[9]; | |
this.Dislikes = JsonArray[10]; | |
this.TotalRate = JsonArray[11]; | |
this.Views = JsonArray[12]; | |
this.Favorites = JsonArray[13]; | |
this.NumCouments = JsonArray[14]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment