Download events in aria2
In my previous post, I have demonstrated how to use
aria2 as the default download manager
on Unix/Linux and how to
integrate aria2 into Conkeror.
In this post, I’m going to show a simple tip that can cause aria2 to display
notification when it finishes downloading. By default, aria2 provides some input
arguments which are the event handlers for download hooks. Those events include
--on-bt-download-complete, --on-download-complete, --on-download-error,
--on-download-pause, --on-download-start, --on-download-stop. The solution
is to pass a shell script to the event and use that bash script to activate
notification program. For example
$ aria2c --on-download-complete="/path/to/notification/script.sh" http://example.com/file.isoYou can also pass the event handler command to the aria2 command for starting it as daemon or on RPC protocol. If you are using the command from my previous post, the command will look like this
$ touch /path/to/download/folder/session.txt && aria2c --enable-rpc --rpc-listen-all --save-session=/path/to/download/folder/session.txt --input-file=/path/to/download/folder/session.txt -x16 -s16 -k1M --dir=/path/to/download/folder --daemon --on-download-complete=/path/to/notification/script.shWhen aria2 finishes downloading, it will run the –on-download-complete script and pass 3 arguments, the third one is the path to the downloaded file. The content of the notification script.sh file should look similar to this
#!/bin/sh
notification-command "Download complete $3"