Guest User

uploaded.to wget download

a guest
Oct 5th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.04 KB | None | 0 0
  1. #!/bin/sh
  2. # Copyright Wolf Posdorfer, 2016
  3. # Derived from 2015 Jan-Philip Gehrcke, http://gehrcke.de
  4. # See http://gehrcke.de/2015/03/uploaded-to-download-with-wget/ for original work
  5.  
  6.  
  7. # usage:
  8. # 1. enable "Direct downloads" in Uploaded
  9. # 2. save script as download.sh
  10. # 3. execute: "sh download.sh http://ul.to/XYZ"
  11.  
  12.  
  13. USERNAME="username"
  14. PASSWORD="password"
  15.  
  16. if [ "$#" -ne 1 ]; then
  17.     echo "Missing argument: URL." >&2
  18.     exit 1
  19. fi
  20.  
  21. TMPDIR="$(mktemp -d)"
  22. # Install trap that removes the temporary directory recursively
  23. # upon exit (except for when this program retrieves SIGKILL).
  24. trap 'rm -rf "$TMPDIR"' EXIT
  25.  
  26.  
  27. LOGINRESPFILE="${TMPDIR}/login.response"
  28. LOGINOUTPUTFILE="${TMPDIR}/login.outerr"
  29. COOKIESFILE="${TMPDIR}/login.cookies"
  30. LOGINURL="http://uploaded.net/io/login"
  31.  
  32.  
  33. echo "Temporary directory: ${TMPDIR}"
  34. echo "Log in via POST request to ${LOGINURL}, save cookies."
  35. wget --save-cookies=${COOKIESFILE} --server-response --output-document ${LOGINRESPFILE} --post-data="id=${USERNAME}&pw=${PASSWORD}" ${LOGINURL} > ${LOGINOUTPUTFILE} 2>&1
  36.  
  37. # Status code is 200 even if login failed.
  38. # Uploaded sends a '{"err":"User and password do not match!"}'-like response
  39. # body in case of error.
  40.  
  41. echo "Verify that login response is empty."
  42. # Response is more than 0 bytes in case of login error.
  43. if [ -s "${LOGINRESPFILE}" ]; then
  44.     echo "Login response larger than 0 bytes. Print response and exit." >&2
  45.     cat "${LOGINRESPFILE}"
  46.     exit 1
  47. fi
  48.  
  49. # Zero response size does not necessarily imply successful login.
  50. # Wget adds three commented lines to the cookies file by default, so
  51. # set cookies should result in more than three lines in this file.
  52. COOKIESFILELINES="$(cat ${COOKIESFILE} | wc -l)"
  53. echo "${COOKIESFILELINES} lines in cookies file found."
  54. if [ "${COOKIESFILELINES}" -lt "4" ]; then
  55.     echo "Expected >3 lines in cookies file. Exit.". >&2
  56.     exit 1
  57. fi
  58.  
  59.  
  60.  
  61. # Assume that login worked.
  62. echo "GET ${1} (use auth cookie), store response."
  63.  
  64. wget --load-cookies=${COOKIESFILE} --content-disposition ${1}
Add Comment
Please, Sign In to add comment