Re: Queue Downloads

<[email protected]> Fri, 6 Sep 2024 13:20:39 +0200
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
On Fri, 6 Sep 2024 00:06:41 +0200
Diego <[email protected]> wrote:

> I see same when do use filename without a path. I think download.dpi
> needs a filename with one path-segment or more.
> 
> Send script v0.2 with a workarround (prefix "./" if there is not a "/"
> in filename)

That works. 

It might be nice to set a default download location, and also
automatically get the filename from the url with basename.

Also, if you want to make this portable so it works on other shells
than just bash, you can do something like this to get the port number:

echo $a | cut -f4- -d"'" | rev | cut -c 5- | rev

There are probably other ways to do it using sed, etc.

I attached a quick and probably incomplete example which incorporates
these ideas :)

Regards,
Alex

_______________________________________________
Dillo-dev mailing list -- dillo-dev-lx9mn2B4QYRWk0Htik3J/[email protected]
To unsubscribe send an email to dillo-dev-leave-lx9mn2B4QYRWk0Htik3J/[email protected]
qdl.sh (application/x-shellscript, 861 B)
#!/bin/sh
# QueueDownload for dillo download.dpi 
# v0.2

# define the download location
dl_dir="$HOME/download"

if [ "$#" -lt 1 ]; then
   echo "Illegal number of parameters"  >&2
   echo "USAGE: $0 URL"
   exit 2
fi

url="$1"
filename=$dl_dir/$(basename "$url")

# start dpid?
if [ ! -f "$HOME/.dillo/dpid_comm_keys" ] ; then
   dpidc stop # to be sure
   dpid &
   sleep 2s
fi

# read dpid comm port and shared secret
read prt secrt < $HOME/.dillo/dpid_comm_keys

# Hey dpid, what is downloads service/server port?
a=`nc 127.0.0.1 $prt << EOF
<dpi cmd='auth' msg='$secrt' '>
<dpi cmd='check_server' msg='downloads' '>
EOF
`

server_port=$(echo $a | cut -f4- -d"'" | rev | cut -c 5- | rev)

# Hi download.dpi, queue-download this!
nc 127.0.0.1 $server_port << EOF
<dpi cmd='auth' msg='$secrt' '>
<dpi cmd='download' url='$url' destination='$filename' '>
EOF