-
-
Save shawnli87/49122dcc5cf2a65fe4580888347a7946 to your computer and use it in GitHub Desktop.
#!/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 |
Why have it like this? Ignoring the continue functionality of wget through the -c parameter.
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
I do not see a reason why the file should be deleted or should not exist in the first place. The continue feature of wget is vastly useful, especially with a slow or unstable connection.
I honestly don't recall the reason now, but I remember I had to do that to make the code functional. It was one of those "lesser of two evils" situations.
Hi, how to use this script? ./gofile_dl http://gofile.me/5rpBN/xYrGYLjQQ didn't work, told me: ./gofile_dl:9: command not found: rev
Hi, how to use this script? ./gofile_dl http://gofile.me/5rpBN/xYrGYLjQQ didn't work, told me: ./gofile_dl:9: command not found: rev
This is zsh script, mainly for MacOS. If you need the bash version, use: https://gist.github.com/shawnli87/d416b7c9030293cabfcf4c225cdc5a15
Updated to fix the websiteToken renaming to wt
Not worked in 2024. Use:
https://github.com/ltsdw/gofile-downloader
Why have it like this? Ignoring the continue functionality of wget through the -c parameter.
I do not see a reason why the file should be deleted or should not exist in the first place.
The continue feature of wget is vastly useful, especially with a slow or unstable connection.
You can also make use of the OR control operator to streamline the logic throughout the script instead of comparing or even saving the return code.
Thank you for this script. Saved me a lot of hassle :-)