brew install elinks aria2
PS: tested on mac os X 10.10 - Yosemite
| #!/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" |