#!/bin/bash set -f # No globbing set -C # No clobbering printurls= if [[ "$1" == '--urls' ]] then printurls=1 shift fi dodownload=1 if [[ "$1" == '--nodl' ]] then dodownload= shift fi function printurl { [[ "${printurls}" ]] && echo "$1" } if [[ $# -ne 1 || ( ! "$1" =~ ^https://gofile\.io/d/[0-9a-zA-Z]+$ && ! "$1" =~ ^https://gofile\.io/\?c=[0-9a-zA-Z]+$ ) ]] then echo 'Usage: gofile.io-dl URL' >&2 exit 1 fi url="$1" printurl "$url" if [[ "${url}" == *'?c='* ]] then code="${url##*=}" else code="${url##*/}" fi printurl "https://apiv2.gofile.io/getUpload?c=${code}" curl -s "https://apiv2.gofile.io/getUpload?c=${code}" | python3 -c 'import json,sys; obj = json.loads(sys.stdin.read().strip())'$'\n''for f in obj["data"]["files"].values():'$'\n'' print(f["size"], f["name"], f["link"])' | \ while read -r size name link do if [[ "${name}" == *'/'* || "${link}" == *' '* || ! "${link}" =~ ^https://srv-file[0-9]+\.gofile\.io/download/ ]] then echo 'Cannot download file:' >&2 echo "name: ${name}" >&2 echo "link: ${link}" >&2 echo "size: ${size}" >&2 exit 1 fi printurl "${link}" if [[ -z "${dodownload}" ]] then continue fi if [[ -e "./${name}" ]] then echo "./${name} already exists" >&2 exit 1 fi echo "Downloading ${link} to ./${name}..." >&2 curl "${link}" >"./${name}" declare -i actualSize=$(stat -c %s "./${name}") if [[ ${actualSize} -ne ${size} ]] then echo "Size mismatch: expected ${size}, got ${actualSize}" >&2 exit 1 fi done