Thursday, October 1, 2015

Make your Raspberry Pi download your favourite TV shows as they are released

That's a long title! But it explains the purpose of this blog, I will detail the steps needed to make your raspberry pi do all the work for you, your Pi will follow your favourite TV shows, and when a new episode is released, it downloads it automatically for you and sends you an email saying it is there, ready for you to watch.

High level steps:
  1. Create a list of your favourite TV shows on http://showrss.info/
  2. Setup the needed software on the Pi (Flexget, Transmission, cron and optionally Kodi)
  3. Write the automation script (or copy it from here) and schedule it to run automatically 
Let's talk about these steps one by one

Create a list of your TV shows on showrss.info

What I said about your Pi following your shows and download them as they are released sounds too good to be true, how will your Pi know when an episode is released? Thanks to RSS feeds this is possible. Some web sites follow TV shows and when a new episode is released they update an RSS feed with the new episode information and download links. I am using showrss.info as it allows you to create a personal RSS feed that has only updates of your personal shows and not everything. Your Pi listens to this personal feed and downloads whatever is in it, this way when you want to start following a new TV show all you need to do is to add is to showrss.info and your Pi will start following and downloading it automatically. 

  1. Head to showrss.info and create a new account.
  2. Go to the "Your shows" section and add your favourite TV shows. 
  3. Go to the "feeds" section and click "Generate" beside your personal feed section and save the URL returned for usage on the Pi

Setup software on the Pi

The below steps assume that you are using a debian based distribution on the Pi. I am personally using OSMC which a Kodi build based on debian, and I have to say it made my life much easier installing and configuring this automation. Here are the software tools needed for this setup

Flexget

The maestro of our setup, Flexget is an automation tool to work with content downloads, it works with torrents, podcasts, ebooks and it it can parse content sources from RSS, html, csv and much more. Flexget is python based

Transmission

Transmission is a lightweight torrent client that Flexget will use to download your TV shows.

Kodi 

So what do you do after you download a new episode? You watch it! I use Kodi to watch the downloaded content on my TV. Kodi has so many builds with different flavours, but I am using OSMC which is very easy to install and use, and it is debian based so it is very powerful to configure. 

Cron

Cron is a scheduling tool that is a part of linux, we use it to run the Flexget script on regular basis to keep checking for new releases. cron should be there by default on most linux distributions, but I did not find it on OSMC so installed it. 

Installation steps

OSMC
Follow the steps in https://osmc.tv/download/ to download and install OSMC. It is pretty easy and UI based! Then connect to it using SSH and run the below commands.

Prep
sudo apt-get update

Flexget
sudo apt-get install python-pip 
sudo pip install flexget 
sudo pip install transmissionrpc

test flexget installation by running flexget -V. You should get a valid version

Transmission
You can install transmission from the command line using 
sudo apt-get install transmission-daemon
Or you can install it from OSMC services section. 

Cron
sudo apt-get install cron

Create the automation script (or use mine! )

Flexget automation script is a file written in YAML that describes the different tasks to be carried out by Flexget. the file should be named config.yml and saved somewhere on the Pi (I put it in /home/osmc/flexget) I am attaching mine here at the end of the post. You should replace all of the upper case variables with your own values. Here are the highlight of the automation file

Task Download_TV_Shows: This is the meat of the file, this tasks gets the RSS feed from showrss, parses it to get the download location, and passes it to transmission to download into the specified path. I use a path pattern of YOUR_TV_SHOWS_ROOT_DIRECTORY_PATH/SERIES_NAME/SEASON_NUMBER/FILE_NAME

EMAIL: After flexget finishes running this task, it sends me an email that includes what was downloaded, and in case of errors it sends me the error message

CLEAN Transmission: This task will clean the completed downloads off transmission after 3 days.

Steps:

  1. Create the yml file in /home/osmc/flexget/config.yml
  2. Test the syntax correctness by running going into /home/osmc/flexget and running flexget --test
  3. Do an inital run by going into /home/osmc/flexget and running flexget execute

Schedule the script to run regularly

  1. Run crontab -e
  2. Add this line to the end of the crontab file 0 3,6,9,12,15 * * * /usr/local/bin/flexget -c /home/osmc/flexget/config.yml execute
  3. The line above will schedule the script to run at 3 AM,  6 AM, 9 AM, 12 PM and 3 PM everyday. 
  4. Press Ctrl + O to write the file, then press enter to accept the name, then press Ctrl + X to exit

One more thing you can do to make your life easier is to add  YOUR_TV_SHOWS_ROOT_DIRECTORY_PATH  to OSMC as a file source, and install the Watchdog plugin to make OSMC refresh your library each time a file is added. 

Enjoy!






email:
    from: YOUR_GMAIL_ACCOUNT
    to: YOUR_GMAIL_ACCOUNT
    smtp_host: smtp.gmail.com
    smtp_port: 587
    smtp_username: YOUR_GMAIL_ACCOUNT
    smtp_password: YOUR_GMAIL_PSSWORD
    smtp_tls: yes
tasks:
  Download_TV_Shows:
    rss: YOUR_SHOWRSS_PERSONAL_FEED_URL
    all_series: yes
    transmission:
      host: localhost
      port: 9091
      username: YOUR_TRANSMISSION_USERNAME
      password: YOUR_TRANSMISSION_PASSWORD
      path: YOUR_TV_SHOWS_ROOT_DIRECTORY_PATH/{{series_name}}/Season {{series_season}}
      ratio: 1
  Cleanup:
    clean_transmission:
      host: localhost
      port: 9091
      username: YOUR_TRANSMISSION_USERNAME
      password: YOUR_TRANSMISSION_PASSWORD
      finished_for: 3 days

2 comments:

Unknown said...

I am getting :

pi@raspberrypi:~/flexget $ flexget -c config.yml
usage: flexget [-h] [-V] [--test] [-c CONFIG] [--logfile LOGFILE]
[--loglevel LEVEL] [--bugreport] [--profile [OUTFILE]] [--cron]
[--debug-db-sessions] [--debug-warnings]
...
flexget: error: too few arguments

when running flexget --test

Unknown said...

hi, what am i doing wrong if im getting this reply? im using the new notify script

pi@raspberrypi:~ $ flexget --test execute
2018-04-23 23:58 INFO manager Test mode, creating a copy from database ...
2018-04-23 23:58 CRITICAL manager [/] The keys `via`, `finished_for`, `Download_TV_Shows`, `notify`, `smtp_tls`, `path`, `port`, `from`, `smtp_port`, `to`, `clean_transmission`, `smtp_username`, `username`, `all_series`, `smtp_password`, `smtp_host`, `host`, `ratio`, `password`, `rss`, `task`, `transmission`, `Cleanup` are not valid here.
2018-04-23 23:58 CRITICAL manager [/tasks] Got `None`, expected: dict
2018-04-23 23:58 CRITICAL manager Failed to load config file: Did not pass schema validation.
Could not start manager: Did not pass schema validation.