#!/bin/bash # downloadque.sh script by Frits Vlaanderen (frits@hccniet.nl) # Based on download.sh script from uzbl # # Without arguments, the script will download all urls in the file $que (.downloadque) with wget. # After downloading a file it downloads the next file in que and deletes the first line from the que. # When the download que becomes empty, the script stops. # If you pass 1 argument to the script, the script will add the argument to the $que file. # If more arguments get passed, the script will stil add the first argument. # When 8 or more arguments get passed to the script, it will use the 8th argument. # This is how uzbl passes the url to the script. # v0.2 Additions: # - Usable without uzbl # - Renames filename to actual filename where possible (no index.php?name=etc) # Extend this with whatever you want, please send me your extensions or criticism or whatever (frits@hccniet.nl) # just an example of how you could handle your downloads # try some pattern matching on the uri to determine what we should do # Some sites block the default wget --user-agent.. dest="$HOME/Downloads" que="$HOME/Downloads/.downloadque" url="$8" GET="wget --user-agent=Firefox" function processque { while [ `wc -l $que | awk '{print $1}'` -ge "1" ] do file=`head -1 $que` filename=`curl -I $file | grep "filename=\"" | sed -e 's/.*filename="//' | sed -e 's/".*$//'` test "x$filename" != "x" && GET="$GET -O \"$filename\"" cd "$dest"; eval "$GET $file" echo `head -1 $que` sed -i 1d $que done echo "Downloadque is empty" } test "x$1" = "x" && { echo "No URL given! Will start processing downloadque now! ($1)"; processque; exit 1; } test "x$8" != "x" && { echo "($8) is added to downloadque"; echo "$8" >> "$que"; exit 1; } test "x$1" != "x" && { echo "($1) is added to downloadque"; echo "$1" >> "$que"; exit 1; } # only changes the dir for the $get sub process #if echo "$url" | grep -E '.*\.torrent' >/dev/null; #then # ( cd "$dest"; eval "$GET" "$url") #else # ( cd "$dest"; eval "$GET" "$url") #fi