Automating My YouTube Uploads Using Node.js
YouTube has the most comprehensive control panel of all video hosting services. Yet, this comprehensiveness comes at a cost. There is a ridiculous number of metadata fields you are supposed to fill per video. It is not obligatory, but the more metadata you provide to the YouTube algorithm, the more discoverable your videos will be. And filling all those fields by hand is a huge pain. Especially if you prepare the script of your videos using Word as I do. You can automate away this pain using the code provided on this page. You can also follow the video tutorial if you can’t get the code to work on your own.
Table of contents:
Video guide: https://www.youtube.com/watch?v=gncPwSEzq1s
The video has the full demonstration of this project. If you want to read the comments or leave a comment, do so under the YouTube video. If you want to contribute to the article, make a pull request on GitHub.
YouTube API Resources:
- Node.js Client QuickStart Guide. My uploader code is adapted from this. Follow the first section of it to download your project credentials: https://developers.google.com/youtube/v3/quickstart/nodejs
- API Reference: https://developers.google.com/youtube/v3/docs/videos/insert
- API Credentials: https://console.developers.google.com/apis/dashboard
If you don’t already have a verified YouTube project, or an old Google APIs project, you will have to ask your project to be whitelisted or your uploads cannot be made public:
- YouTube API Compliance Audit Request Form: https://support.google.com/youtube/contact/yt_api_form
You can find my YouTube uploader code on GitHub too:
Project Design Document
Software development process starts with a design document. If you are interested, you can learn more about Software/Systems Development Life Cycle on Wikipedia.
Below is the software design document that I created for this project. If you want, you can take inspirations from it in your own projects.
- Upload my videos to YouTube programmatically using YouTube API in Node.js. All the video metadata needs to be parsed from the video’s script, which is written in Microsoft Word.
- Read and parse the video metadata from the video’s script, which is a Word document.
- Upload the main 4K video (40GB+) to YouTube and set proper metadata and thumbnail.
- I checked the developer documentation, and YouTube API has a nice HTTP endpoint to upload new videos so we can use it.
- They also provide a Node.js API Client which we can use to simplify this further.
- Even though there are several libraries to read Word documents, we don’t need them. We can programmatically start Word from command line and export a plaintext file of the video script and parse that instead. One less dependency!
- Simple modular design, using Node.js (CommonJS) modules. Each distinct functionality like parsing Word documents, using YouTube API, etc., will be in their modules.
- Optional: A fully flagged command-line app using “Yargs” argument parser library.
Proof of Concept:
- There is an excellent YouTube upload CLI tool in existence already so it proves that this is doable, so there is no need for a separate POC: https://github.com/tokland/youtube-upload
npm initfor a quick start with Node.js.
- Create the module layout.
- Implement each module and the module tests.
- Put all modules together as a simple command-line app.
- Document everything in a README file (and the article’s resources section).
I plan to expand this project to automate my other chores like Twitter posts, Instagram updates, compressing the master video using FFmpeg for storage, and finally storing everything on cheap cloud storage. As I make these improvements, I will post an update article (and video) demonstrating my entire workflow automation. I plan to stick with Node.js as it worked out very well for me. But if you convert my code to Python, ping me so I can post it in the resources section above. And if you don’t want to miss the update when it’s out, follow me on my socials.