Skip to content

Instantly share code, notes, and snippets.

@serkanyersen
Created April 25, 2014 00:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serkanyersen/11274368 to your computer and use it in GitHub Desktop.
Save serkanyersen/11274368 to your computer and use it in GitHub Desktop.
reads all the annotations from google developers youtube channel and extracts goo.gl links
// 1. load up youtube.com
// 2. open console and run this code
var jq = document.createElement('script');
jq.src = "https://code.jquery.com/jquery-latest.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// After that code has run, copy paste the following code and check results in console.
// Don't forget to add your own API key there
$(function() {
var url = 'https://gdata.youtube.com/feeds/users/googledevelopers/uploads';
$.ajax({
url: url,
dataType: "jsonp",
crossDomain: true,
data: {
'alt': 'json',
'start-index': 1, // increase this number after each request, 50, 100, 150, 200, 250 and so on.
'max-results': 50 // can only get max of 50, don't change this.
},
success: function(res) {
$.each(res.feed.entry, function() {
var a = 'http://gdata.youtube.com/feeds/videos/';
var b = 'https://www.youtube.com/annotations_invideo?features=1&legacy=1&video_id=';
var annotations = this.id.$t.replace(a, b);
$.ajax({
url: annotations,
success: function(res, status, xhr) {
var m = xhr.responseText.match(/(goo\.gl\/[\w\W]{6})[\"\\<\s]/gim);
$.each(m || [], function() {
var link = this.toString().replace('"', '').replace('<', '').replace(/\s+/g, '');
var u = 'https://www.googleapis.com/urlshortener/v1/url/';
$.ajax({
url: u,
dataType: "jsonp",
crossDomain: true,
data: {
'projection': 'FULL',
'key': 'API_KEY_HERE', // put your own API key here, othervise this won't work
'shortUrl': 'http://' + link
},
success: function(res) {
if (res.analytics) {
console.log(link, ' -- ', res.analytics.allTime.shortUrlClicks);
} else {
console.log(link, res);
}
}
});
});
}
});
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment