Skip to content

Instantly share code, notes, and snippets.

@VijayKM01
Forked from Ghost---Shadow/PlaylistLength.js
Created April 2, 2020 22:34
Show Gist options
  • Select an option

  • Save VijayKM01/9ea7a40ceca0c38fee6d3678bf35f22c to your computer and use it in GitHub Desktop.

Select an option

Save VijayKM01/9ea7a40ceca0c38fee6d3678bf35f22c to your computer and use it in GitHub Desktop.
Calculate the total length of a youtube playlist. Just open javascript console, paste and press enter.
/**
USAGE
1. Open the playlist you want
2. Right click > Inspect element > Console
3. Copy this and paste. Hit enter.
4. For watch later make sure to click the Edit button
EDIT: Not all playlists have hours.
*/
const table = document.getElementById("pl-video-table")
const rows = Array.from(table.rows)
const toSeconds = s => s ? s.split(':').map(v => parseInt(v)).reverse().reduce((acc,e,i) => acc + e * Math.pow(60,i)) : 0
const getTimestamp = row => toSeconds(row.children[6].children[0].children[0].innerText)
let seconds = rows.reduce((acc,e) => acc + getTimestamp(e),0)
let mins = parseInt(seconds / 60)
seconds %= 60
let hours = parseInt(mins / 60)
mins %= 60
console.log(hours+":"+mins+":"+seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment