Jumping Hurdles with Heroku


Just for fun I decided to take on a small micro project. I see websites all over the internet that let you enter in the url of a youtube video and download the video. I wanted to make a basic, no frills recreation of that and do a fun little 100 lines or less project, the following is what happened.

First I picked a platform, Heroku was the obvious choice as free hosting as it turns out is the right price. Since I already have a domain so I can easily add a CNAME record to my main website’s host file and add on a simple subdomain in this case youtube-download.treyfoster.com. I decided to go with Heroku’s docker deployment configuration, more on that later.

Laravel was an easy choice as it’s simple enough to setup a quick project. Moving to the library to power the project. I suspect most of these websites use youtube-dl a popular python program that gives the user a host of options in how they want to download the file. You can select what format you’d like the video in (it uses ffmpeg as the default converter).

At first I thought I would take a jolly swing at writing a wrapper, however a simple search revealed there was no need as a wrapper library already existed so I ended up using that instead. All that was left to do was rig up a simple controller and I was off to the races. Here’s a primitive version of it which basically does what I wanted:

The next part was getting this to run on Heroku, the default PHP image that Heroku deploys quite obviously does not include the Youtube-dl binary. Luckily Heroku supports docker which means we can have it run whatever image we damn well please. Here is the Dockerfile I finally rested on:

It’s basically just a pull of an image which pulls in all of Laravel’s dependencies, I then just run the Youtube-dl install script and kick it off back to Laravel. Is this the most elegant thing in the world? No, but the process does show how easy it’s becoming to deploy apps. The entire process only takes about thirty minutes from conception to being a usable albeit primitive application.

Leave a Reply

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