How to Change YouTube Title With Real Time View Count, The Tom Scott way

How-to-Change-YouTube-Title-The-Tom-Scott-way

How to Update Title Of Video Automatically Using Google Script Scheduler

If I make a YouTube video and that video gets more than 2.5M views in just 17 hours, I will get to my rooftops and I will shout about it.

Wait — What if the YouTube video itself can shout for me?

YouTuber Tom Scott’s latest video titled, “This video Has X Views,” will update the title of video with its current View Count. Interesting, right?

Its a really good video, but that video isn’t about the actual code and workflow that does the update of title. In this post, I am going to explain the steps to automatically update the title of YouTube video with the view count using Google Apps Script without any Billing.

Let’s break down the entire process into a few steps. So I know that I want to execute a single script to:

  1. Login to Youtube (with the account that contains the video I want to update )
  2. Get the number of current views of the chosen video.
  3. Update the title of the video with the new information
  4. Run this script as often as I like ( Cron Job )Project start

Let’s create a new project in Google Apps Script.

To fetch the view count of the video, we have to call the YouTube Data API using the video ID. It gives the whole data about the video. We have to take the required data from the result object as below:

How to Change YouTube Title With Real Time View Count, The Tom Scott way Google Script Image

getVideoDetails() — This function takes videoId as a parameter and returns details about the video from YouTube using YouTube Data API V3

As the YouTube API Call is limited per day. I recommend adding validation in the code that if the View Count is already the same that in the title. We should not call the Update API. In the below code, it is checking if the view count from the YouTube API is already present in the video title.

How to Change YouTube Title With Real Time View Count - Validate

validate() — This function validates if the current view count and the count in the title are the same.

Now, we are at the final step, if the View Count from YouTube is not the same with the count in the title we should update the info back into the YouTube. We use Youtube. Update API from YouTube Data API V3.

How to Change YouTube Title With Real Time View Count - Update Google Script

updateDetails() — This function updates the info back into the YouTube

https://github.com/nazaltk/This-video-has-n-views.git

Stay Tuned with us: NajmaNazal Vlog

May the way back be with you!

3 thoughts on “How to Change YouTube Title With Real Time View Count, The Tom Scott way

Leave a Reply