Last active
October 27, 2024 18:26
-
-
Save shawnli87/49122dcc5cf2a65fe4580888347a7946 to your computer and use it in GitHub Desktop.
Zsh script to download files from gofile.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
url="$1" | |
until [ ! -z "$url" ] ; do | |
read "url?url=" | |
done | |
id=$(rev <<< "$url" | cut -d'/' -f1 | rev) | |
token=$(curl -s 'https://api.gofile.io/createAccount' | jq -r '.data.token' 2>/dev/null) | |
[ "$?" -ne 0 ] && echo "Creating guest account failed, please try again later" | |
websiteToken=$(curl -s 'https://gofile.io/dist/js/alljs.js' | grep 'fetchData.wt' | awk '{ print $3 }' | jq -r) | |
[ "$?" -ne 0 ] && echo "Getting website token failed, please try again later" | |
resp=$(curl 'https://api.gofile.io/getContent?contentId='"$id"'&token='"$token"'&wt='"$websiteToken"'&cache=true' 2>/dev/null) | |
code="$?" | |
if [[ $(jq -r '.status' <<< "$resp" 2>/dev/null) == "error-passwordRequired" ]] ; then | |
until [ ! -z "$password" ] ; do | |
read "password?password=" | |
password=$(printf "$password" | sha256sum | cut -d' ' -f1) | |
resp=$(curl 'https://api.gofile.io/getContent?contentId='"$id"'&token='"$token"'&wt='"$websiteToken"'&cache=true&password='"$password" 2>/dev/null) | |
code="$?" | |
done | |
fi | |
[ "$code" -ne 0 ] && echo "URL unreachable, check provided link" && exit 1 | |
mkdir "$id" 2>/dev/null | |
cd "$id" | |
wget '--header=Cookie: accountToken='"$token" --delete-after "$url" -q -c -T 5 -t 1 | |
[ "$?" -ne 0 ] && echo "Fetching page failed, check provided link" | |
for i in $(jq '.data.contents | keys | .[]' <<< "$resp"); do | |
filename=$(jq -r '.data.contents['"$i"'].name' <<< "$resp") | |
link=$(jq -r '.data.contents['"$i"'].link' <<< "$resp") | |
if [ ! -f "$filename" ] ; then | |
wget '--header=Cookie: accountToken='"$token" -O "$filename" "$link" -q --show-progress -c -T 5 -t 1 | |
[ "$?" -ne 0 ] && echo "Downloading ""$filename"" failed, please try again later" && rm "$filename" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to fix the websiteToken renaming to wt