Skip to content

Instantly share code, notes, and snippets.

@shawnli87
Last active October 27, 2024 18:26
Show Gist options
  • Save shawnli87/49122dcc5cf2a65fe4580888347a7946 to your computer and use it in GitHub Desktop.
Save shawnli87/49122dcc5cf2a65fe4580888347a7946 to your computer and use it in GitHub Desktop.
Zsh script to download files from gofile.io
#!/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
@shawnli87
Copy link
Author

Updated to fix the websiteToken renaming to wt

@eggplants
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment