Skip to content

Instantly share code, notes, and snippets.

@fredericogg
Last active December 30, 2023 16:16
Show Gist options
  • Save fredericogg/494a20770d33d5ca48d3 to your computer and use it in GitHub Desktop.
Save fredericogg/494a20770d33d5ca48d3 to your computer and use it in GitHub Desktop.
Calcula o tempo total de uma playlist no Youtube. É só colar no console na página da playlist. Fiz esse script porque não achei o tempo total da playlist 😅.
(function() {
var timeSeconds = 0;
var timestampDivList = document.querySelectorAll(".timestamp");
for(var i = 0; i < timestampDivList.length; i++) {
var timestampDiv = timestampDivList[i];
var timeStr = timestampDiv.childNodes[0].innerHTML
var timeParts = timeStr.split(":");
var seconds = (timeParts[0] * 60) + parseInt(timeParts[1]);
timeSeconds += seconds;
}
var hours = (timeSeconds / 60) / 60;
var minutes = (timeSeconds / 60) % 60;
var seconds = (timeSeconds % 60);
var result = parseInt(hours) + ":" + parseInt(minutes) + ":" + parseInt(seconds);
alert(result);
})();
@zoyo23
Copy link

zoyo23 commented Feb 12, 2022

Comigo não rolou só dava NAN, ai eu fiz algumas alterações na busca das informações e rolou tranquilo.

https://gist.github.com/zoyo23/e4050ba6a2f672949f39bb6beca0694c

@vizanchetta
Copy link

cmg n rolou, só dava 0:0:0, fiz o desse zoyo23 e deu bom 👍
https://gist.github.com/zoyo23/e4050ba6a2f672949f39bb6beca0694c

@LauraGenari
Copy link

muito bommm, só precisei fazer umas alterações pq acho q yt atualizou, e ficou assim (function() {

var timeSeconds = 0;

var timestampDivList = Object.entries(document.querySelectorAll("ytd-playlist-video-list-renderer ytd-playlist-video-renderer ytd-thumbnail-overlay-time-status-renderer span")).map(item=> item[1].innerText)

for(var i = 0; i < timestampDivList.length; i++) {

var timeParts = timestampDivList[i].split(":");

var seconds = (timeParts[0] * 60) + parseInt(timeParts[1]);

timeSeconds += seconds;

}

var hours = (timeSeconds / 60) / 60;
var minutes = (timeSeconds / 60) % 60;
var seconds = (timeSeconds % 60);

var result = parseInt(hours) + ":" + parseInt(minutes) + ":" + parseInt(seconds);

alert(result);

})();

@alexmota-dev
Copy link

Recriei e arrumei os bugs, só pegar pessoal: https://github.com/ThalysSilva/Projetos-JavaScript/blob/master/playlist-time_v2.js

Valeu paizão, se é 10 kskssk funcionou.

@alexmota-dev
Copy link

Infelizmente seu código não funciona amigo, mas foi uma ideia genial, de 2016 a 2020 deve ter ajudado muita gente, obrigado.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment