Context : I have a headless Ubuntu HTPC with Sickrage, Couchpotato, Deluge, and XBMC (now called Kodi) installed
Use case : I wanted to know all my current torrents status without having to daily connect to my remote Deluge
Solution : Python script that uses deluge-console to extract information from Deluge and send a Boxcar2 notification. From my iPhone, I’ve being using Boxcar2 as a replacement to the paid and well know Prowl.
How it works : A cronjob calls daily the python script at a fixed time
How it looks like on iOS (Boxcar2 app) :
Python script :
aside note : I’m not a Python developer and I don’t pretend to be one
The original script contains more stuff, and some logic was removed for the sake of the article. I’m pretty sure that for the only purpose of only sending Boxcar2 notifications, it could be trimmed down to 5 lines.
In the following script, replace REPLACE-WITH-USER-TOKEN by your boxcar2 token
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/usr/bin/python import subprocess import os import requests import sys # Use deluge-console to retrieve current downloads information delugeCMD = "deluge-console info" # Execute the command p = subprocess.Popen(delugeCMD, shell=True, stdout=subprocess.PIPE) # Store the result result = p.communicate()[0] # Cleanup torrents list result = result.rstrip() result = result.lstrip() # Exit if no torrents found if not result: sys.exit(1) # Split torrents list into an array torrentsListArr = result.split('\n \n') fullList = [] # Iterate over each torrent for torrent in torrentsListArr: # 1 line = 1 information torrentInfoArr = torrent.split('\n') t = {} for torrentInfo in torrentInfoArr: keyValueArr = torrentInfo.split(':',1) # Store infos in a dictionary t[keyValueArr[0]]=keyValueArr[1] # Once information is collected, store dictionary in list fullList.append(t) strBuilderCurrent = "<p>Current downloads are : <ul>" # Build list of active downloads for currentDownload in fullList: strBuilderCurrent += "<li><b>"+currentDownload['Name']+"</b><br>state is : "+currentDownload['State']+"</li><br>" strBuilderCurrent += "</ul></p>" # Send Boxcar notification payload = {'user_credentials': 'REPLACE-WITH-USER-TOKEN', 'notification[title]': 'Deluge current download(s)', 'notification[long_message]':strBuilderCurrent , 'notification[sound]': 'bird-1', 'notification[source_name]': 'Deluge', 'notification[icon_url]': 'http://www.jmichelgarcia.com/wp-includes/images/deluge-icon.png'} r = requests.post("https://new.boxcar.io/api/notifications", data=payload) |
And finally, the crontab (must be done using the same user used by Deluge) :
1 2 |
00 20 * * * /home/jmichelgarcia/deluge-scripts/deluge-boxcar2.py >> /home/jmichelgarcia/deluge-scripts/logs/cron.log |
Leave a Reply