Skip to content

Instantly share code, notes, and snippets.

@vizv
Last active June 29, 2020 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vizv/c38143a70236059b4016abafd51d23ab to your computer and use it in GitHub Desktop.
Save vizv/c38143a70236059b4016abafd51d23ab to your computer and use it in GitHub Desktop.
GDIndex Listing Script
#!/bin/bash
[ $# -eq 1 ] || { echo "Usage: $0 URL" >&2; exit 1; }
GD_DIR_MIME='application/vnd.google-apps.folder'
JQ_COND_DIR="select(.mimeType == \"${GD_DIR_MIME}\")"
JQ_COND_FILE="select(.mimeType != \"${GD_DIR_MIME}\")"
URL="${1%/}"
JSON="$(curl -sd '' "${URL}/")"
DATA_JSON="$(jq -cr '.data' <<< "$JSON")"
[ "$DATA_JSON" = 'null' ] || JSON="$DATA_JSON"
IFS=$'\n'
for DIR in $(jq -r "(.files[] | ${JQ_COND_DIR}).name" <<< "$JSON"); do
DIR="$(echo -n "$DIR" | jq -sRr @uri)"
"$0" "${URL}/${DIR}"
done
for FILE in $(jq -r "(.files[] | ${JQ_COND_FILE}).name" <<< "$JSON"); do
FILE="$(echo -n "$FILE" | jq -sRr @uri)"
echo "${URL}/${FILE}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment