There are two mistakes one can make along the road to truth...not going all the way, and not starting.
--Prince Gautama Siddharta
#ubuntuforums web interface
wow I like sed more and more but even more the examples helping me understand the manual.
This was cool
Hi I used this hack for a while but now in jaunty things seem to be different? Anyway, the second line works for me in jaunty:
my wget version in jaunty is GNU Wget 1.11.4. To mee it seems spaces are not backslashed anymore (?)Code:wget http://(url) 2>&1 | sed -u 's/.*\ \([0-9]\+%\)\ \+\([0-9.]\+\ [KMB\/s]\+\)$/\1\n# Downloading \2/' | zenity --progress --title="Downloading" --auto-close wget http://(url) 2>&1 | sed -u 's/.* \([0-9]%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --title="Downloading" --auto-close
Sorry, I forgot to include more than one percentage digit, see the \+ just before % below:
Anyway, this version includes Estimated Time of Arrival for the impatientCode:second line: wget http://(url) 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --title="Downloading" --auto-close
This is good, but there is still some problems. instead I use named pipes and not anonymous pipes to transfer wget result to zenity . my code is :
I'm still working on regexp and I know there is a lot better regexp than mine in this code but its work .Code: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
You can use DOWNLOAD function for your scripts, just take one argument (download link) but I wrote complete example too.
Again thanks to original idea of this script, the idea is from the 8th and 3rd post of this thread.
The complete information about this code available on my blog but in Persian (farsi)
Last edited by fzerorubigd; August 18th, 2010 at 08:56 AM.
Could you adapt the script to work with axel, instead of wget?
hope to see a script for axel please.
i tried but not working
Code:axel -a http://(url) 2>&1 | sed 's/.* \([0-9]\+%\).* \([0-9]\+.[0-9]\)\(.*\)].*\[\([0-9]\+:[0-9]\+\).*/\1\n#Speed: \2\3 - Estimated time: \4/' | zenity --progress --title="Downloading"
Bookmarks