Notifying with Pushover when Transmission is done downloading a torrent

Dec 15, 2013   #transmission  #pushover  #torrent 

DISCLAIMER First of all, lets get this out of the way: Don’t use torrents to download copyright protected material, like music and films.

Pushover

Pushover makes it easy to send real-time notifications to your Android and iOS devices.

You need to go and make an account and set up Pushover on your device. Once you have done that, create a new Application get get a unique API Token/Key.

You should be able to test your setup by modifying the following command with your own credentials. The command makes a POST request to the Pushover API.

curl -s -F "token=3847ckdjJfu49djHfiWyejnd27839F" -F "user=83Jd93Ldur2djk4yhfye844wjd3Jh4" -F "message=Hello World" https://api.pushover.net/1/messages.json

The result should be a message on your device (Phone).

The script

The script is made in Python and is really really simple. All you need to do is replace your information in the beginning.

#!/usr/bin/env python

TOKEN = "3847ckdjJfu49djHfiWyejnd27839F"
USER = "83Jd93Ldur2djk4yhfye844wjd3Jh4"
DEVICE = "My Nexus 5"

import urllib, urllib2
from os import environ

def notify(message):
        mydata=[
                ('token', TOKEN),
                ('user', USER),
                ('device', DEVICE),
                ('message', message)
        ]

        req=urllib2.Request('https://api.pushover.net/1/messages.json', urllib.urlencode(mydata))
        req.add_header("Content-type", "application/x-www-form-urlencoded")
        return urllib2.urlopen(req).read()

if __name__ == "__main__":
        notify(environ['TR_TORRENT_NAME'])

That’s it. Thats all there is to it. No one said it would be difficult. Now all we need to do is make Transmission execute the script upon finish. I have saved the file at /var/lib/transmission-daemon/script-torrent-done, but you can save it whereever. Just make sure it’s executable, by running the following command:

chmod +x /var/lib/transmission-daemon/script-torrent-done

You should be able to receive a “Hello World” message on your mobile device by running the script like so:

TR_TORRENT_NAME="Hello World" /var/lib/transmission-daemon/script-torrent-done

Transmission

Installing Transmission is beyond the scope of this post. I expect that you already have a working installation. What we need to do is to edit Transmissions configuration file. Remember to stop the program/daemon first. Otherwise it will discard your changes.

What you need to do is set the following two settings in the configuration file.

"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/var/lib/transmission-daemon/script-torrent-done"

You can find a copy of my Transmission config file here. To read more about the environment options (like TR_TORRENT_NAME) please read the official documentation.