Forum

Full Version: Tranmission complete script with Notify my android
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,
been fiddling around with my transmission done script thoughed i put it up here.

Its made out of 2 scripts t-clean.sh & notify.sh you can put them together in your /home/xbian/ dir and point transmisson to /home/xbian/t-clean.sh for your done-script.

- you need curl to make it work, make sure you got it installed. Think it can be installed with the xbian menu, otherwise run sudo apt-get install curl
- after that you need an Notify my Android account and make an API-key https://www.notifymyandroid.com/
- You put that api-key in the notify.sh at INSERT_API_HERE (between the "")
- After that install NMA on your android device and login.

Now if you got a download done in transmission it will remove it directly and send you a push notification on your device with time & name. So you know whats up.

Hope anyone can use this. feel free to do with it what you fancy. if you got any update or improvements please post them in this thread so xbians can use it.
Cheers

t-clean.sh (dont forget to put in your port/user/pass)
Code:
#!/bin/bash
PORT="INSERT_PORT"
USER="INSERT_USER"
PASS="INSERT_PASS"



transmission-remote $PORT --auth $USER:$PASS  --torrent $TR_TORRENT_ID --remove

TORRENT="$TR_TORRENT_NAME"

export TR_TORRENT_NAME
export TORRENT
source /home/xbian/notify.sh

notify.sh (I've cannabalised a script from Author : Markp1989@gmail.com Version: 25JULY2011 Author : chiristod@illinois.edu Version: 12FEBRUARY2015 props go to them)
Code:
#!/bin/bash
################################################################################​#########
### Script for sending notifications using "Notify My Androids" API                     #
################################################################################​#########
## Requirements:    curl                                                                #
################################################################################​#########
## Usage: input your NMA API                                                              #
################################################################################​#########
## API Documentation:    https://www.notifymyandroid.com/api.jsp                         #
################################################################################​#########

APIkey="INSERT_API_HERE"

TORRENT="$TR_TORRENT_NAME"


function error_exit {
##this function is used to exit the program in the event of an error.
    echo "[ error ] Notification not sent:" >> /home/xbian/log/notify-log.txt
    echo "$errormessage" >> /home/xbian/log/notify-log.txt
    exit 1

}
function clean_exit {
    echo "[ info ] Notification sent"
    ##removing output file when notification was sent okay
    rm "$notifyout"
    exit 0
}



##renaming parameters to make rest of the code more readable.
application="XBian"
event="Download Finished"
description="$(date '+%Y %b %d %H:%M') $TORRENT has been downloaded"
priority=0

##the urls that are used to send the notification##
baseurl="https://www.notifymyandroid.com/publicapi"
verifyurl="$baseurl/verify"
posturl="$baseurl/notify"

##choosing a unique temp file based on the time (date,month,hour,minute,nano second),to avoid concurent usage interfering with each other
notifyout=/tmp/androidNotify$(date '+%d%m%Y%H%M%S%N')

function send_notification {
    ##sending the notification using curl
    curl --silent --data-ascii "apikey=$APIkey" --data-ascii "application=$application" --data-ascii "event=$event" --data-asci "description=$description" --data-asci "priority=$priority" $posturl -o $notifyout
}

function check_notification {
    ##checking that the notification was sent ok.
    if [ ! -f $notifyout ]; then
        errormessage="curl failed"
        error_exit
    fi
    ##api returns message 200 if the notification was sent
    if grep -q 200 $notifyout; then
        clean_exit
    else
        ##getting the error reported by the API, this may break if the API changes its output, will change as soon as I can find a commandline xml parser
        errormessage="$(cut -f4 -d'>' $notifyout | cut -f1 -d'<')"
        error_exit
    fi
}

##running the functions
send_notification
check_notification
Reference URL's