Let's Automate downloads so we get content we want as it becomes available, plus some automated house keeping scripts to keep things running.


Introduction 

If you had utorrent and want to replicate the ability to use RSS feeds for content with transmission then there is a great little application in Python that adds RSS feed support to Transmission Of course you can still add content using chrome and the "remote torrent adder" Chrome add on. Its a great program that support multiple transmission servers.

Background

We looked at how a small cheap low power Single Board Computer (SBC) like the Rasberry Pi, Orange Pi can be used to replace an always on PC. Sure the newest PCs use less power but I've an old PC which works fine and I'm keen to use a really low power server.

The last couple of post covered

1) Installing Armbain on Orange Pi / Rasberry Pi and installing Transmission
2) Adding a link to a NAS drive on the SBC

This final post will add automatic download of content we have subscribed too plus some housekeeping processes that will eliminate the need for maintenance.

apt-get update
apt-get install python-pip
sudo apt-get install python-setuptools

For info on setuptools this is a good source

  1. http://stackoverflow.com/questions/14426491/python-3-importerror-no-module-named-setuptools
  2.  https://www.liquidweb.com/kb/how-to-install-pip-on-ubuntu-14-04-lts/


Ok so the python language and installer code are in place. We can now check the version of pip (there Python Install Program) and update it to the latest version before we add the python programs we need

pip -V
pip install --upgrade pip
pip -V
pip install transmissionrpc
pip install feedparser

Now the programs are installed we can test a command to see if we can add downloads from a feedparser you need to change the details to match your needs

/root/feedtransmission.py "http://showrss.info/user/XXXX.rss?magnets=true&namespaces=true&name=null&quality=null&re=null" --transmission-host 192.168.x.y  --transmission-port 9091

If the parameters are correct this will add new items to the transmission for download.
The added items are logged in a file called addeditems.txt This is done to prevent repeat downloads of the SAME file as the feed provider only provides the feed it does not keep track of what you have watched.

Script to to grab new shows

We can use the command above as the basis for the script to grab new shows. Create the file

su nano \root\getnewshows.sh

Add one line (plus a blank second line)

/root/feedtransmission.py --transmission-host 192.168.0.251 --transmission-port 9091 http://showrss.info/user/14666.rss?magnets=true&namespaces=true&name=null&quality=null&re=null

Save the file (Control + X, Yes, Return), set the file as executable

chmod +x g.sh

Feedreansmission logs files it has processed in a file called addeditems.txt this file will grow and grow with new lines being added at the top of the file. Depending on your feed you can decide how many lines you want to maintain 100 is a good starting point as this will liekly be around a 2-3 weeks downloads. The commands below copy the first 100 lines of the addeditems.txt file to short.txt, delete the addeditems.txt file and rename short.txt as addeditems.txt.  If run periodically these commands will reset the size of the addeditems.txt file to 100 rows.

Space management is important especially on SBC

tail-100 /root/addeditems.txt > /root/short.txt  
rm /root/addeditems.txt 
mv /root/short.txt /root/addeditems.txt

Ok we have all the parts we need, so we can schedule them to run automatically.

Automated Housekeeping

To stop the addeditems file growing forever we can used this command. This keeps the most recent 100 lines (the ones at the top of the file)

tail-100 /root/addeditems.txt >  /root/short.txt && rm /root/addeditems.txt && root/short.txt /root/addeditems.txt

I normally set up a short python script to close completed torrents after seeding

#!/usr/bin/python
import sys, os
import feedparser
import transmissionrpc
import argparse

# Read the torrents on the server...

tc=transmissionrpc.Client('192.168.x.y',port=9091)
t=tc.get_torrents()
for key in t:
#for torrent in tc.items():
        if key.isFinished:
                print 'Removing Seed Complete', key.name
                tc.remove_torrent(key.id)
        else:
                if key.percentDone == 1:
                        print 'Removing Download Complete',key.name
                        tc.remove_torrent(key.id) #Retains data. Torrent is removed


To monitor for problems with transmission issue this command, to recent errors logged

sudo service transmission-daemon status

For details of what is being downloaded the web gui for transmission is excellent  you can access the Web UI by using the URL on your transmission server

http://192.168.x.y:9091

There are also phone apps for monitoring transmission.  Kodi has an add-on for Tracking transition downloads, and Kodi can be used to run the Transmission server (e.g. LibreElec on Rasberry Pi) however Kodi is not a good platform for automated downloads as we need to write python scripts

Setting up Crontab

Finally once everything is working we can drop items into Cron to run things for us: Lights out.

#Every 30 mins check the feed
#Remember this is a low power SBC so a feed check can take a long time especially if the server 
#is busy and the internet is slow due to active transfers
#Less than 30 mins might mean that a check has not completed before another one has started!
*/30 * * * * /usr/root/getnewshows.sh
#Every 15 minutes run a short Python script to close completed transfers
#This frees up slots and bandwidth for new transfers
*/15 * * * * /usr/bin/python /root/s.py
#At 6am every 10 days keep only the most recent 100 lines of file automatically added by the call to feedtransmission
0 6 */10 * * tail -100 /root/addeditems.txt > /root/short.txt && rm /root/addeditems.txt && mv /root/short.txt /root/addeditems.txt
#Bounce the server to keep things fresh?
#0 5 * * * reboot 

Blacklists

You might want to add a blocklist to Transimission:  https://giuliomac.wordpress.com/2014/02/19/best-blocklist-for-transmission/
This is the recommended blocklist http://john.bitsurge.net/public/biglist.p2p.gz

Working efficiently to minimised ISP meddling

Capping your upload speed may improve download performance as many ISPs in the UK limit uploads and if your outbound connection is maxed out transmission is unable to communicate with peers so the download speed collapses to a few KB. PlusNet are an example of an ISP that does this. If I cap my upload then my download performance is increased. I tend to stick with the default settings otherwise.