-
-
Save nextrevision/6e31a80c787f2b4f5b1738a401751513 to your computer and use it in GitHub Desktop.
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
// 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) { | |
data = netflix.reactContext.models.serverDefs.data; | |
url = data.SHAKTI_API_ROOT + '/' + data.BUILD_IDENTIFIER; | |
jQuery.getJSON(url + '/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(); | |
}; | |
var getDays = function(time) { | |
return Math.floor(time / 60 / 60 / 24); | |
}; | |
var getHours = function(time) { | |
return Math.floor((time / 60 / 60) % 24); | |
}; | |
var getMinutes = function(time) { | |
return Math.round((time / 60) % 60); | |
}; | |
fetchAllViewedItems().then(function(viewedItems) { | |
var days = [ | |
{name: 'Sunday', daysWatched: 0, totalTime: 0}, | |
{name: 'Monday', daysWatched: 0, totalTime: 0}, | |
{name: 'Tuesday', daysWatched: 0, totalTime: 0}, | |
{name: 'Wednesday', daysWatched: 0, totalTime: 0}, | |
{name: 'Thursday', daysWatched: 0, totalTime: 0}, | |
{name: 'Friday', daysWatched: 0, totalTime: 0}, | |
{name: 'Saturday', daysWatched: 0, totalTime: 0}, | |
{name: 'Sunday', daysWatched: 0, totalTime: 0} | |
]; | |
var totalMovieTime = 0; | |
var totalTvTime = 0; | |
var currentDay = ''; | |
var currentDayTime = 0; | |
var longestDay = ''; | |
var longestDayTime = 0; | |
var totalTime = viewedItems.reduce(function(runningTotal, viewedItem) { | |
var itemDate = new Date(viewedItem.dateStr); | |
days[itemDate.getDay()].totalTime += viewedItem.bookmark; | |
if (viewedItem.dateStr == currentDay) { | |
currentDayTime += viewedItem.bookmark; | |
} else { | |
if (currentDayTime > longestDayTime) { | |
longestDay = currentDay + ''; | |
longestDayTime = currentDayTime + 0; | |
} | |
days[itemDate.getDay()].daysWatched += 1; | |
currentDay = viewedItem.dateStr; | |
currentDayTime = viewedItem.bookmark; | |
} | |
// record movie and tv times separately | |
if (viewedItem.series === undefined) { | |
totalMovieTime += viewedItem.bookmark; | |
} else { | |
totalTvTime += viewedItem.bookmark; | |
} | |
return runningTotal + viewedItem.bookmark; | |
}, 0); | |
for (var i=0; i<days.length-1; i++) { | |
var time = days[i].totalTime / days[i].daysWatched; | |
var percentageOfWeek = Math.round(days[i].totalTime / totalTime * 100); | |
console.log('Average watched on %s: %i hours, %i minutes (%i%)', days[i].name, getHours(time), getMinutes(time), percentageOfWeek); | |
} | |
longestDate = new Date(longestDay); | |
console.log('Longest Day Watching: %s (%i hours, %i minutes)', longestDate.toDateString(), getHours(longestDayTime), getMinutes(longestDayTime)); | |
console.log('You have cumulatively watched %i days, %i hours and %i minutes of movies', getDays(totalMovieTime), getHours(totalMovieTime), getMinutes(totalMovieTime)); | |
console.log('You have cumulatively watched %i days, %i hours and %i minutes of TV series', getDays(totalTvTime), getHours(totalTvTime), getMinutes(totalTvTime)); | |
console.log('You have cumulatively watched %i days, %i hours and %i minutes of Netflix', getDays(totalTime), getHours(totalTime), getMinutes(totalTime)); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment