YAD का उपयोग कर समाधान
अवलोकन
काफी समय में Zenity को अपडेट नहीं किया गया है। सौभाग्य से कई सुविधाओं के साथ YAD नामक एक कांटा है। यह आधिकारिक रिपॉजिटरी में नहीं आया है, फिर भी, लेकिन आप इसे webupd8 PPA से इंस्टॉल कर सकते हैं:
sudo add-apt-repository ppa:webupd8team/y-ppa-manager
sudo apt-get update
sudo apt-get install yad
YAD में शामिल सुविधाओं में से एक बहु प्रगति-बार संवाद है। यहाँ कई प्रगति सलाखों से संबंधित YAD के मैनुअल का एक अंश है:
Multi progress bars dialog options
--bar=LABEL[:TYPE]
Add progress bar. LABEL is a text label for progress bar. TYPE is a progress bar type. Types are:
NORM for normal progress bar, RTL for inverted progress bar and PULSE for pulsate progress bar.
--vertical
Set vertical orientation of progress bars.
--align=TYPE
Set alignment of bar labels. Possible types are left, center or right. Default is left.
Initial values for bars set as extra arguments. Each lines with progress data passed to stdin must be started
from N: where N is a number of progress bar. Rest is the same as in progress dialog.
तो कई प्रगति पट्टियों वाली एक बहुत ही सरल स्क्रिप्ट इस तरह दिख सकती है:
for i in {1..100}; do
printf "1:$i\n2:$i\n3:$i\n"
sleep 0.2
done | yad --multi-progress --bar="Bar 1":NORM --bar="Bar 2":NORM --bar="Bar 3":NORM
यह परिणाम कैसा दिखेगा:
हम बार के साथ विवरण जोड़ सकते हैं #
:
for i in {1..100}; do
printf "1:$i\n2:$i\n3:$i\n"
printf "1:#Progress 1 is at $i percent\n2:#Progress 2 is at $i percent\n3:#Progress 3 is at $i percent\n"
sleep 0.2
done | yad --multi-progress --bar="Bar 1":NORM --bar="Bar 2":NORM --bar="Bar 3":NORM
परिणाम:
अगर हम इसे wget download स्क्रिप्ट में लागू करना चाहते हैं तो हमें पहले कुछ चीजें करनी होंगी:
- wget आउटपुट से डाउनलोड प्रगति और अन्य दिलचस्प डेटा निकालने का एक तरीका खोजें
- एकाधिक फ़ाइलों पर पुनरावृति करने का एक तरीका खोजें
- हम एक एकल याड संवाद के लिए सभी जानकारी पास करने का एक तरीका खोजें
मुझे यह प्रोजेक्ट दिलचस्प लगा, इसलिए मैंने बैठकर एक स्क्रिप्ट तैयार की, जो उपरोक्त सभी को करनी चाहिए।
yad_wget
यहाँ मैं क्या लेकर आया हूँ:
#!/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
और यह ऐसा दिखता है:
स्क्रिप्ट कैसे काम करती है यह जानने के लिए सभी टिप्पणियों के माध्यम से पढ़ना सुनिश्चित करें और यदि आपके कोई प्रश्न हैं, तो कृपया नीचे टिप्पणी में पूछने में संकोच न करें।
संपादित करें:
मैंने एक साथ अधिकतम डाउनलोड की संख्या निर्धारित करने के लिए समर्थन जोड़ा। जैसे MAXDLS="5"
:
axel-kapt
?sudo apt-get install axel-kapt