I want to write a bash function to both start downloading a file and open it in a video player; I don't know how to get the path of the file being downloaded though:
function dl-and-stream() {
aria2c "$1" &
sleep 30
mpv #What to put here
}
PS: This is not my only use case, and I’m aware of --out
, but I like to keep the original file name.
Update: My use cases can be fulfilled via --on-download-complete
(and other event handlers), but I still prefer not using that if possible. (Because they need the creation of additional script files.)
aria2c
provides an--on-download-start
option which lets you run a command as soon as the download started. To use it to start playing the file, write a script withand run
aria2c
like that in your function:That has the extra advantage that you don’t need to
sleep
for a fixed amount of time, which may not be enough in some cases. In fact, you don’t need a function at all with this solution, a simplealias
does it: