Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianwebber/7da5645619d4110a210d to your computer and use it in GitHub Desktop.
Save sebastianwebber/7da5645619d4110a210d to your computer and use it in GitHub Desktop.
script para download de gibis do hqonline.com.br
#!/bin/bash
### http://blog.edwards-research.com/2010/01/quick-bash-trick-looping-through-output-lines/
SEPARADOR="|"
function formata_nro() {
printf "%0${1}d" ${2}
}
function busca_links() {
#ret=$(elinks --dump "$1" | egrep -o 'https://docs.google.com[\/a-zA-Z0-9\-]{1,}/edit' | sort | uniq | cut -d '/' -f 6)
ret=$(elinks --dump "$1" | egrep -B 1 'https://docs.google.com[\/a-zA-Z0-9\-]{1,}/preview')
OIFS="${IFS}"
NIFS=$'\n'
IFS="${NIFS}"
linha=1
nome_arquivo=""
for LINE in ${ret} ; do
IFS="${OIFS}"
if [ "$LINE" != "--" ]; then
if [ "${nome_arquivo}X" = "X" ]; then
nome_arquivo=$(echo $LINE | awk '{ $1=""; print $0 }' | xargs echo)
else
uuid_link=$LINE
if [ "${uuid_link}X" != "X" ]; then
nome_arquivo_for=""
nome_arquivo_for="${nome_arquivo_for}"$(formata_nro 4 $linha)
nome_arquivo_for="${nome_arquivo_for} - ${nome_arquivo}.pdf"
url_download=$(monta_url $( echo "$uuid_link" | awk -F '/' '{print $(NF-1)}'))
echo "Baixando arquivo ${nome_arquivo_for}..."
aria2c --file-allocation=none -o "${nome_arquivo_for}" --quiet --continue=true "$url_download"
nome_arquivo=""
uuid_link=""
linha=$(($linha+1))
fi
fi
fi
# echo "$linha ---- ${LINE}"
IFS="${NIFS}"
done
IFS="${OIFS}"
# for link in ${ret}; do
# # echo "${link}"
# titulo=$(echo "$link" | head -n 1)
# link=$(echo "$link" | tail -n 1)
# echo "$titulo_____$link"
# done
# echo "$ret"
# echo "${retorno[@]}"
}
function monta_url() {
echo "https://docs.google.com/uc?export=download&id=$1"
}
busca_links "$1"

Usage dependencies

brew install elinks aria2

PS: tested on mac os X 10.10 - Yosemite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment