I'm trying to get, among other details, the title of a given video for a certain YouTube video. Because they're all probably rooted in the same problem, I'll just show a simplified example with just getting the title using the API. Here's what I have so far:
$.ajax({
url: "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&alt=json",
dataType: "jsonp",
success: function(data) {
videoName = data.entry.title.$t;
$('#video_name').text(videoName);
}
});
For some videos, such as this one, this works perfectly. For others, such as this one, it doesn't grab that information ever.
Why does this not work? That second example is just one video that does not work with this. About 1/3 don't work it seems.
I'd really appreciate some insight on this.
EDIT How I'm getting videoID
:
var videoID = getUrlVars()["v"];
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m,key,value) {
vars[key] = value;
});
return vars;
}
The example video ends like so: ?v=J66NOwZegc4
EDIT2 So I've added the $.ajax function with what seems to be causing the problem instead:
$.ajax({
url: "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&alt=json",
dataType: "jsonp",
async: "false",
success: function(data) {
commentCount = data.entry.gd$comments.gd$feedLink.countHint;
iterations = Math.floor(commentCount/50);
remaining = commentCount - (iterations*50);
videoDesc = data.entry.title.$t;
$('#video_name').text(videoDesc);
document.title = 'Watching "' + videoDesc + '" on YTRT';
$('#shareLink').val('http://www.ytrealtime.com?v=' + videoID);
}
});