nr revisó este gist 1 week ago. Ir a la revisión
1 file changed, 45 insertions
drivedl.sh(archivo creado)
| @@ -0,0 +1,45 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | # Downloads shared file from google drive with given file ID | |
| 3 | + | ||
| 4 | + | set -e | |
| 5 | + | ||
| 6 | + | # shellcheck source=./util.sh disable=SC2155 | |
| 7 | + | function _dl_util_sh { | |
| 8 | + | local UTIL_VERSION="v2.2.6" | |
| 9 | + | local dir="$( dirname "$1" )" | |
| 10 | + | [ -f "${dir}/util.sh" ] || bash "${dir}/download-util.sh" "$UTIL_VERSION" || exit 1 | |
| 11 | + | source "${dir}/util.sh" | |
| 12 | + | }; _dl_util_sh "$0"; unset -f _dl_util_sh | |
| 13 | + | ||
| 14 | + | function main { | |
| 15 | + | check "curl" | |
| 16 | + | check "jq" | |
| 17 | + | check "hq" | |
| 18 | + | ||
| 19 | + | local GID="$1" | |
| 20 | + | ||
| 21 | + | [ -z "$GID" ] && err "Expected first argument to be the shared google file ID" | |
| 22 | + | ||
| 23 | + | local URL1="https://drive.google.com/uc?export=download&id=${GID}" | |
| 24 | + | ||
| 25 | + | local -a values=() | |
| 26 | + | ||
| 27 | + | values=( $( \ | |
| 28 | + | curl -L "$URL1" \ | |
| 29 | + | | hq '{ name: .uc-name-size > a | @text, size: .uc-name-size | @text, url: form | @(action), uuid: form input[name=uuid] | @(value) }' \ | |
| 30 | + | | jq -r '.name, (.size | capture("\\((?<s>.+)\\)").s), .url, .uuid' \ | |
| 31 | + | ) ) | |
| 32 | + | ||
| 33 | + | local GNAME="${values[0]}" | |
| 34 | + | local GSIZE="${values[1]}" | |
| 35 | + | local GURL="${values[2]}" | |
| 36 | + | local GUUID="${values[3]}" | |
| 37 | + | ||
| 38 | + | local URL2="${GURL}?export=download&confirm=t&id=${GID}&uuid=${GUUID}" | |
| 39 | + | ||
| 40 | + | prompt_question "Download ${GSIZE} file to ${GNAME}?" y || exit 1 | |
| 41 | + | ||
| 42 | + | try_run curl -L -o "$GNAME" "$URL2" | |
| 43 | + | } | |
| 44 | + | ||
| 45 | + | main "$@" | |
Siguiente
Anterior