Victor Franzi's Home Page

4 April 2020

All the code used in this post is available here

Netflix and chill

What is better after a hard day of work than coming home and watching a good movie? You grab a beer, take a sit on the sofa, and.. you start Netflix. But what about those movies that are not on Netflix? How do you watch them?

I took advantage of the lockdown by setting up an infrastructure to get those movies, arrange them in my library and share them over my home network.

This article, as you can guess, will show you how I do this. To do so, we will separate this in three sections:

  1. Get the movie
  2. Put it in the library
  3. Make it available on my home network

Prelude, show me the beast

I’m young, I’m lazy, and I don’t want to mess my server with configurations, daemons, etc. The simplest way to do this is to put everything in Docker containers.

Under the hood, it runs on a Raspberry Pi 3 (called babar), with a 2TB HDD plugged in. This drive is partitioned using LVM, so I can add storage just by extending the virtual group (and logical volume) with new drives.

So we have one big partition which is mounted on /downloads. This partition is mounted by adding this entry in /etc/fstab:

UUID=12345678-1234-abcd-ef42-deadbeef6969   /downloads       ext4        rw,relatime 0 2

Type # blkid to get the partition UUID.

To sum up, here is the architecture:

 RPi -------------- HDD(s)
  |                   |
  |         LVM (single partition)
  |                   |
/data             /downloads
 > library         > torrents

First, get that damn movie

Let’s take a movie that we will watch together, let me suggest The Holy Mountain, a movie from Alexandro Jodorowsky.

In order to watch this movie, we first need to get it, by getting it I mean downloading it.

Disclaimer: downloading is very bad, please don’t do this at home.

I go to my favorite torrent tracker, and get the .torrent. Once we have this torrent file, we will need a software to download it, and more generally to manage our torrents.

So, after having tried a couple softwares to manage my torrents, I ended up using an existing Docker image, docker-transmission-openvpn. This one is pretty good, it uses transmission which is the bread and butter of torrenting, and fully integrates openvpn (hey hadopi).

The image is very simple to set up, fill your VPN provider credentials, and that’s all. In order to get that image working, I created a simple docker-compose file with the following service:

transmission:
  image: haugene/transmission-openvpn
  volumes:
    - '/downloads:/data'
  environment:
    - OPENVPN_PROVIDER=PIA
    - OPENVPN_CONFIG=CA Toronto
    - OPENVPN_USERNAME=user
    - OPENVPN_PASSWORD=pass

Transmission web interface is accessible at http://babar:9091/

Now, arrange that library

Once downloaded, The Holy Mountain is located at /downloads/completed/The.Holy.Mountain.mkv. This directory is such a mess, transmission will just leave the files there, and not arrange them at all.

What we need now is to sort the movies. To do so, I use the very good jpillora’s media-sort.

This software reads a directory, and for each found media file, it searches for informations about it on the internet. Then, it arranges the movies in /data where they are all sorted by movie (./title.ext) and series (./show/season/show S0E0.episode.ext).

As no official Docker image is available, I created a simple Dockerfile. The created image is integrated in the global docker-compose.

As media-sort is highly customizable, the image only defines /media-sort as the entry point. I use the following options (specified in the command field of the compose file).

media-sort \
        --tv-dir /data --movie-dir /data \
        --tv-template '...snippet...' \
        --movie-template '...snippet...' \
        --action link \
        --recursive \
        --num-dirs -1 \
        --accuracy-threshold 80 \
        --watch \
        /downloads

Share it over the network

That’s almost good, we downloaded The Holy Mountain with transmission, and put it in the library using media-sort. It’s now time to make it available on the network.

Here, multiple solutions were possible. Some may want to use Kodi, or Radarr, or even Plex. I ended up using UPnP which is supported by my TV.

To set up the UPnP sharing, I use ReadyMedia (formerly minidlna).

A docker image already exists, I just had to integrate it with my other services!

minidlna:
  image: vladgh/minidlna
  volumes:
    - "/media:/media:ro"
  environment:
    - MINIDLNA_MEDIA_DIR=/media
    - MINIDLNA_FRIENDLY_NAME=Babar (DLNA)

No Netflix but still chill

Once all the services are created and integrated in the compose file, I just have to run docker-compose up -d and voilà, it just works™.

Waow, what a trip. This damn movie is eventually available on my network.

On my TV, I can simply select my server, and the movie is here. On my phone and my laptop, VLC supports both UPnP and DLNA, select Local network.

Alright, we’re good! Now let’s grab this damn beer, sit on this damn sofa, and watch this damn movie.