-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl
executable file
·100 lines (90 loc) · 3.29 KB
/
dl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
for dep in axel cut bc bash tput
do command -v "$dep" >/dev/null 2>&1 || { echo "dependency $dep not found. please make the command available in the PATH by installing it/changing the path/moving the binary to a place in the path."; exit 255; }
done
trap "tput cnorm; exit 130" SIGINT
function syntax {
exit="$1"
[[ "$1" == '' ]] && exit=1
echo -e "usage: $0 [-h] [-q] [-a opts] url\n"\
"-h : display this\n"\
"-q : dont show axel output except progress bar\n"\
" : (if you dont want the progress bar, call axel, not me.)\n"\
"-a opts : pass arguments directly to axel.\n"\
"-o file : saves output to file\n"\
"-H : show axel help page\n"\
"-i : show download speed"\
"-d : use axels download bar but filter out extra lines (auto-uses -q) (disabled)"
exit "$exit"
}
default=false
quiet=false
info=false
while getopts ":Hhqa:o:id" arg;do
case $arg in
h ) syntax 0;;
q ) quiet=true;;
a ) opts="$OPTARG";;
o ) outfile="-o '$OPTARG'";;
H ) axel --help; exit 0;;
d ) default=true; quiet=true ;;
i ) info=true;;
* ) syntax 1
esac
done
shift $((OPTIND-1))
if [[ "$1" == "--" ]]; then url="$2"; else url="$1"; fi
if [[ "$url" == '' ]]
then syntax 1
fi
# outfile="-o '${outfile[-1]}'"
# # echo "url: $url; quiet: $quiet; help: $help"
# # echo "axel opts: '$opts'"
tput civis
opts="${opts[*]}"
eval "axel $opts $outfile $url" 2>&1 | {
while read -r line; do
pers="$(echo "$line" | cut -d ']' -f '1' -s | cut -c '3-4')"
# echo "$line:::$pers"
#[[ "$line" == "[ 0%] "*" ["*"KB/s]"* ]] && pers="0"
pers="${pers// /}"
if [[ "$pers" =~ ^[0-9]+$ ]] && ! $default
then [[ "$pers" == 00 ]] && pers=100
dispers="[$pers%] "
cols=$(($(tput cols)-${#dispers}-2))
$info && {
infoline="$(echo "$line" | cut -d '[' -f '3,4' -s)"
# infoline="${infoline// /}"
infoline=" [${infoline}"
cols=$((cols-${#infoline}))
}
# eval "printf ' %.0s' {1..$(($(tput cols)-1))}" && echo -ne '\r'
# echo -n "$dispers"
out="$dispers"
ch="$(echo "$cols*($pers/100)" | bc -l | cut -d . -f 1)"
# echo "$cols="
# echo "$ch-"
# echo "$(($cols-$ch-1))"
# out="$out$(eval "printf '\e[0;32m#%.0s\e[0m' {1..$ch}")"
out="$out$(eval "printf '#%.0s' {1..$ch}")"
out="$out$(eval "printf '=%.0s' {1..$(($cols-$ch))}")"
# $info && echo -n "$infoline"
$info && out="$out$infoline"
echo -ne "${out}"
# eval "printf '*%.0s' {1..$(($(tput cols)-${#out}-1))}"
echo -ne "\r"
# elif [[ "$line" == "Initializing download: "* ]]
# then echo "axel is now downloading $(cut -d ':' -f '2' <<< "$line")"
elif [[ "$line" == "["*"%] "*" ["*"KB/s]"* ]] || [[ "$line" == *"."*"["*"KB/s]"* ]]
then
if $default
then echo -ne "\r$line"
fi
elif [[ "$line" == '' ]]
then :
else $quiet || { eval "printf ' %.0s' {1..$(($(tput cols)-1))}"; echo -e "\raxel: $line" ;}
fi
done
}
tput cnorm
echo ''