Skip to content

Instantly share code, notes, and snippets.

@adammw
Last active May 14, 2019 15:45
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save adammw/ebaceb48f8b886b83e73 to your computer and use it in GitHub Desktop.
Save adammw/ebaceb48f8b886b83e73 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) {
jQuery.getJSON('https://www.netflix.com/api/shakti/b6260b85/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);
});
})();
@goedible
Copy link

I like this idea! I tried it in CHrome on Linux mint 17.1 and got an error:
GET https://www.netflix.com/api/shakti/b6260b85/viewingactivity?pg=0 404 (Not Found)

What should I do?

@vineyy
Copy link

vineyy commented Jan 14, 2016

Updated fork here: https://gist.github.com/vineyy/6c25e8013feda5833134

The hardcoded alphanumeric part 'b6260b85' in the Netflix API changes. I don't yet know if it changes with profile and/or with location etc but it does.

There is a way to find what API can be hit to get the data. The https://www.netflix.com/WiViewingActivity page html has a JSON object defined as netflix.contextData and it has a services.data.api that tells what API can be hit. Type netflix.contextData.services.data.api on the devtool console and see yourself.

@eyeyen
Copy link

eyeyen commented Apr 8, 2016

@vineyy, I saw that updated gist and @sander110419 was instructing to concatenate the build. It's here:
https://gist.github.com/eyeyen/4d3cf27a50f1c6a770cc1e683a31c89d

You can see that specific revision here:
https://gist.github.com/eyeyen/4d3cf27a50f1c6a770cc1e683a31c89d/revisions

Cheers!

@kichimi
Copy link

kichimi commented Dec 28, 2017

I've been through all the modified scripts I can find and this is the only one that works still, Netflix change their code too much to justify any real effort in fixing the others so if you want to get this script to work, the simplest way is to open the developer console and go to the network tab, scroll down one page on the viewing history page to see what the API url should be, and correct the script.

Another thing worth noting, is that the figures it gives out are seriously inaccurate if you like to rewatch shows. Each show you watch will only appear once in that page no matter how many times you watch it.

@richja
Copy link

richja commented Apr 11, 2018

That always changing number is build identifier for Netflix API, it probably changes with every new build of their API. You can find current one in source of the page, search for BUILD_IDENTIFIER.

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