Batch upload videos to youtube using Youtube Uploader

Recently I had a client that asked that the documentation of the application I made for them to be on videos posted privately on YouTube.

That’s no problem…

But there is the inconvenience of having to upload videos one by one using the YouTube interface.

That’s why I recurred to the YouTube Uploader tool. To be able to script the upload of all the videos.

Youtube Uploadeer Home page

So lets see how you can grab this tool and how can you install it to upload videos to Youtube from the command line.

TOC

Installation

YouTube Uploader is written in Go. And if a tool is written in Go it’s very, very likely that the product is a binary file and that is multi platform.

This is exactly the case with YouTube Uploader. The download its just a zipped binary file. And there are multiple binary files, one for each architecture.

So the installation consist in:

# The Mac version is suffixed by mac_amd64
curl -o youtubeuploader.zip -L  https://github.com/porjo/youtubeuploader/releases/download/20.04/youtubeuploader_mac_amd64.zip
unzip youtubeuploader.zip
mv youtubeuploader_mac_amd64 youtubeuploader
chmod 755 youtubeuploader # Make it executable
sudo mv youtubeuploader /usr/local/bin
youtubeuploader -v

The complete installation steps

Create Google’s Developers Account

Before we start to upload videos to YouTube, we need to authorize the tool using an API key. And for that you need to have an account in Google’s Developer Console.

So if you don’t have an account there yet. Go and create one… Done? good, lets move on.

Create a new Client ID and Secret for Youtube Uploader

Youtube Uploader uses OAuth to authenticate itself to Youtube. This means that you have to create a Client ID and a Secret in Google Developer Console.

So start by creating a new project for this.

Creation of a new project 1/2

Creation of a new project 2/2

Actually, creating a project is not required, but its a good idea in case you have any security issue.

Enable the Youtube API

Now that we have a new project, head over to the API library by clicking on Library on the Left Sidebar

API Library

And look for YouTube Data API V3

Youtube API Library

And enable it

Enable YouTube API

Create OAuth credentials

First of all, be sure that you are still on the Youtube API configuration and then select Create Credentials for a OAuth Client

Create credentials OAuth Client ID

On the next screen select Web Application

OAuth Web Application

Give it a name and use the callback http://localhost:8080/oauth2callback. This is very important!.

Select OAuth Callback

Finally take a not of the Client API ID and the Secret since we’re going to need them on the next step.

OAuth id and secret

Configure your workspace

Youtube Uplaoder needs 2 files on your local file system in order to work:

This files have to be placed in the directory where you are going to execute the command.

The creation of the client_secrets.json is pretty straight forward. Just use a text editor to create the file with the following structure:

{
  "installed": {
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "redirect_uris": ["http://localhost:8080/oauth2callback"],
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token"
  }
}

Create the client_secrets.json

Remember to change YOUR_CLIENT_ID and YOUR_CLIENT_SECRET for your actual data:

A real client_secrets.json file

The request.token file will be created for us in the first upload. Meaning, the next step.

Uploading your first file

As I said before, when you upload your first file, the request.token will get created. That’s why the first upload is so important.

So have a .mp4 file at hand and execute the following upload command:

youtubeuploader -filename "my-local-file.mp4" -title "This is my first vide"

Obviously, change the name of the file and the title accordingly

Upload command

Youtube Uploader will open a new browser window asking to select an account to use for the uploading:

Select upload account browser window

You’ll get a certificate error which is pretty normal in our case

Certificat error browser windows

And then you’ll get asked if you want to grant upload permissions to Youtube Uploader

Grant upload permissions

And then a success message of permissions granted:

Permissions granted window

In that moment. The request.token will get created, and your file will start uploading.

File uploading

You can check that the request.token got created

Request Token created

Next Uploads

Fortunately the Auth section for Youtube Uploader only has to be executed once. But you have to remember to keep the client_secrets.json and your request.token around!

Otherwise you have to go trough the authorization part again.

Summary

So to use Youtube Uploader you just have to:

Interesting Parammeters

You can get a complete list of the supported parammeters by executing

youtubeuploader -h

But here is a list of the most useful ones: