Setting up a Raspberry Pi for XBMC and automatic torrenting by RSS feed
There is a single show that my wife and I watch which we torrent. I had been downloading the torrent manually and then using Videostream to cast to my TV. But having to manually torrent the show was getting annoying and I didn’t want to have to get my laptop out every time we wanted to watch the show (which has new episodes every Monday, Wednesday, and Friday).
At the same time I was growing tired of not using my Raspberry Pi from PyCon 2013. I simply had not found a use for it yet and have toyed with various ideas (the leading one has been to add a small display and have it help keep an eye on Buildbots at sprints).
But then I realized I could solve both my laziness in torrenting and use of my Raspberry Pi by making it act as an XBMC media centre that would torrent based on an RSS feed. I finally made it all work, but it was a decent amount of effort so I figured I should write the instructions down.
Raspbmc for the Pi #
I decided to go with Raspbmc for the XBMC distribution on Raspberry Pi. That was based on various reviews saying it was the easiest to get going and was the least customized behind the scenes which meant easier access to Debian functionality.
Now my personal setup did complicate the initial installation. I don’t have a desktop so no monitors in the house, and the TV is not near the router, so the only screen I had for my Pi was not near the router. This posed a problem as the simple installer for Raspbmc required a wired internet connection for initial boot. That meant downloading an image and installing it manually on to the SD card. Luckily the official Raspberry Pi docs on installing OS images is very good so it was more tedious than anything (the dd
command was not fast, but I also bet the free SD card I used is not blazingly fast either).
After that I was able to plug in the Pi, boot it up, and then flip on the WiFi for internet. Turning on the WiFi required me to go to PROGRAMS -> Raspbmc Settings and under the Network configuration tab there is Network Mode which I flipped to WiFi (various WiFi settings are also under that tab). For the next step I needed to know the IP address of the Raspberry Pi, so I went to SYSTEM -> System Info and noted the IP address as listed under Summary.
With network connectivity established, I SSH'ed into the Pi – username is pi
and the password is raspberry
by default – so I could change the password running the command sudo passwd pi
.
Transmission #
I decided to use the daemon version of Transmission as the torrenting client. While still SSH'ed into the Pi, I installed the daemon by running sudo apt-get install transmission-daemon
. I then updated it’s config by stopping the daemon with sudo /etc/init.d/transmission-daemon stop
and then editing the config with sudo vi /etc/transmission-daemon/settings.json
.
For my config I ended up changing the following:
"download-dir": "/home/pi/Transmission/Downloads",
"idle-seeding-limit": 60,
"idle-seeding-limit-enabled": true,
"incomplete-dir": "/home/pi/Transmission/Incomplete",
"incomplete-dir-enabled": true,
"ratio-limit": 2,.
"ratio-limit-enabled": true,
"rpc-enabled": true,
"rpc-password": "raspberry",
"rpc-username": "transmission",
"rpc-whitelist": "127.0.0.1,192.168.*.*",
"rpc-whitelist-enabled": true,
With those changes in place, I ran mkdir ~/Transmission; mkdir ~/Transmission/Downloads; mkdir ~/Transmission/Incomplete; chmod -R 777 ~/Transmission
. I changed what user account Transmission ran as and then restarted the daemon with sudo /etc/init.d/transmission-daemon start
and then ran sudo update-rc.d transmission-daemon defaults
to guarantee it came up at boot time (I should note the user account change I just did and have not verified it works yet; if it fails I’ll probably just go with a silly little cron job which changes the owners of the files in the directory). With all that done I verified the web UI worked by visiting http://raspberry-pi-IP-address:9091 where I set some rules so that Transmission only runs at night when my ISP gives me free bandwidth.
Flexget #
At this point I had an XBMC media centre that could torrent, but it wasn’t torrenting automatically from an RSS feed yet. For that I needed to set up Flexget. It turns out Flexget is a Python project, so I knew what was necessary to get it running with fast C extensions, etc. And since the Pi is only meant for a XBMC media centre I was able to be sloppy and install everything globally:
sudo apt-get install python-dev
sudo apt-get install python-pip
sudo pip install flexget
sudo pip install transmissionrpc
With all the software in place, I was able to configure Flexget to do what I needed by running mkdir ~/.flexget; vi ~/.flexget/config.yml
with the following contents (fill in the name of the TV show and RSS feed for your own needs):
templates:
torrent:
transmission:
host: localhost
port: 9091
username: transmission
password: raspberry
clean_transmission:
host: localhost
port: 9091
username: transmission
password: raspberry
finished_for: 6 hours
min_ratio: 2
tasks:
tv_show:
rss: http://some-rss-feed.com
series:
- Some Series Name
template: torrent
schedules:
- tasks: tv_show
interval:
hours: 1
I verified the config was sound with flexget check
and then verified the config was accurate with flexget --test execute
. Happy with everything I ran sudo crontab -e
and added the line @reboot /usr/local/bin/flexget daemon start -d
to make sure it started at reboot. I then ran /usr/local/bin/flexget daemon start -d
to get the daemon started and went to Transmissions’ web UI to cancel the torrents for episodes I had already watched.
Set up XBMC #
With files ready to watch, you need to tell XBMC about them. So I went to VIDEOS -> Files -> Add Videos… and added the directory I had Transmission download the videos to. After it indexes the directory it will show the files downloaded!
At this point you might want to add some niceties to XBMC like the Watchdog add-on so you don’t have to re-index the directory manually, or an Android controller like Yatse. Otherwise this should be enough to let a Raspberry Pi automatically download torrents and provide a way to play them on your TV!