Created
December 25, 2014 21:52
-
-
Save felix-orduz/8a4425d2f566f41b1e96 to your computer and use it in GitHub Desktop.
wget con barra de progreso
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DOWNLOAD() { | |
| rand="$RANDOM `date`" | |
| pipe="/tmp/pipe.`echo '$rand' | md5sum | tr -d ' -'`" | |
| mkfifo $pipe | |
| wget -c $1 2>&1 | while read data;do | |
| if [ "`echo $data | grep '^Length:'`" ]; then | |
| total_size=`echo $data | grep "^Length:" | sed 's/.*\((.*)\).*/\1/' | tr -d '()'` | |
| fi | |
| if [ "`echo $data | grep '[0-9]*%' `" ];then | |
| percent=`echo $data | grep -o "[0-9]*%" | tr -d '%'` | |
| current=`echo $data | grep "[0-9]*%" | sed 's/\([0-9BKMG.]\+\).*/\1/' ` | |
| speed=`echo $data | grep "[0-9]*%" | sed 's/.*\(% [0-9BKMG.]\+\).*/\1/' | tr -d ' %'` | |
| remain=`echo $data | grep -o "[0-9A-Za-z]*$" ` | |
| echo $percent | |
| echo "#Downloading $1\n$current of $total_size ($percent%)\nSpeed : $speed/Sec\nEstimated time : $remain" | |
| fi | |
| done > $pipe & | |
| wget_info=`ps ax |grep "wget.*$1" |awk '{print $1"|"$2}'` | |
| wget_pid=`echo $wget_info|cut -d'|' -f1 ` | |
| zenity --progress --auto-close --text="Connecting to $1\n\n\n" --width="350" --title="Downloading"< $pipe | |
| if [ "`ps -A |grep "$wget_pid"`" ];then | |
| kill $wget_pid | |
| fi | |
| rm -f $pipe | |
| } | |
| if [ $1 ];then | |
| DOWNLOAD "$1" | |
| else | |
| dllink=$(zenity --entry --text "Your download link :" --width="350" --entry-text "" --title="Download url") | |
| if [ $dllink ];then | |
| DOWNLOAD "$dllink" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment