Dockerize your tv shows download and streaming to your TV

ยท 983 words ยท 5 minute read

I’m going to explain my setup of how do I watch my favourites tv shows using containers.

Requisites ๐Ÿ”—

  • TV
  • WiFi
  • ChromeCast
  • Plex for Android
  • ShowRSS feed. You need to create an account and setup it with your favourites tv shows, so you’ll end up with some rss feed like
  • CentOS 7 (or any distro docker capable) with docker daemon installed and running
  • Non root user to run all the commands (this is a personal preference, feel free to do it with root user if you want…)
  • Shared folders to store your multimedia, flexget config & plex config. Something like:
โ”œโ”€โ”€ plex
โ”œโ”€โ”€ flexget
โ”œโ”€โ”€ music
โ”œโ”€โ”€ pictures
โ”œโ”€โ”€ transmission
โ”‚ย ย  โ”œโ”€โ”€ downloads
โ”‚ย ย  โ”œโ”€โ”€ incomplete
โ”‚ย ย  โ””โ”€โ”€ watch
โ””โ”€โ”€ videos
    โ”œโ”€โ”€ movies
    โ””โ”€โ”€ tvshows

I store the media folder in a btrfs subvolume, but that’s another topic :)

Setup ๐Ÿ”—

TV ๐Ÿ”—

  • ChromeCast is properly setup to your TV and wireless network
  • Android mobile with Plex for Android installed in the same wireless network

NAT ๐Ÿ”—

You need to open 12345/udp port in your router to your docker host (transmission container connectivity with the outside world)

Docker host ๐Ÿ”—

Why Fedora? Because I like it and I work at Red Hat :D

How does it work ๐Ÿ”—

Transmission container is listening in 9091 for API calls and webgui. Every hour (using cron), the flexget container is executed, and attached to the same network namespace than the transmission container (so it can send API calls to localhost).

Flexget will:

  • query the RSS feed and enqueue the proper magnet links to the transmission daemon to download the tv shows that you’ve configured
  • if finished, it will move the tv shows to the proper folders in your media folder
  • if finished, and ratio or timeout reached, it will clean the transmission queue

Then, when you want, fire the Plex app in your Android phone, browse your favourite tv show, and play it in your big screen TV :)

Installation ๐Ÿ”—

Easy peasy!

  • Pull the docker images:
docker pull eminguez/transmission-fedora
docker pull eminguez/flexget-fedora
docker pull eminguez/plex-media-server-fedora
  • Create a simple script to run the flexget container (in my case /home/edu/bin/`) and give it the proper execution permissions
docker run --rm --net=container:transmission -v /storage/media/flexget/:/home/flexget/.config/flexget/ -v /storage/media/transmission/downloads/:/home/flexget/flexget/from -v /storage/media/videos/tvshows/:/home/flexget/flexget/to eminguez/flexget-fedora > /dev/null
  • Setup an hourly cron task to trigger the flexget container:
0 * * * * /home/edu/bin/ >/dev/null 2>&1
  • Configure flexget to get your tv shows. I use the following template, replace the VARIABLES with your settings, and store it in /storage/media/flexget/config.yml:
      host: localhost
      port: 9091
      username: transmission
      password: PASSWORD
      finished_for: 2 hours
      min_ratio: 1
    disable: [details]
    # configuration of email parameters
    # each feed will send an email with the accepted entries
    # can be disabled per feed with email: active: False
      active: True
      from: FROM
      to: TO
      smtp_port: 587
      smtp_login: true
      smtp_username: USERNAME
      smtp_password: PASSWORD
      smtp_tls: true
  # downloading task
    # fetch all the feed series
    all_series: yes
    limit_new: 10  
    # use transmission to download the torrents
      host: localhost
      port: 9091
      username: transmission
      password: PASSWORD
    only_new: yes
  # sorting task
      # directory with the files to be sorted
      path: /home/flexget/flexget/from/
      # fetch all avi, mkv and mp4 files, skips the .part files (unfinished torrents)
      regexp: '.*\.(avi|mkv|mp4)$'
      recursive: yes
    accept_all: yes
    seen: local
        - sample
    # this is needed for the episode names
    thetvdb_lookup: yes
      parse_only: yes
      # this is where the series will be put
      to: /home/flexget/flexget/to/{{ tvdb_series_name }}
      # save the file as "Series Name - SxxEyy - Episode Name.ext"
      filename: '{{ tvdb_series_name }} - {{ series_id }} - {{ tvdb_ep_name }}{{ location | pathext }}'
  • Run the transmission container with the previously used password as environmental variable:
docker run -d --name transmission --restart=always -p 12345:12345 -p 12345:12345/udp -p 9091:9091 -e ADMIN_PASS=PASSWORD -v /storage/media/transmission/downloads:/var/lib/transmission/downloads -v /storage/media/transmission/incomplete:/var/lib/transmission/incomplete -v /storage/media/transmission/watch:/var/lib/transmission/watch eminguez/transmission-fedora

Note the restart=always flag to keep it running 24x7 and survive host reboots!

  • Run the plex container:
docker run --name plex-media-server -d --restart=always -v /storage/media/plex/:/config -v /storage/media/:/media -p 32400:32400 eminguez/plex-fedora

Note the restart=always flag to keep it running 24x7 and survive host reboots!

  • Browse to http://your_host:32400/web and configure plex for your environment.

If this doesn’t work, kill the plex container, edit /storage/media/plex/Plex Media Server/Preferences.xml and add the allowedNetworks="" attribute to the <Preferences …> node to allow networking connections, and start the plex container again

Tips ๐Ÿ”—

  • If you want Avahi broadcast to work, add --net=host to the plex container run command, but this will be more insecure. I’ve setup manually my server in the Plex Android app to point directly to the host in Settings > Advanced > Manual Connections
  • Set a friendly Plex server name under Plex Settings > Server > General in the Plex web Gui
  • You can download any torrent/magnet file browsing http://your_host:9091 using “transmission/PASSWORD” and it will be downloaded to /storage/media/transmission/downloads/ folder
  • As a bonus, you can drop any torrent file in /storage/media/transmission/watch/ folder and transmission will gently download it for you :)

Volume mapping explanation ๐Ÿ”—

Flexget ๐Ÿ”—

  • `/storage/media/flexget/:/home/flexget/.config/flexget/ to store the flexget configuration, sqlite database and log file
  • /storage/media/transmission/downloads/:/home/flexget/flexget/from where transmission will move the files once downloaded
  • `/storage/media/videos/tvshows/:/home/flexget/flexget/to where plex will look for tv shows

Transmission ๐Ÿ”—

  • /storage/media/transmission/incomplete:/var/lib/transmission/incomplete incomplete downloaded files
  • /storage/media/transmission/downloads:/var/lib/transmission/downloads where transmission will move the files once downloaded
  • /storage/media/transmission/watch:/var/lib/transmission/watch where transmission will look for torrent files

Plex ๐Ÿ”—

  • /storage/media/plex/:/config to store the plex configuration, database and so on
  • /storage/media/:/media where plex will look for media files (tv shows, movies, music, pictures,…)

References and thanks ๐Ÿ”—

I’ve used the following repos as base and just adapt it to Fedora:

So, thank you @wernight and @elventear :)