I created a CLI tool to easily upload files to Google Drive

If you know me, you might know that I have big sense of preservation. I’m a big fan of collecting video games for that reason, but it also applies to something else. I follow a lot of Twitch streamers and love watching their content, but one thing I really dislike about Twitch compared to YouTube, is that stream archives (“VODs”) are only stored for 60 days (for non-partners even less). This is a huge issue for someone like me who likes to go back to older content from time to time and re-watch older livestreams.

This is an issue I am currently trying to solve for myself and today I built a small tool that will probably help me a ton in the greater scheme of things.

My current solution to this was a small VPS I set up to download Twitch VODs and render them together with the chat using an open-source tool called TwitchDownloader. The developer of that tool kindly provided me with their own solution to rendering chat and video together, so I didn’t have to figure that out.

However recently I faced a new problem with this little make-shift solution: disk space. So far I had just downloaded the videos to the VPS and left them there because moving files this big around is a hassle. Now that the disk space is reaching it’s limit I was forced to come up with a quicker solution.

I have thought about setting up my own personal storage servers for this but that’s something that will take a bit longer to do properly, so I chose Google Drive for storage. I am on a Google Workspace (formerly G-Suite) plan which allows me to store a ton of files and not having to worry about disk space running out. Additionally, Google Drive processes video files so I can even watch these archived livestreams directly from their UI, without having to download them to my computer first.

Which is the reason I created my google-drive-upload-cli. A simple Kotlin-based CLI tool to upload large files to a Google Drive account. I had previously tried multiple existing CLI tools for Google Drive, but ran into issues with almost all of them and since Google doesn’t offer one themselves, I was forced to do it myself. The only alternative would’ve been downloading all of these files to my personal computer and then uploading them through the Google Drive UI, which would basically make my computer’s internet connection unusable for days.

I chose Kotlin since it’s a language I’m familiar with. I pretty much replaced Java with it entirely and it allows me to start a project quickly and get to programming. I had previously looked into how easily I can make something like this and found this StackOverflow answer. Seems I wasn’t the only one looking for quick and easy solutions to this problem. All I had to do was wrap all of that into a solution that refreshes OAuth tokens and I was almost done. For resumable uploads of bigger files, I borrowed an existing Java class that somebody had created a while back.

Now I added my little CLI to the existing scripts I had on my VPS and my solution is almost automatic. In the future I would like to upgrade this even more. I’ve had the idea of a web tool where I can just dump any link and it will automatically download and store the video for me for a while. Maybe I’ll get to that one day. For now, I can safely store and Twitch videos and not worry about them being lost.

It wasn’t a big project but it was fun to work on something open-source again, I haven’t done that in a while. I don’t know if I will continue working on this tool specifically, since it was just made as a quick solution to a simple problem. Maybe I’ll add something like support for uploading entire folders, who knows.

You can check out the source code on GitHub.