Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sudohaxe/4302f64698b60a62b74823ed7210933e to your computer and use it in GitHub Desktop.
Save sudohaxe/4302f64698b60a62b74823ed7210933e to your computer and use it in GitHub Desktop.
Get a YouTube Channel's Total Video Duration
/**
* ๐Ÿ“œ 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