Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Requires aria2
- if [ -f .htmltmp ]; then
- #Download progress bar
- currentdown=$(cat .downprogress)
- currentdown=$[ $currentdown +1 ]
- percent=$( echo "($(echo "$currentdown/$totaldown * 100" | bc -l )+0.5)/1" | bc )
- remaining=$(( 100 - $percent ))
- echo -ne "\r["
- printf "%0.s=" `seq $percent`
- echo -n ">"
- [[ $remaining != 0 ]] && printf "%0.s." `seq $remaining`
- echo -n "] $percent% ($currentdown/$totaldown files completed)"
- echo $currentdown > .downprogress
- exit
- else
- #Save html source and filename
- curl -s $1 >> .htmltmp
- url=$1
- #Parse html for image links and album title (to create a folder for)
- awk -F\" '/data-src/ {print $10}' .htmltmp | sed '/^$/d' | sed 's/s.jpg/.jpg/g' | sed -e 's/^/http:/' >> .htmltmp1
- fold=$(awk -F\" '/data-title/ {print $6; exit}' .htmltmp | tr -d ' ')
- mkdir $fold 2> /dev/null
- #Account for blank titles, already existing directory or incompatible special characters
- if [ $? = 1 ]; then
- echo "Error creating directory - defaulting to album url"
- fold=$(echo "${url##*/}")
- mkdir $fold
- fi
- echo "Saving files to "$(pwd)/$fold
- #Data for progress bar
- totaldown=$(wc -l .htmltmp1 | awk '{ print $1 }')
- export totaldown
- echo 0 > .downprogress
- #Download generated link file
- echo "Downloading files..."
- echo
- aria2c --dir=$(pwd)/$fold --input-file=$(pwd)/.htmltmp1 -q --on-download-complete ./aria2imgur.sh
- #aria2 error status
- if [ $? = 0 ]; then
- errors="no download errors"
- else
- errors="download errors"
- fi
- #Rename files according to album order - aria2 doesn't support this with its -o flag
- while read line
- do
- file_counter=$[ $file_counter +1 ]
- file_name=$(echo "${line##*/}")
- mv $(pwd)/$fold/$file_name $(pwd)/$fold/"$file_counter - $file_name"
- done < .htmltmp1
- #Remove temporary files
- rm .htmltmp .htmltmp1 .downprogress
- echo
- echo
- echo "Done with" $errors
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement