[Showcase] GUI frontend for wget with multiple progress bars

439 views
Skip to first unread message

Glutanimate

unread,
May 15, 2014, 9:47:38 PM5/15/14
to yad-c...@googlegroups.com
Hi everyone,

I recently wrote a YAD script in answer to an Askubuntu question. It uses YAD's --multi-progress option to monitor downloads with wget. Joe suggested I post it here, so here we go:

#!/bin/bash
# NAME:         yad_wget
# VERSION:      0.2
# AUTHOR:       (c) 2014 Glutanimate
# DESCRIPTION:  graphical frontend to wget in form of a yad script
# FEATURES:     - display progress of multiple simultaneous downloads
#               - set maximum number of simultaneous downloads
# DEPENDENCIES: yad
#
#               Install yad on Ubuntu with:
#
#                   sudo add-apt-repository ppa:webupd8team/y-ppa-manager
#                   sudo apt-get update
#                   sudo apt-get install yad
#
# LICENSE:      GNU GPLv3 (http://www.gnu.de/documents/gpl-3.0.en.html)
#
# NOTICE:       THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 
#               EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 
#               PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR 
#               IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
#               AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 
#               PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
#               YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
#
#               IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 
#               COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 
#               PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 
#               INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE 
#               THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED 
#               INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE 
#               PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 
#               PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#
# USAGE:        yad_wget <space-delimited URLs>
#               Closing the yad dialog will terminate all downloads in progress
# Variables and settings
MAXDLS="5" # set maximum number of simultaneous downloads
URILIST="$@" # gets list of URIs from stdin
USAGE="$0 <space-delimited URLs>"
# Set GUI variables up
TITLE="YAD wget downloader"                 # dialog title
TEXT="<b>Downloads</b> in progress:"        # dialog text
ICON="emblem-downloads"                     # window icon (appears in launcher)
IMAGE="browser-download"                    # window image (appears in dialog)
#URILIST="http://proof.ovh.net/files/100Mb.dat http://speedtest.wdc01.softlayer.com/downloads/test10.zip http://cachefly.cachefly.net/100mb.test"
# Usage checks
if [[ -z "$URILIST" ]]
  then
      echo "Error: No arguments provided"
      echo "Usage: $USAGE"
      exit 1
fi

# download file and extract progress, speed and ETA from wget
# we use sed regex for this
# source: http://ubuntuforums.org/showthread.php?t=306515&page=2&p=7455412#post7455412
# modified to work with different locales and decimal point conventions
download(){
    wget  "$1" 2>&1 | sed -u \
    "s/.* \([0-9]\+%\)\ \+\([0-9,.]\+.\) \(.*\)/$2:\1\n$2:# Downloading at \2\/s, ETA \3/"
    RET_WGET="${PIPESTATUS[0]}"             # get return code of wget
    if [[ "$RET_WGET" = 0 ]]                # check return code for errors
      then
          echo "$2:100%"
          echo "$2:#Download completed."
      else
          echo "$2:#Download error."
    fi
}

# compose list of bars for yad
for URI in $URILIST; do                     # iterate through all URIs
    FILENAME="${URI##*/}"                   # extract last field of URI as filename
    YADBARS="$YADBARS --bar=$FILENAME:NORM" # add filename to the list of URIs
done
IFS=" "
COUNTER="1"
DYNAMIC_COUNTER="1"
# main
# iterate through all URIs, download them in the background and 
# pipe all output simultaneously to yad
# source: http://pastebin.com/yBL2wjaY
for URI in $URILIST; do
    if [[ "$DYNAMIC_COUNTER" = "$MAXDLS" ]] # only download n files at a time
      then
          download "$URI" "$COUNTER"        # if limit reached wait until wget complete
          DYNAMIC_COUNTER="1"               # before proceeding (by not sending download() to bg)
      else
          download "$URI" "$COUNTER" &      # pass URI and URI number to download()
          DYNAMIC_COUNTER="$[$DYNAMIC_COUNTER+1]"
    fi
    COUNTER="$[$COUNTER+1]"                 # increment counter
