Advertisement
Guest User

aria2 imgur

a guest
Aug 22nd, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.90 KB | None | 0 0
  1. #!/bin/bash
  2. #Requires aria2
  3.  
  4. if [ -f .htmltmp ]; then
  5.    
  6.     #Download progress bar
  7.     currentdown=$(cat .downprogress)
  8.     currentdown=$[ $currentdown +1 ]
  9.  
  10.     percent=$( echo "($(echo "$currentdown/$totaldown * 100" | bc -l )+0.5)/1" | bc )
  11.     remaining=$(( 100 - $percent ))
  12.  
  13.     echo -ne "\r["
  14.     printf "%0.s=" `seq $percent`
  15.     echo -n ">"
  16.     [[ $remaining != 0 ]] && printf "%0.s." `seq $remaining`
  17.     echo -n "] $percent% ($currentdown/$totaldown files completed)"
  18.  
  19.     echo $currentdown > .downprogress
  20.     exit
  21.  
  22. else   
  23.    
  24.     #Save html source and filename
  25.     curl -s $1 >> .htmltmp
  26.     url=$1
  27.  
  28.     #Parse html for image links and album title (to create a folder for)
  29.     awk -F\" '/data-src/ {print $10}' .htmltmp | sed '/^$/d' | sed 's/s.jpg/.jpg/g' | sed -e 's/^/http:/' >> .htmltmp1
  30.     fold=$(awk -F\" '/data-title/ {print $6; exit}' .htmltmp | tr -d ' ')
  31.  
  32.     mkdir $fold 2> /dev/null
  33.     #Account for blank titles, already existing directory or incompatible special characters
  34.     if [ $? = 1 ]; then
  35.         echo "Error creating directory - defaulting to album url"
  36.         fold=$(echo "${url##*/}")
  37.         mkdir $fold
  38.     fi
  39.     echo "Saving files to "$(pwd)/$fold
  40.  
  41.     #Data for progress bar
  42.     totaldown=$(wc -l .htmltmp1 | awk '{ print $1 }')
  43.     export totaldown
  44.     echo 0 > .downprogress
  45.  
  46.     #Download generated link file
  47.     echo "Downloading files..."
  48.     echo
  49.     aria2c --dir=$(pwd)/$fold --input-file=$(pwd)/.htmltmp1 -q --on-download-complete ./aria2imgur.sh
  50.  
  51.     #aria2 error status
  52.     if [ $? = 0 ]; then
  53.         errors="no download errors"
  54.         else
  55.         errors="download errors"
  56.     fi
  57.  
  58.     #Rename files according to album order - aria2 doesn't support this with its -o flag
  59.     while read line
  60.         do
  61.         file_counter=$[ $file_counter +1 ]
  62.         file_name=$(echo "${line##*/}")
  63.         mv $(pwd)/$fold/$file_name $(pwd)/$fold/"$file_counter - $file_name"
  64.     done < .htmltmp1
  65.  
  66.     #Remove temporary files
  67.     rm  .htmltmp .htmltmp1 .downprogress
  68.  
  69.     echo
  70.     echo
  71.     echo "Done with" $errors
  72.  
  73. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement