Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Copyright Wolf Posdorfer, 2016
- # Derived from 2015 Jan-Philip Gehrcke, http://gehrcke.de
- # See http://gehrcke.de/2015/03/uploaded-to-download-with-wget/ for original work
- # usage:
- # 1. enable "Direct downloads" in Uploaded
- # 2. save script as download.sh
- # 3. execute: "sh download.sh http://ul.to/XYZ"
- USERNAME="username"
- PASSWORD="password"
- if [ "$#" -ne 1 ]; then
- echo "Missing argument: URL." >&2
- exit 1
- fi
- TMPDIR="$(mktemp -d)"
- # Install trap that removes the temporary directory recursively
- # upon exit (except for when this program retrieves SIGKILL).
- trap 'rm -rf "$TMPDIR"' EXIT
- LOGINRESPFILE="${TMPDIR}/login.response"
- LOGINOUTPUTFILE="${TMPDIR}/login.outerr"
- COOKIESFILE="${TMPDIR}/login.cookies"
- LOGINURL="http://uploaded.net/io/login"
- echo "Temporary directory: ${TMPDIR}"
- echo "Log in via POST request to ${LOGINURL}, save cookies."
- wget --save-cookies=${COOKIESFILE} --server-response --output-document ${LOGINRESPFILE} --post-data="id=${USERNAME}&pw=${PASSWORD}" ${LOGINURL} > ${LOGINOUTPUTFILE} 2>&1
- # Status code is 200 even if login failed.
- # Uploaded sends a '{"err":"User and password do not match!"}'-like response
- # body in case of error.
- echo "Verify that login response is empty."
- # Response is more than 0 bytes in case of login error.
- if [ -s "${LOGINRESPFILE}" ]; then
- echo "Login response larger than 0 bytes. Print response and exit." >&2
- cat "${LOGINRESPFILE}"
- exit 1
- fi
- # Zero response size does not necessarily imply successful login.
- # Wget adds three commented lines to the cookies file by default, so
- # set cookies should result in more than three lines in this file.
- COOKIESFILELINES="$(cat ${COOKIESFILE} | wc -l)"
- echo "${COOKIESFILELINES} lines in cookies file found."
- if [ "${COOKIESFILELINES}" -lt "4" ]; then
- echo "Expected >3 lines in cookies file. Exit.". >&2
- exit 1
- fi
- # Assume that login worked.
- echo "GET ${1} (use auth cookie), store response."
- wget --load-cookies=${COOKIESFILE} --content-disposition ${1}
Add Comment
Please, Sign In to add comment