This YouTube video will be deleted once the channel reaches 4000 watch hours. Why 4000? Well, it's just a random number and no, it has nothing to do with monetization xD.
The main script is located in the /backend/autoDeleteVideo.js
file. We first need access to the YouTube Analytics API to check the channel's watch hours and YouTube Data API to authenticate and delete the video on my channel.
Also, I've set up GitHub Actions that does all of it for me once every 3 days. What about authenticating? Well, it's thanks to this file: /backend/getRefreshToken.js
. It's only run once to sign in with the account and get the refresh token manually and then you don't need that file anymore. Because, we only care about the refresh token for this line of code for automatic authentication:
oauth2Client.setCredentials({ refresh_token: REFRESH_TOKEN });
Once the GitHub Actions have run, it'll also generate a JSON file in the /frontend/analytics.json
folder, which I've used to set up a small landing page to show the data.
Here's a couple of useful resources if you want to dive deeper:
- Make a YouTube video, duh
- Fix the frontend
- Add a proper README