The YouTube and it’s API

Like I described in this post I used to publish videos using an AutoHotkey script. Before that I did it manually of course, which worked fine when I only occasionally published videos. But once I needed to publish videos on time every other day (as my schedule was in the beginning) I needed an automated way of doing it. Thus I wrote the script, which in brief would read text files I would write containing the url of the video and named with the desired publish date. The script opened the URL in my browser on my laptop (not my main computer) and would essentially click the “publish” button on the videos edit page.

This worked for the most part, but sometimes the script would fail to publish a video, which wasn’t a big deal when I was at home and could have it retry immediately. But as I might not always be home, I knew I couldn’t continue relying on this script. And attempts to make it more reliable had failed.

I started looking into YouTube’s API which as I found out allows you to edit the settings of videos the proper way. But it wasn’t easy to figure out how to gain access. Not by a long shot. I needed to allow my scripts permanent access to my account, which required me to use a method that wasn’t as well documented as the main one, which requires a login page to be displayed and the user actively permit access to their account.

But eventually I figured it out. But there weren’t any videos. And I wasn’t sure why at first. But eventually I figured out that the way my google account is built, there’s a main google account which I created a long time ago, and as a child to that there is my YouTube channel which I created even longer ago. And it turns out that the main google account is it’s own YouTube channel, which has no videos in it. And it turns out that the API accesses this by default of course.

Eventually I figured out how to point the API at my proper YouTube channel, which involved getting an email address that I didn’t know it had, which was listed on my channels Google+ page, which I didn’t know existed and found by accident.

My show schedule as it is at the moment.
My show schedule as it is at the moment.

But, as a result I now have a really reliable way of automatically publishing my videos on schedule. I have built a web-interface my system which lets me add new videos easily. For videos belonging to series with a set schedule, like the lets-plays, it will figure out when the next video should be published based on the defined schedule and when the last video is set to publish and pre-select that date.

A major feature of this system (in addition to scheduling) is that it can now insert all the information for a video from my own database.

Before the procedure of uploading a video to YouTube included setting the title, description, tags, recording date, and thumbnail. These I would copy from my system where I would have entered them already. Now however all I do is start the upload and copy the link for the video that it thankfully produces immediately once the file starts uploading. Then I just insert that into my video manager. I can then just click a button and it will use the information I have already entered and set the title, description, tags and even the thumbnail using the image I upload to my system.

This might seem superfluous, to enter the data into my system instead of just entering it into the video myself. But having it in my system allows me much more freedom for manipulating the data however I want before sending it to YouTube.

My system has a database that tracks several different entities. There is of course the Video entity, which has the description, title, publish date etc. Then there’s the Show. A show has a name, of course, for example “Minecraft LetsPlay”. But it also has a default description and default tags. YouTube allows you to have “Upload Defaults” where you can set a title, description and tags (and more) that will be set to new videos that you upload. But it only allows a single default.

Numbers in { } are used to insert text. {0} in the description is where the video description goes.
Numbers in { } are used to insert text. {0} in the description is where the video description goes.
Where I would enter the information for a new show, or edit an existing one.

My system allows me any number of defaults I want, defined as a Show. When I tell it to set the data of a video on YouTube it will take the description of the video, combine that with the description of the show the video belongs to and send the combination to YouTube. Further, and this is something you cannot do on YouTube at all, if I change the description of a show a bit I can tell my system to update all of the videos that are a part of that show. If I wanted to do that on the YouTube site I’d have to edit the videos one-by-one manually. And if you have a series that contains hundreds of videos that’s just not something you would do. But my system makes these updates easy. And I have already used it a couple of times to add more info or correct mistakes.

I’m quite proud of it. And I will continue using it for as long as I keep publishing YouTube videos, probably even if they decide to let anyone use their own scheduling system. Because mine us just so much better.

Leave a Reply

Your email address will not be published. Required fields are marked *