-
-
Save sudohaxe/4302f64698b60a62b74823ed7210933e to your computer and use it in GitHub Desktop.
Get a YouTube Channel's Total Video Duration
This file contains hidden or 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
/** | |
* ๐ Youtube Channel Total Video Duration Grabber/Calculator | |
* | |
* โ Instructions: | |
* - Scroll all the way to the bottom of the YouTube home/feed/playlist page | |
* to ensure all videos are loaded. | |
* - Paste this script into the browser console. | |
* | |
* โ ๏ธ Disclaimer: | |
* This script was created with the help of AI assistance. | |
* I am not responsible or liable for any issues, damage, or consequences | |
* resulting from the use of this script. Use it at your own risk. | |
*/ | |
var items = document.getElementsByClassName("style-scope ytd-rich-item-renderer"); | |
console.log(`๐ฆ Found ${items.length} video containers on the page.\n`); | |
var allVideos = []; | |
var seen = new Set(); | |
var allHours = 0; | |
var allMinutes = 0; | |
var allSeconds = 0; | |
for (var i = 0; i < items.length; i++) { | |
var titleElement = items[i].querySelector("#video-title"); | |
var badge = items[i].querySelector(".badge-shape-wiz__text"); | |
var title = titleElement ? titleElement.textContent.trim() : null; | |
var duration = badge ? badge.textContent.trim() : null; | |
if (!title || !duration) continue; | |
let uniqueKey = `${title}__${duration}`; | |
if (seen.has(uniqueKey)) { | |
console.log(`โ ๏ธ Duplicate skipped: "${title}" โ ${duration}`); | |
continue; | |
} | |
seen.add(uniqueKey); | |
console.log(`โ [${allVideos.length + 1}] "${title}" โ ${duration}`); | |
// Parse duration | |
var timeParts = duration.split(":").map(Number); | |
if (timeParts.length === 3) { | |
allHours += timeParts[0]; | |
allMinutes += timeParts[1]; | |
allSeconds += timeParts[2]; | |
} else if (timeParts.length === 2) { | |
allMinutes += timeParts[0]; | |
allSeconds += timeParts[1]; | |
} else if (timeParts.length === 1) { | |
allSeconds += timeParts[0]; | |
} | |
allVideos.push({ title, duration }); | |
} | |
// Normalize time | |
allMinutes += Math.floor(allSeconds / 60); | |
allSeconds %= 60; | |
allHours += Math.floor(allMinutes / 60); | |
allMinutes %= 60; | |
var totalDays = Math.floor(allHours / 24); | |
allHours %= 24; | |
console.log("\n๐ Final Video Summary:"); | |
console.table(allVideos); | |
console.log("\n๐งฎ Total Watch Time:"); | |
console.log("----------------------------------"); | |
console.log("๐บ Unique Videos Counted:", allVideos.length); | |
console.log(`๐ Total Time: ${totalDays} days, ${allHours} hours, ${allMinutes} minutes, ${allSeconds} seconds`); | |
console.log("----------------------------------"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment