SCRIPT: Send iOS push notification when torrent is complete

Discussion of Transmission that doesn't fit in the other categories
krautboy
Posts: 1
Joined: Wed Jun 04, 2014 4:52 pm

SCRIPT: Send iOS push notification when torrent is complete

Post by krautboy »

Hello everyone,

i hope this is the appropriate forum/category to post this, if not please move/edit. I just wanted to share
a quick and simple script i did for use with Transmission and Boxcar. What it does is send a push notification
to your iOS device whenever a torrent has finished downloading.

All you need for this is the free Boxcar iOS app, create a account inside the app. Edit the token inside
the script. Set Transmission to call the script after a torrent is done. Thats it.

Code: Select all

#!/bin/sh

#
# Send push notification to iOS device when a torrent is complete.
#
# Requires: Boxcar account, Transmission torrent client and curl.
#
# Get the API token from the boxcar iOS app.
# Change text output below if you wish.
# Set Transmission to start script when torrent is complete.
# Make sure you keep this script as Plain-text, save changes.
# Open Terminal, go to folder of this script and do “chmod +x TransmissionBoxcar.sh”
#
#
#
# http://www.boxcar.io
# http://www.transmissionbt.com
#

#
# Available environment variables from Transmission (as of v2.83) are:
#
# TR_APP_VERSION
# TR_TIME_LOCALTIME
# TR_TORRENT_DIR
# TR_TORRENT_HASH
# TR_TORRENT_ID
# TR_TORRENT_NAME
#

# You need to change this! Get your token from the boxcar iOS app.
token=“XXXXXXXXXXXXXXXX”

# message title for the notification
title="'$TR_TORRENT_NAME' complete"

# the full message text when opened in the boxcar app (can use HTML)
message="<b>$TR_TORRENT_NAME</b> <br><br>is finished downloading. <br><br><br>$TR_TIME_LOCALTIME<br>"

# For a list of possible sounds, check the boxcar website
sound="'bird-1'"

# what shows up as source of the notification
source="Transmission"

# what url curl does connect to, do not change
url="https://new.boxcar.io/api/notifications"


# this now actually connects to boxcar and sends the notification, do not change
curl -k -d "user_credentials=$token" -d "notification[title]=$title" -d "notification[long_message]=$message" -d "notification[sound]=$sound" -d "notification[source_name]=$source" $url

#
#
# EOF
Any comments are welcome. Hope this is useful to some of you.
Mitchdzj
Posts: 1
Joined: Wed Jan 07, 2015 8:39 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by Mitchdzj »

Hello Krautboy,
Thank you for this script. I would like to give it a shot but Im a total noob and need really precise directions. My first question is if Im suppose to copy and paste the code or download the file? I don't see a download option however I could be missing it. This leads me to my next question which is what I should name the file if Im to copy and paste it into a new txt file. Is it TransmissionBoxcar.sh?
Thx again!
Mikey_
Posts: 7
Joined: Sat Jan 31, 2015 6:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by Mikey_ »

I modified krautboy's script to work with pushover instead of boxcar.

Code: Select all

#!/bin/sh

#
# Send push notification to pushover device when a torrent is complete.
#
# Requires: Pushover account, Transmission torrent client and curl.
#
# Get the API token from the pushover website.
# Change text output below if you wish.
# Set Transmission to start script when torrent is complete.
# Make sure you keep this script as Plain-text, save changes.
# Open Terminal, go to folder of this script and do “chmod +x TransmissionPushover.sh”
#
#
#
# https://pushover.net/
# http://www.transmissionbt.com
#

#
# Available environment variables from Transmission (as of v2.83) are:
#
# TR_APP_VERSION
# TR_TIME_LOCALTIME
# TR_TORRENT_DIR
# TR_TORRENT_HASH
# TR_TORRENT_ID
# TR_TORRENT_NAME
#

# Insert your own tokens
TOKEN_USER="USER_TOKEN";
TOKEN_APP="APP_TOKEN";

# Message for the notification.
MESSAGE="$TR_TORRENT_NAME finished downloading.

$TR_TIME_LOCALTIME";

PRIORITY=0;
SOUND="tugboat";
TITLE="Download complete";

TIMESTAMP=$(date +%s);

curl -s --form-string "token=$TOKEN_APP" --form-string "user=$TOKEN_USER" --form-string "timestamp=$TIMESTAMP" --form-string "priority=$PRIORITY" --form-string "sound=$SOUND" --form-string "title=$TITLE" --form-string "message=$MESSAGE" https://api.pushover.net/1/messages.json

#
#
# EOF
How to use it
Download the script into /root/ by typing:

Code: Select all

 wget -P /root/ https://dl.dropboxusercontent.com/u/10098610/Transmission/TransmissionPushover.sh
Get the app token and user token from the pushover site, and replace APP_TOKEN and USER_TOKEN with those.

To open TransmissionPushover.sh for editing, type:

Code: Select all

nano /root/TransmissionPushover.sh
After saving the script, we need to give the script permission to run by typing:

Code: Select all

chmod 0755 /root/TransmissionPushover.sh
In /etc/transmission-daemon/settings.json edit

Code: Select all

"script-torrent-done-enabled": true, 
"script-torrent-done-filename": "/root/TransmissionPushover.sh",
Attachments
2015-02-01 12.02.42 (Small).png
2015-02-01 12.02.42 (Small).png (35.49 KiB) Viewed 46827 times
Last edited by Mikey_ on Thu Feb 12, 2015 5:22 pm, edited 3 times in total.
twalsh77
Posts: 3
Joined: Wed Feb 04, 2015 3:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by twalsh77 »

Mikey_ wrote:I modified krautboy's script to work with pushover instead of boxcar.

Code: Select all

#!/bin/sh

#
# Send push notification to pushover device when a torrent is complete.
#
# Requires: Pushover account, Transmission torrent client and curl.
#
# Get the API token from the pushover website.
# Change text output below if you wish.
# Set Transmission to start script when torrent is complete.
# Make sure you keep this script as Plain-text, save changes.
# Open Terminal, go to folder of this script and do “chmod +x TransmissionPushover.sh”
#
#
#
# https://pushover.net/
# http://www.transmissionbt.com
#

#
# Available environment variables from Transmission (as of v2.83) are:
#
# TR_APP_VERSION
# TR_TIME_LOCALTIME
# TR_TORRENT_DIR
# TR_TORRENT_HASH
# TR_TORRENT_ID
# TR_TORRENT_NAME
#

# Insert your own tokens
TOKEN_USER="USER_TOKEN";
TOKEN_APP="APP_TOKEN";

# Message for the notification.
MESSAGE="$TR_TORRENT_NAME finished downloading.

$TR_TIME_LOCALTIME";

PRIORITY=0;
SOUND="tugboat";
TITLE="Download complete";

TIMESTAMP=$(date +%s);

curl -s --form-string "token=$TOKEN_APP" --form-string "user=$TOKEN_USER" --form-string "timestamp=$TIMESTAMP" --form-string "priority=$PRIORITY" --form-string "sound=$SOUND" --form-string "title=$TITLE" --form-string "message=$MESSAGE" https://api.pushover.net/1/messages.json

#
#
# EOF

How to use it
[list][*]Create a file, ex in /root/TransmissionPushover.sh
[*]Paste above text into TransmissionPushover.sh
[*]Get the app token and user token from the pushover site, and replace APP_TOKEN and USER_TOKEN with those.
[*]Open Terminal, go to folder of this script and do “chmod +x TransmissionPushover.sh”
[*]In /etc/transmission-daemon/settings.json edit[/list]
[code]"script-torrent-done-enabled": true, 
"script-torrent-done-filename": "/root/TransmissionBoxcar.sh", 
Can someone give me a how to do this in layman terms.

Thnaks,
Mikey_
Posts: 7
Joined: Sat Jan 31, 2015 6:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by Mikey_ »

The instructions in my earlier post should hold all the answers. Code tags was a bit off, so instructions was inside the code itself. If it isn't clear enough, please let me know what part you are stuck at, so I can try and improve that step.
twalsh77
Posts: 3
Joined: Wed Feb 04, 2015 3:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by twalsh77 »

Mikey_ wrote:The instructions in my earlier post should hold all the answers. Code tags was a bit off, so instructions was inside the code itself. If it isn't clear enough, please let me know what part you are stuck at, so I can try and improve that step.
If you could walk me through the whole way that would be awesome, bit of a noob with stuff like this but would love to use this script.
Mikey_
Posts: 7
Joined: Sat Jan 31, 2015 6:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by Mikey_ »

