-
Notifications
You must be signed in to change notification settings - Fork 18
Post Processing
Watcher supplies a method to post-process completed or failed downloads for all supported download clients.
In watcher/post scripts
you will find a python script with the name of your downloader. Copy this to the appropriate scripts directory for your downloader, and rename to watcher.py if you wish.
Depending on your operating system and environment you may need to change the permissions on the script to allow execution.
Open NZBGet and set up a new category in Settings. The category name must match the category set up in Watcher's downloader settings.
In the NZBGet sidebar, open Watcher. If the option is not there you may need to restart NZBGet. Add your Watcher server information. If you are running Watcher behind a proxy such as Apache or Nginx you must use the full path to watcher, as shown in the image.
Save your settings and restart NZBGet.
Open the post-processing script in a text editor and modify the conf
entry at the top of the file. If you are running Watcher behind a proxy such as Apache or Nginx you must use the full path to watcher, as shown in the example.
conf = {
'watcherapi': '12345678987654321',
'watcheraddress': 'http://localhost:9090/watcher',
'sabkey': 'SABAPIKEY',
'sabhost': 'localhost',
'sabport': '8080'
}
Open Sabnzbd and set up a new category. The category name must match the category set up in Watcher's downloader settings.
In Switches, un-check the option to Post-Process Only Verified Jobs.
Save your settings and restart Sabnzbd.
Open the post-processing script in a text editor and modify the config section at the top of the file. If you are running Watcher behind a proxy such as Apache or Nginx you must use the full path to watcher, as shown in the example.
The category
must match the category in Settings > Downloader.
watcherapi = '12345678987654321'
watcheraddress = 'http://localhost:9090/watcher'
category = 'Watcher'
Open Deluge and open Edit > Preferences
. Click on Plugins
and enable the plugin Execute
.
Click on Execute
and add a new event Torrent Complete
.
If using Linux or a similar OS, enter the path to the post-processing script and click Add
.
If using Windows, enter the path to deluge.bat
and click Add
. In Windows, Deluge is unable to execute python directly. Deluge is, however, able to execute a batch file which in turn executes the python script. deluge.bat
must stay in the same directory as deluge.py
.
Apply the changes and restart Deluge.
Open the post-processing script in a text editor and modify the config section at the top of the file. If you are running Watcher behind a proxy such as Apache or Nginx you must use the full path to watcher, as shown in the example.
The category
must match the category in Settings > Downloader.
watcherapi = '12345678987654321'
watcheraddress = 'http://localhost:9090/watcher'
category = 'Watcher'
Close Transmission and edit Transmission's settings.json
file. This can be found in ~/.config/transmission/settings.json
.
Change the following two lines:
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/path/to/script/transmission.py",
Save your changes and start Transmission.
Getting transmission to execute python scripts directly can be hit-or-miss, so it may be necessary to use a shell script to execute the Watcher post-script:
#!/bin/sh
/usr/bin/python /path/to/script/transmission.py
Open the post-processing script in a text editor and modify the config section at the top of the file. If you are running Watcher behind a proxy such as Apache or Nginx you must use the full path to watcher, as shown in the example.
The category
must match the category in Settings > Downloader.
watcherapi = '12345678987654321'
watcheraddress = 'http://localhost:9090/watcher'
category = 'Watcher'
Open QBittorrent and open Tools > Options
. Click on Downloads
and scroll to the bottom. Enable Run external program on torrent completion
and enter the path to the post-processing script followed by "%N" "%D" "%R" "%I"
.
It my be necessary to preface the script path with python
depending on your environment.
Apply settings and restart QBittorrent.
Open the post-processing script in a text editor and modify the config section at the top of the file. If you are running Watcher behind a proxy such as Apache or Nginx you must use the full path to watcher, as shown in the example.
The label
must match the label set in Settings > Downloader.
watcherapi = '12345678987654321'
watcheraddress = 'http://localhost:9090/watcher'
category = 'Watcher'
Open your rTorrent config file, typically located at ~/.rtorrent.rc
Add the following line:
system.method.set_key = event.download.finished,Watcher,"execute={/usr/bin/python,/PATH/TO/RTORRENT.PY,\"$d.get_custom1=\",\"$d.get_name=\",\"$d.get_hash=\",\"$d.get_base_path=\"}"
Change /PATH/TO/RTORRENT.PY
to the absolute path of the rTorrent post-processing script. If your python binary is in a different location than /usr/bin/python
you may need to change that as well.
Save the file and restart rTorrent.
Currently (4/7/2018), DownloadStation does not have the ability to call scripts when Usenet downloads complete.
Due to how Synology and DownloadStation manage directories a bit of extra help is required to facilitate postprocessing.
Copy post-scripts/downloadstation.py
to your NAS, and remember its location.
Log in to your NAS using SSH.
Enter ls /usr/syno/etc/packages/DownloadStation/download
. This will show a list of files. If settings.json
does not exist and you haven't downloaded any torrents yet you may need to start a torrent to create this file.
Once you can confirm that settings.json
exists we need to stop DownloadStation from overwriting it.
Enter vi /var/packages/DownloadStation/scripts/start-stop-status
to edit DownloadStation's start-stop script.
Find the line rm ${PACKAGE_DIR}/etc/download/settings.json
and comment it out by adding a #
so it reads # rm ${PACKAGE_DIR}/etc/download/settings.json
Using PackageCenter, stop DownloadStation.
Edit DownloadStation's setting with vi /usr/syno/etc/packages/DownloadStation/download/settings.json
Change the following lines:
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/path/to/downloadstation.py"
You may now start DownloadStation through PackageCenter and end your SSH session.
Edit downloadstation.py
. Enter your Watcher address and api key. For destination
use the absolute path of the download directory you chose in your Watcher Downloader settings. This will generally begin with a volume name such as /volume1/
delay
will cause the script to wait before executing. This is neccesary because DownloadStation starts the postprocessing script before it moves the download to the download directory. This can be increased if neccesary.
Put.IO can automatically alert Watcher when the download completes. This must be enabled in the Downloader settings. In order to receive Put.IO's postprocessing request, Watcher must have an external address by forwarding its port through your router, a reverse proxy, a DDNS service, or a combination of those services. This wiki will not go into detail about how to accomplish this, but https://www.howtogeek.com/66438/how-to-easily-access-your-home-network-from-anywhere-with-ddns/ has a very thorough article explaining the process. Since your API key is sent through the postprocessing request it is strongly recommended that you use https.
If enabled, Watcher can download files from Put.IO to a local directory. After this download completes all Post Processing methods will be called, such as moving and renaming the download.
If downloading is enabled you may choose to delete the files from your Put.IO account. Files will only be deleted if all postprocessing tasks are successful.
If you need to send a post-processing request manually, or through another script, the process if fairly straightforward.
You will need to send a POST request to the Watcher server, using the url http://ipaddress:9090/postprocessing/
The request needs to pass a JSON object with the following keys:
-
apikey
Watcher's API key. -
mode
'complete' or 'failed'. -
guid
For NZB's the full download link to the file. For torrents or magnets use the torrent hash. Can benone
as well, but search results will not be marked as Bad or Finished. -
path
File path to the download. Can be a directory or single file.
A large timeout is necessary for the POST request response when moving large files across slower media. Tailor this to fit your needs.
The response from Watcher will be a JSON object with a large amount of post-processing data.
A quick example of this in python is:
import json
import urllib
import urllib2
data = {'apikey': '123456789abcdef', 'mode': 'complete', 'guid': '123456789ABCDEFEDCBA9876543210', 'parent_dir': '/home/user/downloads/Super.Cool.Movie.2017'}
post_data = urllib.urlencode(data)
request = urllib2.Request(url, post_data)
response = json.loads(urllib2.urlopen(request, timeout=300))
A typical response is as follows:
"data": {
"added_date": "2017-03-31",
"alternative_titles": "Night of the Living Dead,Night of the Living Dead 90,Night of the Living Dead '90",
"apikey": "abcdefghijklmnopqrstuvwxyz",
"audiocodec": "DD5.1",
"container": "mkv",
"digital_release_date": null,
"downloadid": null,
"finished_date": "2017-03-31",
"finished_file": "/Movies/Night of the Living Dead/Night of the Living Dead 1990 BluRay-1080P DD5.1.mkv",
"finished_score": 620,
"guid": "0123456789ABCDEF",
"imdbid": "tt0100258",
"mode": "complete",
"name": "Night of the Living Dead",
"original_file": "/Downloads/Watcher/Night of the Living Dead/Night of the Living Dead 1080P DD5.1.mkv",
"path": "/Downloads/Watcher/Night of the Living Dead/",
"plot": "In this remake of the original classic film, a group of people are trapped inside a farmhouse as legions of the walking dead try to get inside and use them for food.",
"poster": "images/poster/tt0100258.jpg",
"quality": "Default",
"rated": null,
"release_date": "1990-10-18",
"releasegroup": "",
"resolution": "BluRay-1080P",
"score": "6.7",
"status": "Disabled",
"title": "Night of the Living Dead",
"tmdbid": "19185",
"url": "https://www.themoviedb.org/movie/19185",
"videocodec": "",
"year": "1990"
},
"status": "incomplete",
"tasks": {
"0123456789ABCDEF": {
"update_MARKEDRESULTS": true,
"update_SEARCHRESULTS": true
},
"cleanup": {
"enabled": true,
"response": null
},
"mover": {
"enabled": true,
"response": true
},
"renamer": {
"enabled": true,
"response": true
},
"update_movie_status": true
}
}
response['status'] be 'finished' if all tasks complete successfully or 'incomplete' should any task fail.
While the WebUI displays the most common choices for file name or path formatting, any key in this JSON object may be used. For example, renaming the movie to {plot} {year}
will set the name of the movie to its entire plot followed byt the year. This may cause adverse side-effects due to special characters, so caution is advised.
Several other fields may be blank contingent on Watcher's ability to parse the metadata from the information given.