Created
May 4, 2014 19:43
-
-
Save mfojtik/ef7513d894ca496f690c to your computer and use it in GitHub Desktop.
A simple Bash based downloader for uloz.to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# A simple Bash/Curl downloader for uloz.to | |
# | |
# Usage: /download.sh "http://uloz.to/xpmeHeT/test-txt" (any uloz.to URL) | |
# | |
# You can export your uloz.to credentials via ~/.bashrc: | |
# | |
# export ULOZTO_USER="username" | |
# export ULOZTO_PASS="password" | |
# | |
# Or you can edit this script and make them default (don't forget to chmod 0700 | |
# in that case!) | |
ULOZTO_USER=${ULOZTO_USER:-""} | |
ULOZTO_PASS=${ULOZTO_PASS:-""} | |
# We need couple temporary files, one to get token and second for | |
# login and download, last one for filename change... | |
token_cookie=`mktemp` | |
login_cookie=`mktemp` | |
headers=`mktemp` | |
# Get the form token first (srsly, using tokens to prevent script download? ;-) | |
# | |
token=$(curl -sqLc $token_cookie "http://uloz.to/login?do=web-login" | \ | |
perl -ne 'if (m/frmloginForm\-_token_" value="(\w+)" /g) { print "$1" }') | |
[ -z "$token" ] && echo "Unable to get token. Wrong username/password?" && exit 1 | |
# Login to you WIP account and get the session | |
# | |
curl -sLb $token_cookie -c $login_cookie \ | |
--data "username=${ULOZTO_USER}&password=${ULOZTO_PASS}&_token_=${token}" \ | |
"http://uloz.to/login?do=loginForm-submit" > /dev/null | |
[ "$?" != "0" ] && echo "Unable to login :-(" && exit 1 | |
# Download the file and save HTTP headers | |
# After download, we extract the Content-Disposition from them and rename | |
# the file afterwards. | |
# | |
src=`TMPDIR=$(pwd) mktemp` | |
curl -D $headers --progress-bar -L -b $login_cookie "$1?do=directDownload" > $src | |
# I srsly sux in Perl :`( | |
dst=`perl -ne 'if (m/attachment;filename\*=UTF-8..(.*)$/g) { $s=$1;$s =~ s/^\s+|\s+$//g;print $s;}' $headers` | |
if [ -z "$dst" ]; then | |
echo "Unable to get original filename, keeping download in '$src'" | |
else | |
mv -fv "$src" "$dst" | |
fi | |
# Cleanup... | |
# | |
rm -f $headers $login_cookie $token_cookie |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've exported login credentials but getting "Unable to get token. Wrong username/password?".