Skip to content

Instantly share code, notes, and snippets.

@mbilgidhis
Last active April 22, 2022 19:51
Show Gist options
  • Save mbilgidhis/f1b95732e1bc83660ba399fc99614136 to your computer and use it in GitHub Desktop.
Save mbilgidhis/f1b95732e1bc83660ba399fc99614136 to your computer and use it in GitHub Desktop.
#!/bin/bash
## HOW TO USE
## [Your Bash Script File] [Uptobox URL]
##
## This script need jq package
if [ -z "$1" ];
then
echo "You need parameter for this function to run"
exit 1
fi
### this function credit https://stackoverflow.com/a/6174447
function getpath() {
# extract the protocol
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol -- updated
url=$(echo $1 | sed -e s,$proto,,g)
# extract the user (if any)
user="$(echo $url | grep @ | cut -d@ -f1)"
# extract the host and port -- updated
hostport=$(echo $url | sed -e s,$user@,,g | cut -d/ -f1)
# by request host without port
host="$(echo $hostport | sed -e 's,:.*,,g')"
# by request - try to extract the port
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
# extract the path (if any)
path="$(echo $url | grep / | cut -d/ -f2-)"
echo $path
}
TOKEN=[your token]
BASE_URL=https://uptobox.com/api/link
LINK=$1
PATH=$(getpath $LINK)
URL="${BASE_URL}?token=${TOKEN}&file_code=${PATH}"
DWNL=$(/usr/bin/curl -s ${URL} | /usr/bin/jq -r '.data' | /usr/bin/jq -r '.dlLink')
/usr/bin/wget $DWNL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment