A COVID-born project

Since my home internet is satellite-based with a tiny 50 GB monthly cap, I used to (pre-pandemic) just download shows from tou.tv using ffmpeg while in Montreal and throw them on a USB stick. The problem is that now I'm home full-time, with zero access to a decent internet connection. So how do I actually enjoy a platform I pay for every month when it barely limps along at 270p over Xplornet's brutal latency? I finally coded up the answer.

Docker containers built on simple, powerful tools

A picture is worth a thousand words, so here is a quick overview of the recorder architecture that does the heavy lifting:

Schéma de l'architecture Docker de l'enregistreur VHS

Here is a closer look at the tools under the hood:

  • SimpleScreenRecorder: Video and audio capture software that adjusts sampling on the fly to avoid audio/video sync drift. The defaults work great and you can drive it programmatically over stdin.
  • Pulseaudio: Audio server: the default on Fedora, Ubuntu, Debian, Linux Mint, openSUSE, and even OpenWrt.
  • Xvfb: X11 virtual framebuffer display server (a headless screen emulator).
  • Selenium (geckodriver/firefox): Browser automation framework to drive the web player programmatically.
  • Ffmpeg: Video and audio encoder; used here to re-encode and compress the raw high-quality captures down to a reasonable size.
  • Gluetun VPN client: A Dockerized VPN client with tinyproxy so the recorder gets a Canadian IP address even when running on a VM hosted in another region.

To sum up the architecture in one sentence: a Python app orchestrating a bunch of tools inside Docker, acting like a robot that clicks around to play a show, records it, and ships the finished file where it belongs.

What does it look like?

Here it is in action on the command line:

The tool automatically connects to the site, logs in, detects the video length, and records the whole thing with a single command. Note that in this demo we force a 10-second recording so we don't have to sit through a full episode just to see the rest of the run.

A few challenges

Selenium and tou.tv

Obviously, it didn't all work on the first try. I hit plenty of snags, especially around automating tou.tv with Selenium. Selenium itself is great, but because tou.tv is bloated, flaky, and behaves differently from one run to the next, I had to arm myself with patience and handle every weird edge case one by one, slowly but surely. By the end of it, I probably leveled up my patience way more than my Python.

That said, it did force me to get a much better grasp on a few Selenium concepts I only vaguely knew before: ActionChains and the Wait classes.

IP addresses and geo-blocking

Since the whole thing runs in the cloud, and Google's Canadian regions were sporadically running out of capacity, I had to spin up VMs hosted in the US. Naturally, tou.tv decided to block my requests. The fix? A VPN, of course. I already had a Private Internet Access subscription and found a Docker VPN client that lets the other containers route through it via proxy.

Even then, tou.tv's sheer bloat caused headaches too. I'm not just saying that to be mean: the tou.tv home page alone fires off 410 requests and downloads over 8 MB. Sorry to the devs, or maybe the product owners, but one thing's for sure, it could be better (especially for folks on mediocre connections). Long story short, I had to tweak a few default settings in the VPN image to beef it up; you can see the diff here.

Full automation on GCP

In the next post, I'll share an overview and walkthrough of the full system deployed on Google Cloud Platform, which lets me record a show with a single API call.