Skip to content

Instantly share code, notes, and snippets.

@vineyy
Forked from adammw/how_much_netflix.js
Last active September 14, 2017 20:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vineyy/6c25e8013feda5833134 to your computer and use it in GitHub Desktop.
Save vineyy/6c25e8013feda5833134 to your computer and use it in GitHub Desktop.
// how_much_netflix.js
// A script that looks through your Netflix viewing activity and
// tallys up how much time you've spent watching Netflix
//
// INSTRUCTIONS TO USE:
// Open https://www.netflix.com/WiViewingActivity and the developer console
// Copy and paste this script into the developer console and press enter
//
(function() {
var fetchAllViewedItems = function() {
var deferred = jQuery.Deferred();
var viewedItems = [];
(function fetchPage(page) {
var api = netflix.contextData.services.data.api;
var path = api.protocol + '://' + api.hostname + '/' + api.path.join('/');
jQuery.getJSON(path + '/viewingactivity?pg=' + page).done(function(json) {
viewedItems = viewedItems.concat(json.viewedItems);
console.log('Fetched %s viewed items', viewedItems.length);
if (json.viewedItems.length == json.size) {
fetchPage(++page);
} else {
deferred.resolve(viewedItems);
}
}).fail(deferred.reject);
})(0);
return deferred.promise();
};
fetchAllViewedItems().then(function(viewedItems) {
var totalTime = viewedItems.reduce(function(runningTotal, viewedItem) {
return runningTotal + viewedItem.bookmark;
}, 0);
var days = Math.floor(totalTime / 60 / 60 / 24);
var hours = Math.floor((totalTime / 60 / 60) % 24);
var minutes = Math.round((totalTime / 60) % 60);
console.log('According to your viewing history, you have cumulatively watched %i days, %i hours and %i minutes of Netflix', days, hours, minutes);
});
})();
@JefStat
Copy link

JefStat commented Mar 6, 2016

Well done, now I just need to get some aggregated stats of how much watched per month, per year, avg per month avg per year.

@sander110419
Copy link

I tried it and I couldn't get it to work with a page not found error.
I dug a little deeper and found that if I checked the ID myself en use the old code it worked.

My ID was: fd272551 which I got from the source (http://i.imgur.com/eKS0NiV.png)

so using the following code I got it to work:

// how_much_netflix.js // A script that looks through your Netflix viewing activity and // tallys up how much time you've spent watching Netflix // // INSTRUCTIONS TO USE: // Open https://www.netflix.com/WiViewingActivity and the developer console // Copy and paste this script into the developer console and press enter // (function() { var fetchAllViewedItems = function() { var deferred = jQuery.Deferred(); var viewedItems = []; (function fetchPage(page) { jQuery.getJSON('https://www.netflix.com/api/shakti/fd272551/viewingactivity?pg=' + page).done(function(json) { viewedItems = viewedItems.concat(json.viewedItems); console.log('Fetched %s viewed items', viewedItems.length); if (json.viewedItems.length == json.size) { fetchPage(++page); } else { deferred.resolve(viewedItems); } }).fail(deferred.reject); })(0); return deferred.promise(); }; fetchAllViewedItems().then(function(viewedItems) { var totalTime = viewedItems.reduce(function(runningTotal, viewedItem) { return runningTotal + viewedItem.bookmark; }, 0); var days = Math.floor(totalTime / 60 / 60 / 24); var hours = Math.floor((totalTime / 60 / 60) % 24); var minutes = Math.round((totalTime / 60) % 60); console.log('According to your viewing history, you have cumulatively watched %i days, %i hours and %i minutes of Netflix', days, hours, minutes); }); })();

@joba12
Copy link

joba12 commented Jan 19, 2017

Hey, the variable with the API key is not available anymore
netflix.contextData.services.data.api
Uncaught TypeError: Cannot read property 'services' of undefined
at :1:20

how to get the correct api key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment