Skip to content

Instantly share code, notes, and snippets.

@putty182
Last active August 17, 2022 11:46
Show Gist options
  • Save putty182/1ce2583d2fe48cf7dcfbde6aad814375 to your computer and use it in GitHub Desktop.
Save putty182/1ce2583d2fe48cf7dcfbde6aad814375 to your computer and use it in GitHub Desktop.
Netflix viewing history to CSV
  1. Visit https://www.netflix.com/viewingactivity in a reputable browser
  2. Open the JS Console.
  3. Copy/paste this script, execute it and wait 4 seconds after the page finishes scrolling.
  4. ...
  5. Profit!

Recent release of Chrome will add a nice 'Copy' button next to the console output.

waitseconds can be adjusted if nessessary to ensure all play history gets loaded.

Google sheets allows pasting CSV directly into a new sheet and splitting text to columns based on commas, or you could save it as a .csv yourself

Next step: mark all this as watched in Trakt!

var rows = []
var counts = []
var waitseconds = 4
var scrolltimer = setInterval(() => {
// scroll to bottom of the page
window.scrollTo(0,document.body.scrollHeight)
// remember how many rows we see right now
rows = document.querySelectorAll('.retable .retableRow');
counts.push(rows.length)
// all done if we've waited long enough and the last x counts are the same
var finished = counts.length > (waitseconds * 2) && counts.slice(counts.length - (waitseconds * 2), counts.length)
.every((count, idx, counts) => count === counts[0])
if (finished) {
// no more scrolling
clearInterval(scrolltimer)
// grab the items
var items = Array.prototype.slice
.call(document.querySelectorAll('.retable .retableRow'))
.map((row) => ({
'date': row.querySelector('.date').textContent,
'title': row.querySelector('.title').textContent,
'url': row.querySelector('.title a').href
}))
// munge into a csv string
var header = Object.keys(items[0]);
var csv = items.map(row => header.map(field => JSON.stringify(row[field])).join(','))
csv.unshift(header.join(','))
csv = csv.join('\r\n')
// log it for now
console.log(csv)
}
}, 500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment