Utoljára aktív 1 week ago

drivedl.sh Eredeti
1#!/bin/bash
2# Downloads shared file from google drive with given file ID
3
4set -e
5
6# shellcheck source=./util.sh disable=SC2155
7function _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
14function 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
45main "$@"