twalsh77 wrote:
Mikey_ wrote:The instructions in my earlier post should hold all the answers. Code tags was a bit off, so instructions was inside the code itself. If it isn't clear enough, please let me know what part you are stuck at, so I can try and improve that step.
If you could walk me through the whole way that would be awesome, bit of a noob with stuff like this but would love to use this script.
But I already did? What part of it is unclear?
twalsh77
Posts: 3
Joined: Wed Feb 04, 2015 3:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by twalsh77 »

Mikey_ wrote:
twalsh77 wrote:
Mikey_ wrote:The instructions in my earlier post should hold all the answers. Code tags was a bit off, so instructions was inside the code itself. If it isn't clear enough, please let me know what part you are stuck at, so I can try and improve that step.
If you could walk me through the whole way that would be awesome, bit of a noob with stuff like this but would love to use this script.
But I already did? What part of it is unclear?
Ok so the first step is to create a file called TransmissionPushover.sh right? Do I do this in textedit?
Mikey_
Posts: 7
Joined: Sat Jan 31, 2015 6:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by Mikey_ »

Updated my earlier post with instructions that should pretty much be copy&paste to get it to work.
interconnect
Posts: 26
Joined: Thu Aug 02, 2012 10:19 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by interconnect »

Hi, I've been unable to get this script to work with Boxcar. I've saved the file TransmissionBoxcar.sh and have added my Boxcar token as directed. I have saved the file in Documents/Scripts/TransmissionBoxcar.sh. I have set Transmission to call the script and have also made the script executable by doing: “chmod +x TransmissionBoxcar.sh”. When I download a torrent, I never receive a notification. Am I missing something?
Mikey_
Posts: 7
Joined: Sat Jan 31, 2015 6:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by Mikey_ »

interconnect wrote:Hi, I've been unable to get this script to work with Boxcar. I've saved the file TransmissionBoxcar.sh and have added my Boxcar token as directed. I have saved the file in Documents/Scripts/TransmissionBoxcar.sh. I have set Transmission to call the script and have also made the script executable by doing: “chmod +x TransmissionBoxcar.sh”. When I download a torrent, I never receive a notification. Am I missing something?
Try chmod 0755 on the file instead, could be because the user transmission is running under can't get to it. (also check it can get into the folders)
interconnect
Posts: 26
Joined: Thu Aug 02, 2012 10:19 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by interconnect »

Tried changing to 0755 no luck. When I run in Terminal I get {"Response":"Not Authorized"}. Should mention I am using Mac OS X. I don't know if it's a good idea to change the permission of the users folders. Is their somewhere else I can put the file?
Mikey_
Posts: 7
Joined: Sat Jan 31, 2015 6:08 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by Mikey_ »

interconnect wrote:Tried changing to 0755 no luck. When I run in Terminal I get {"Response":"Not Authorized"}. Should mention I am using Mac OS X. I don't know if it's a good idea to change the permission of the users folders. Is their somewhere else I can put the file?
That looks like the reply from their API saying you are not authorized, have you changed the token in the script?
interconnect
Posts: 26
Joined: Thu Aug 02, 2012 10:19 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by interconnect »

Mikey_ wrote:
interconnect wrote:Tried changing to 0755 no luck. When I run in Terminal I get {"Response":"Not Authorized"}. Should mention I am using Mac OS X. I don't know if it's a good idea to change the permission of the users folders. Is their somewhere else I can put the file?
That looks like the reply from their API saying you are not authorized, have you changed the token in the script?
Yes, I did. Entered by hand. Let me quadruple check it!
interconnect
Posts: 26
Joined: Thu Aug 02, 2012 10:19 pm

Re: SCRIPT: Send iOS push notification when torrent is compl

Post by interconnect »

Mikey_ wrote:
interconnect wrote:Tried changing to 0755 no luck. When I run in Terminal I get {"Response":"Not Authorized"}. Should mention I am using Mac OS X. I don't know if it's a good idea to change the permission of the users folders. Is their somewhere else I can put the file?
That looks like the reply from their API saying you are not authorized, have you changed the token in the script?
No luck. I even copied it just to be safe.
Post Reply