-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgofile.io-dl
executable file
·56 lines (48 loc) · 1.47 KB
/
gofile.io-dl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
set -f # No globbing
set -C # No clobbering
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"
if [[ "${url}" == *'?c='* ]]
then
code="${url##*=}"
else
code="${url##*/}"
fi
server="$(curl -s "https://apiv2.gofile.io/getServer?c=${code}" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read().strip())["data"]["server"])')"
if [[ ! "${server}" =~ ^srv-file[0-9]+$ ]]
then
echo "Unexpected server value: ${server}" >&2
exit 1
fi
curl -s "https://${server}.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["md5"], f["name"], f["link"])' | \
while read -r size md5 name link
do
if [[ "${name}" == *'/'* || "${link}" == *' '* || "${link}" != "https://${server}.gofile.io/download/"* ]]
then
echo 'Cannot download file:' >&2
echo "name: ${name}" >&2
echo "link: ${link}" >&2
echo "size: ${size}" >&2
echo "md5: ${md5}" >&2
exit 1
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
md5sum -c <<<"${md5} ./${name}"
done