Skip to content

Instantly share code, notes, and snippets.

@shawnli87
Forked from MCOfficer/README.md
Last active April 9, 2024 10:03
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save shawnli87/d416b7c9030293cabfcf4c225cdc5a15 to your computer and use it in GitHub Desktop.
Save shawnli87/d416b7c9030293cabfcf4c225cdc5a15 to your computer and use it in GitHub Desktop.
Bash script to download files from gofile.io
#!/bin/bash
url="$1"
#prompt for url if not provided
until [ ! -z "$url" ] ; do
read -p "url=" url
done
id=$(sed 's|.*gofile.io/d/||g' <<< "$url")
echo "Downloading $id"
#get guest account token for url and cookie
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"
#get website token for url
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"
#get content info from api
resp=$(curl 'https://api.gofile.io/getContent?contentId='"$id"'&token='"$token"'&wt='"$websiteToken"'&cache=true' 2>/dev/null)
code="$?"
#prompt for password if required
if [[ $(jq -r '.status' <<< "$resp" 2>/dev/null) == "error-passwordRequired" ]] ; then
until [ ! -z "$password" ] ; do
read -p "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
#verify content info was retrieved successfully
[ "$code" -ne 0 ] && echo "URL unreachable, check provided link" && exit 1
#create download folder
mkdir "$id" 2>/dev/null
cd "$id"
#load the page once so download links don't get redirected
curl -H 'Cookie: accountToken='"$token" "$url" -o /dev/null 2>/dev/null
[ "$?" -ne 0 ] && echo "Loading page failed, check provided link"
for i in $(jq '.data.contents | keys | .[]' <<< "$resp"); do
name=$(jq -r '.data.contents['"$i"'].name' <<< "$resp")
url=$(jq -r '.data.contents['"$i"'].link' <<< "$resp")
#download file if not already downloaded
if [ ! -f "$name" ] ; then
echo
echo "Downloading $name"
curl -H 'Cookie: accountToken='"$token" "$url" -o "$name"
[ "$?" -ne 0 ] && echo "Downloading ""$filename"" failed, please try again later" && rm "$filename"
fi
done
echo
echo
echo "Note: gofile.io is entirely free with no ads,"
echo "you can support it at https://gofile.io/donate"
@aquint-g
Copy link

Thank you, it helps a lot :)

@asifajrof
Copy link

I was getting a "not premium error" for the website token. Maybe they have updated it recently. Checked from loading their site. As of now, "abcde" works fine.

@asifajrof
Copy link

@asifajrof changed again, how did you find it?

yup, at least for now it's fghij.

I found it by loading the page in my browser. Use the inspect tool and check in the networks tab.

@Rust1v1
Copy link

Rust1v1 commented May 19, 2023

I think gofile may have updated their API again, even using the new websiteToken I'm getting the notPremium error when using getContent

Copy link

ghost commented May 19, 2023

its agh3456fg now

@Rust1v1
Copy link

Rust1v1 commented May 20, 2023

agh3456fg

Good looking out, thank you!

@shawnli87
Copy link
Author

Fixed the websiteToken issues and added enhancements to bring the script more in line with my Zsh version (i.e. error checking, encrypted folders)

@Anceph
Copy link

Anceph commented Jun 7, 2023

Thanks!

@hunescoo
Copy link

jq: error (at :1): null (null) has no keys
any clue?

@tuocan
Copy link

tuocan commented Jan 28, 2024

jq: error (at :1): null (null) has no keys any clue?

I'm getting the same error

@shawnli87
Copy link
Author

@hunescoo @tuocan Fixed. The Gofile shortened the websiteToken key to wt.

@tmatzxzone
Copy link

is there a way to download a certain file within the folder? using the certain content id?

@shawnli87
Copy link
Author

is there a way to download a certain file within the folder? using the certain content id?

@tmatzxzone The whole point of using the script is to download multiple files at the same time. Why wouldn't you just use the browser for individual files?

@tmatzxzone
Copy link

is there a way to download a certain file within the folder? using the certain content id?

@tmatzxzone The whole point of using the script is to download multiple files at the same time. Why wouldn't you just use the browser for individual files?

im using headless vps, is there a way tho for a single file?

@shawnli87
Copy link
Author

is there a way to download a certain file within the folder? using the certain content id?

@tmatzxzone The whole point of using the script is to download multiple files at the same time. Why wouldn't you just use the browser for individual files?

im using headless vps, is there a way tho for a single file?

@tmatzxzone No

@tmatzxzone
Copy link

is there a way to download a certain file within the folder? using the certain content id?

@tmatzxzone The whole point of using the script is to download multiple files at the same time. Why wouldn't you just use the browser for individual files?

im using headless vps, is there a way tho for a single file?

@tmatzxzone No

alrite, i just add the file name that i dont need to download so it skip the download LUL, thx for the script tho

@asifajrof
Copy link

is there a way to download a certain file within the folder? using the certain content id?

im using headless vps, is there a way tho for a single file?

alrite, i just add the file name that i dont need to download so it skip the download LUL, thx for the script tho

I used another parameter to explicitly mention the filenames that i wanted to download. its not a full proof solution, but it works. you may check this fork

@kasumabalidps
Copy link

kasumabalidps commented Mar 7, 2024

is there a way to download a certain file within the folder? using the certain content id?

@tmatzxzone The whole point of using the script is to download multiple files at the same time. Why wouldn't you just use the browser for individual files?

im using headless vps, is there a way tho for a single file?

@tmatzxzone No

alrite, i just add the file name that i dont need to download so it skip the download LUL, thx for the script tho

Try this my fork

@tmatzxzone
Copy link

they just updated their API

@Zorg64
Copy link

Zorg64 commented Mar 15, 2024

A fork to work with the API update, but it is also heavily modified. Take and adapt what you need.

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