Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How to find the total views of all videos in a YouTube PlayList?

$
0
0

I am trying to find the total number of views of all videos in a playlist I own in YouTube. I can see that a "total views" number is posted under the playlist name. However this appears to be the number of views generated by entering the playlist first. When I add up the number of views of individual videos I get a substantially larger number because, I assume, most of videos are watched by following a link other than the playlist.

In particular using the following JS in the YT console

ytInitialData.header.playlistHeaderRenderer.viewCountText.simpleText

just gives the same number that is available under the playlist name.

ChatGPT gives the following JS

var totalViews = 0;var videos = document.querySelectorAll('ytd-playlist-video-renderer');for (var i = 0; i < videos.length; i++) {  var viewsElement = videos[i].querySelector('#metadata > span:nth- child(1)');  if (viewsElement !== null) {     var views = viewsElement.textContent.trim().replace(/\D/g,'');     totalViews += parseInt(views);  } } console.log('Total views of all videos in the playlist: '+ totalViews);

But this gives a total count of 0.

Could it be that the count the not available in the HTML source code? And how do we get the total count?


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>