Commit 20b7fed1 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: add aria2 backend support

parent 9f513b0b
...@@ -315,7 +315,7 @@ AXELCOMPRESSED='' ...@@ -315,7 +315,7 @@ AXELCOMPRESSED=''
WGETQ='' #-q WGETQ='' #-q
CURLQ='' #-s CURLQ='' #-s
AXELQ='' #-q AXELQ='' #-q
# TODO: aria2c ARIA2Q=''
# TODO: # TODO:
WGETNAMEOPTIONS='--content-disposition' WGETNAMEOPTIONS='--content-disposition'
CURLFILENAMEOPTIONS='--remote-name --remote-time --remote-header-name' CURLFILENAMEOPTIONS='--remote-name --remote-time --remote-header-name'
...@@ -327,9 +327,11 @@ CURLTRUSTSERVERNAMES='' ...@@ -327,9 +327,11 @@ CURLTRUSTSERVERNAMES=''
CURLOUTPUTDIR='' CURLOUTPUTDIR=''
WGETOUTPUTDIR='' WGETOUTPUTDIR=''
USEOUTPUTDIR='' USEOUTPUTDIR=''
ARIA2OUTPUTDIR=''
WGETNODIRECTORIES='' WGETNODIRECTORIES=''
WGETCONTINUE='' WGETCONTINUE=''
CURLCONTINUE='' CURLCONTINUE=''
ARIA2CONTINUE=''
WGETTIMEOUT='' WGETTIMEOUT=''
CURLMAXTIME='' CURLMAXTIME=''
WGETREADTIMEOUT='' WGETREADTIMEOUT=''
...@@ -360,6 +362,7 @@ set_quiet() ...@@ -360,6 +362,7 @@ set_quiet()
WGETQ='-q' WGETQ='-q'
CURLQ='-s' CURLQ='-s'
AXELQ='-q' AXELQ='-q'
ARIA2Q=''
quiet=1 quiet=1
} }
...@@ -368,6 +371,7 @@ unset_quiet() ...@@ -368,6 +371,7 @@ unset_quiet()
WGETQ='' WGETQ=''
CURLQ='' CURLQ=''
AXELQ='' AXELQ=''
ARIA2Q=''
quiet='' quiet=''
} }
...@@ -485,10 +489,11 @@ while [ -n "$1" ] ; do ...@@ -485,10 +489,11 @@ while [ -n "$1" ] ; do
shift shift
CURLOUTPUTDIR="--create-dirs --output-dir $1" CURLOUTPUTDIR="--create-dirs --output-dir $1"
WGETOUTPUTDIR="-P $1" WGETOUTPUTDIR="-P $1"
ARIA2OUTPUTDIR="-d $1"
USEOUTPUTDIR="$1" USEOUTPUTDIR="$1"
;; ;;
-U|-A|--user-agent) -U|-A|--user-agent)
user_agent="Mozilla/5.0 (X11; Linux $arch) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36" user_agent="Mozilla/5.0 (X11; Linux $arch) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36" #"
WGETUSERAGENT="-U '$user_agent'" WGETUSERAGENT="-U '$user_agent'"
CURLUSERAGENT="-A '$user_agent'" CURLUSERAGENT="-A '$user_agent'"
AXELUSERAGENT="--user-agent='$user_agent'" AXELUSERAGENT="--user-agent='$user_agent'"
...@@ -552,6 +557,7 @@ while [ -n "$1" ] ; do ...@@ -552,6 +557,7 @@ while [ -n "$1" ] ; do
-c|--continue) -c|--continue)
WGETCONTINUE="$1" WGETCONTINUE="$1"
CURLCONTINUE="-C -" CURLCONTINUE="-C -"
ARIA2CONTINUE="--continue=true"
;; ;;
-T|--timeout) -T|--timeout)
if [ -z "$argvalue" ];then if [ -z "$argvalue" ];then
...@@ -934,6 +940,7 @@ fi ...@@ -934,6 +940,7 @@ fi
WGET="$(print_command_path wget)" WGET="$(print_command_path wget)"
CURL="$(print_command_path curl)" CURL="$(print_command_path curl)"
ARIA2="$(print_command_path aria2)"
ORIG_EGET_BACKEND="$EGET_BACKEND" ORIG_EGET_BACKEND="$EGET_BACKEND"
...@@ -964,6 +971,13 @@ case "$orig_EGET_BACKEND" in ...@@ -964,6 +971,13 @@ case "$orig_EGET_BACKEND" in
curl) curl)
[ -n "$CURL" ] || fatal "There are no curl in the system but you forced using it via EGET_BACKEND. Install it with $ epm install curl" [ -n "$CURL" ] || fatal "There are no curl in the system but you forced using it via EGET_BACKEND. Install it with $ epm install curl"
;; ;;
*/aria2)
ARIA2="$orig_EGET_BACKEND"
[ -x "$ARIA2" ] || fatal "There are no $orig_EGET_BACKEND in the system but you forced using it via EGET_BACKEND. Install it with $ epm install aria2"
;;
aria2)
[ -n "$ARIA2" ] || fatal "There are no curl in the system but you forced using it via EGET_BACKEND. Install it with $ epm install aria2"
;;
'') '')
[ -n "$WGET" ] && EGET_BACKEND="wget" [ -n "$WGET" ] && EGET_BACKEND="wget"
[ -z "$EGET_BACKEND" ] && [ -n "$CURL" ] && EGET_BACKEND="curl" [ -z "$EGET_BACKEND" ] && [ -n "$CURL" ] && EGET_BACKEND="curl"
...@@ -984,6 +998,7 @@ url_scat() ...@@ -984,6 +998,7 @@ url_scat()
local URL="$1" local URL="$1"
cat "$(path_from_url "$URL")" cat "$(path_from_url "$URL")"
} }
# download to default name of to $2 # download to default name of to $2
url_sget() url_sget()
{ {
...@@ -1233,13 +1248,65 @@ url_get_response() ...@@ -1233,13 +1248,65 @@ url_get_response()
echo "$answer" echo "$answer"
} }
elif [ "$EGET_BACKEND" = "aria2" ] ; then
__aria2()
{
docmd $ARIA2 $ARIA2Q $ARIA2OUTPUTDIR $ARIA2CONTINUE "$@"
}
# put remote content to stdout
url_scat()
{
local URL="$1"
download_with_mirroring __aria2 -x1 -s1 --allow-piece-length-change=false -o - "$URL" && return
unset_quiet
download_with_mirroring __aria2 -x1 -s1 --allow-piece-length-change=false -o - "$URL"
}
# download to default name of to $2
url_sget()
{
local URL="$1"
if [ "$2" = "/dev/stdout" ] || [ "$2" = "-" ] ; then
scat "$URL"
return
elif [ -n "$2" ] ; then
download_with_mirroring __aria2 -x1 -s1 --allow-piece-length-change=false -o "$2" "$URL"
return
fi
# TODO: overwrite always
download_with_mirroring __aria2 "$URL"
}
url_pget()
{
#[ -n "$USEOUTPUTDIR" ] || fatal "USEOUTPUTDIR is not set"
echo "$@" | xargs -n1 | download_with_mirroring __aria2 -i-
}
# left wget here
url_get_response()
{
local URL="$1"
local answer
answer="$(quiet=1 __wget --timeout 20 --tries 1 --spider -S "$URL" 2>&1)"
# HTTP/1.1 405 Method Not Allowed
# HTTP/1.1 404 Not Found
if echo "$answer" | grep -q "^ *HTTP/[12.]* 40[45]" ; then
(quiet=1 __wget -O/dev/null --header="Range: bytes=0-0" -S "$URL" 2>&1)
return
fi
echo "$answer"
}
else else
fatal "Unknown EGET_BACKEND '$EGET_BACKEND', logical error." fatal "Unknown EGET_BACKEND '$EGET_BACKEND', logical error."
fi fi
# Common code for both wget and curl (http related) # Common code for both wget and curl and aria2 (http related)
if [ "$EGET_BACKEND" = "wget" ] || [ "$EGET_BACKEND" = "curl" ] ; then if [ "$EGET_BACKEND" = "wget" ] || [ "$EGET_BACKEND" = "curl" ] || [ "$EGET_BACKEND" = "aria2" ] ; then
url_get_headers() url_get_headers()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment