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 |
Updated to fix the websiteToken renaming to wt
Not worked in 2024. Use:
https://github.com/ltsdw/gofile-downloader
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is zsh script, mainly for MacOS. If you need the bash version, use: https://gist.github.com/shawnli87/d416b7c9030293cabfcf4c225cdc5a15