-
Notifications
You must be signed in to change notification settings - Fork 302
DoneCmdUsage
DoneCmd is an external program called when a task is finished. The program must be executable (eg: mode 0755).
When DoneCmd is called, the following environment variables are set:
CLD_DIR=/path/of/DownloadDirectory
CLD_PATH=Torrent-Downloaded-File-OR-Dir
CLD_SIZE=46578901
CLD_TYPE=file
CLD_HASH=12345678901234567890abcdefgabcdefg
CLD_RESTAPI=127.0.0.1:2001
CLD_STARTTS=1614926125
CLD_FILENUM=1
-
CLD_DIRis same withDownloadDirectoryin the config. -
CLD_PATHis the downloaded file path, joiningCLD_DIRandCLD_PATHwill be the absolute path to the downloaded file. -
CLD_SIZEis the file size in bytes. WhenCLD_TYPE=torrent, is the whole torrent size. -
CLD_TYPEis the calling event type, for each torrent taskDoneCmdwill be called at least twice (multiple times if the torrent has more than one file), once withCLD_TYPE=filewhen a file is completed, andCLD_TYPE=torrentwhen the whole torrent completed. -
CLD_HASHis the hash of the torrent. -
CLD_RESTAPIis the--rest-apiargument of the program. -
CLD_STARTTSis the Unix timestamp that the task was started.
An example of bash script using this env varilables to do useful things, is provided under scripts/doneCMD.sh
SimpleTorrent logs details when running DoneCmd, heres example output from journalctl:
Aug 19 16:41:41 host.net cloud-torrent[8522]: [DoneCmd] [/usr/local/bin/add2aria2.py] environ:[LANG=en_US.utf8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin HOME=/var/lib/nginx LOGNAME=nginx USER=nginx SHELL=/sbin/nologin CLD_DIR=/srv/http/dl/cloud CLD_PATH=魔道祖师 羡云篇 01.mp4 CLD_SIZE=324558998 CLD_TYPE=file]
Aug 19 16:41:42 host.net cloud-torrent[8522]: [DoneCmd] Output: ID:[256] AddURL: xxxx----.mp4
The first line is the external program and it's starting environment virables, other than those starts with CLD_, they are derived from SimpleTorrent.
The second line is the stdout/stderr output combined from the external program.
If there were errors running the program, the message also logged here.
Note that there maybe spaces in the variable CLD_PATH, when the program is an shell script, remember to double quote it: echo "$CLD_PATH"
You don't need to wait for a downloaded torrent to test a script for doneCMD. Use the bash env can easily produce the running environment.
In the following example, prefix with env ... gives all the environments like SimpleTorrent does to doneCMD.sh.
The switch bash -x will show details on every line executed.
env \
CLD_DIR=/srv/http/dl/cloud \
CLD_RESTAPI=localhost:3001 \
CLD_PATH="Some Downloaded File.mp4" \
CLD_HASH=12345678901234567890abcdefgabcdefg \
CLD_TYPE=file \
CLD_SIZE=789554712 \
CLD_STARTTS=1629104374 \
CLD_FILENUM=1 \
bash -x /path/to/your/doneCMD.sh