done | yad --multi-progress --auto-kill $YADBARS --title "$TITLE" \
--text "$TEXT" --window-icon "$ICON" --image "$IMAGE"
# ↑ launch yad multi progress-bar window

I hope I didn't mess up the formatting too much. I must admit that I am quite new to the whole Google groups thing.

Anyway, I hope you enjoyed this small script showcase and will find it useful for your own projects.

If there's anything you would improve or any other suggestions/questions please don't hesitate to comment.
I am still a newbie as far as bash scripts are concerned and would appreciate any feedback


-- Glutanimate

Johnny Rosenberg

unread,
May 16, 2014, 3:55:49 PM5/16/14
to yad-c...@googlegroups.com
I am a bash newbie forever, I just seem to never learn, but I still make my own scripts now and then, and most of them surprisingly work…

Anyway, isn't it right that you don't need any quotes inside ”[[   ]]”? The following line should work, shouldn't it?
if [[ -z $URILIST ]]

Your line, which also works, I suppose:
if [[ -z "$URILIST" ]]


Or maybe I just misunderstood the whole thing, just as usual…

Just trying to learn…
Johnny Rosenberg
 


-- Glutanimate
--
You received this message because you are subscribed to the Google Groups "yad-common" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yad-common+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Glutanimate

unread,
May 17, 2014, 2:43:37 PM5/17/14
to yad-c...@googlegroups.com
Ehm, I think I might have sent a PM instead of a reply to the topic. I would have posted it again properly but I can't seem to find an overview of outgoing PMs. Johnny, would you be so kind and post my reply here? (I don't have time to type it out again, right now). Thank you!

Johnny Rosenberg

unread,
May 17, 2014, 4:25:04 PM5/17/14
to yad-c...@googlegroups.com


---------- Forwarded message ----------
From: Glutanimate <gluta...@gmail.com>
Date: 2014-05-17 20:22 GMT+02:00
Subject: Private message regarding: [yad] [Showcase] GUI frontend for wget with multiple progress bars
To: gurus....@gmail.com


Hi,
 
 I am a bash newbie forever, I just seem to never learn, but I still make my own scripts now and then, and most of them surprisingly work…

haha, you sound just like me. I always have to look up the simplest of things whenever I write a new script. Don't get yourself beat up. I think there are a lot of us "eternal bash newbies" out there!

Anyway, isn't it right that you don't need any quotes inside ”[[   ]]”? The following line should work, shouldn't it?
if [[ -z $URILIST ]]
Your line, which also works, I suppose:
if [[ -z "$URILIST" ]]
http://mywiki.wooledge.org/BashFAQ/031
Or maybe I just misunderstood the whole thing, just as usual…

No, you're absolutely right it appears. If the tutorial you linked to is right - and I am pretty sure it is - then "no WordSplitting or glob expansion will be done for [[ (and therefore many arguments need not be quoted". 

I actually had no idea that this was the case. I just got into the habit of quoting almost everything after messing up a few times because of the lack of quotes.

The double-quotes don't seem to be making a difference in this case, though, so I think I will just leave them there for now. They do seem to be necessary when comparing with regex, though.

Thanks for teaching me something new today ☺.

-- Glutanimate

Milos Pavlovic

unread,
Oct 24, 2016, 9:37:25 PM10/24/16
to yad-common


петак, 16. мај 2014. 03.47.38 UTC+2, Glutanimate је написао/ла:
Hi everyone,

I recently wrote a YAD script in answer to an Askubuntu question. It uses YAD's --multi-progress option to monitor downloads with wget. Joe suggested I post it here, so here we go:

...
Anyway, I hope you enjoyed this small script showcase and will find it useful for your own projects.

If there's anything you would improve or any other suggestions/questions please don't hesitate to comment.
I am still a newbie as far as bash scripts are concerned and would appreciate any feedback


-- Glutanimate

 
 Thank you for posting this.
I used your method to make a youtube-dl wrapper script, yt-get (requires: latest youtube-dl, ffmpeg, yad, jq)
Reply all
Reply to author
Forward
0 new messages