#!/bin/bash # Downloads shared file from google drive with given file ID set -e # shellcheck source=./util.sh disable=SC2155 function _dl_util_sh { local UTIL_VERSION="v2.2.6" local dir="$( dirname "$1" )" [ -f "${dir}/util.sh" ] || bash "${dir}/download-util.sh" "$UTIL_VERSION" || exit 1 source "${dir}/util.sh" }; _dl_util_sh "$0"; unset -f _dl_util_sh function main { check "curl" check "jq" check "hq" local GID="$1" [ -z "$GID" ] && err "Expected first argument to be the shared google file ID" local URL1="https://drive.google.com/uc?export=download&id=${GID}" local -a values=() values=( $( \ curl -L "$URL1" \ | hq '{ name: .uc-name-size > a | @text, size: .uc-name-size | @text, url: form | @(action), uuid: form input[name=uuid] | @(value) }' \ | jq -r '.name, (.size | capture("\\((?.+)\\)").s), .url, .uuid' \ ) ) local GNAME="${values[0]}" local GSIZE="${values[1]}" local GURL="${values[2]}" local GUUID="${values[3]}" local URL2="${GURL}?export=download&confirm=t&id=${GID}&uuid=${GUUID}" prompt_question "Download ${GSIZE} file to ${GNAME}?" y || exit 1 try_run curl -L -o "$GNAME" "$URL2" } main "$@"