Ravas coding goodies

For discussions about programming and projects not necessarily associated with Porteus.
User avatar
Rava
Contributor
Contributor
Posts: 4650
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#166 by Rava » 31 Jan 2023, 21:39

Here my skeleton .wget-nameloop-double.sh
There is also a .wget-nameloop-single.sh The difference: one uses single quotes for the filenames, the other double quotes.
Single quotes are more robust, but will fail when the $namebase contains single quotes as well.
Like nameext="I've gotten yadda yadda " will work, when

Code: Select all

I've gotten yadda yadda 
is the title, but
nameext='I've gotten yadda yadda ' will fail.

Code: Select all

#!/bin/bash
#V0.3 - added || notify-send -i error * $sourceurl
namebase="TITLE "
nameext=".mp4"
filename=wget.sh
sourceurl=
declare -i n=12
declare -i i

echo '#!/bin/bash' >> $filename
echo '#	'$sourceurl >> $filename
echo -n "processing # "
for ((i = 1; i <= ${n}; i++)); do  { 
	if [ $i -lt 10 ]; then
		number=0${i}
	else
		number=${i}
	fi
	echo '#wget -c '\'\'' -O "'$namebase$number$nameext'" && notify-send -i info -t 0 "Downloading '$number'" "finished" || notify-send -i error -t 0 "Downloading '$number'" "failed"'  >> $filename
	echo -n $number" "
} done 
echo "echo press enter
read" >> $filename
chmod u+x $filename
Replace "TITLE " with the title.
Set the sourceurl= if you want, you can keep it blank as well.

As example, using "TEST " as $namebase and declare -i n=2 and sourceurl=http://example.net/TEST the script produces this wget.sh script and makes it executable:

Code: Select all

#!/bin/bash
#	http://example.net/TEST
#wget -c '' -O "TEST 01.mp4" && notify-send -i info -t 0 "Downloading 01" "finished" || notify-send -i error -t 0 "Downloading 01" "failed"
#wget -c '' -O "TEST 02.mp4" && notify-send -i info -t 0 "Downloading 02" "finished" || notify-send -i error -t 0 "Downloading 02" "failed"
echo press enter
read
Of course, the more single episodes you are planning of downloading, the more help the script gives you.

Why are the

Code: Select all

#wget -c 
lines commented out by default?
Because it is meant for you to manually hunt down the URLs for each episode first.
When you have one URL, uncomment the line and insert it at the correct place.
E.g. like so:

Code: Select all

#!/bin/bash
#	http://example.net/TEST
wget -c 'http://example.net/random1/TEST01.mp4' -O "TEST 01.mp4" && notify-send -i info -t 0 "Downloading 01" "finished" || notify-send -i error -t 0 "Downloading 01" "failed"
wget -c 'http://example.net/random2/TEST02.mp4' -O "TEST 02.mp4" && notify-send -i info -t 0 "Downloading 02" "finished" || notify-send -i error -t 0 "Downloading 02" "failed"
echo press enter
read
When you happen to have all URLs in advance and they are something like this

Code: Select all

http://example.net/TEST01.mp4
http://example.net/TEST02.mp4
[…]
http://example.net/TEST24.mp4
then my above script is less useful, then you can tweak the script to include the target URLs as well.

Have a screenshot from yesterday as example where I hunted down more URLs while wget.sh already ran and re-started the script more than once:
Image
:D
Cheers!
Yours Rava

Post Reply