Rapidshare Downloader Ubuntu modrapi
Rapidshare Downloader Linux
If you have "Status: Target server unavailable modrapi relogin <- it should work again RS made some changes with session i think
modrapi is a linux commandline downloader for users of rapidshare.com that have premium account.
modrapi functionality: - links storage - import from a webpage - import from a file - manual link add - download bandwitch limiter - free disk space checker - modrapi block download when there is not enough space - duplicate blocker
how to install
download tar archive from here unpack it into /usr/bin
$ chmod a+x /usr/bin/modrapi $ modrapi configure
full help in english (stable)
$ modrapi -h
License GPL
<source lang=bash>
- !/bin/bash
- Author: m0d
- Remember to rate this script at:
- http://m0ds-ubuntu.blogspot.com/
- License: GPL
- rc2 update:
- - opt. status - added
- - opt. downloaded - added
- - opt. removeitem - added
- rc3 update:
- - duplicate blocker - added
- stable update:
- - "x" encoded as entity in filename problem - fixed
- - duplicate check - updated
- 1.1
- - wget oputput visibility as configuration option - added
- 1.2
- - automatic resume - added
- - import - filenames problem with files created in MS Windows - fixed
- 1.3
- - Login methode update, fixed ssl problem
- - Error debug - added
- - RLog file - added
- - lifting :D
SCRIPT_VERSION="1.3"
SCRIPT_DATE="12 june 2008"
- Modules check ########
for tool in wget sed ls cat expr basename grep wc; do if ! type $tool >/dev/null 2>&1; then echo "Critical ERROR : \"$tool\" not found in your system." exit 2 fi done
- Config check ########
MODDIR="$HOME/.modrapi" MODCFG="$HOME/.modrapi/modrapi.cfg" MODSES="$HOME/.modrapi/modrapi.ses" MODSTORAGE="$HOME/.modrapi/modrapi.db" MODTMP="$HOME/.modrapi/modrapi.tmp" MODHTTP="$HOME/.modrapi/modrapi.http" MODLOGIN="$HOME/.modrapi/modrapi.login" LOG="$HOME/.modrapi/modrapi.log" RLOG="$HOME/.modrapi/modrapi.rlog" WGETLOG="$HOME/.modrapi/mwget.log"
if ! [ -d $MODDIR ] ; then
mkdir $MODDIR
fi
function Logit() { DATE=`date` echo "[$DATE] $1" >> $LOG }
if ! [ -e $LOG ] ; then
touch $LOG Logit "= Log file created"
fi
function MakeConfig() { CFG="$MODCFG" echo " " echo "============================" echo " modrapi config generator" echo "============================" echo " "
echo ">> Step 1/6" echo " rapidshare.com Premium LOGIN :" read -p " : " ULOGIN
echo ">> Step 2/6"
echo " rapidshare.com Premium PASSWORD :" read -p " : " UPASSWORD
echo ">> Step 3/6" echo " Path to the folder that will store downloaded files ( ex. $HOME/download ) :" read -p " : " DLFOLDER
if [ -z "$DLFOLDER" ] ; then DLFOLDER="$HOME/download" fi
if ! expr "$DLFOLDER" : '/[\/]*' > /dev/null ; then LOCDIR=`pwd`
echo "# You didnt passed full path" echo "# Setting actual folder - as main path"
if ! expr "$DLFOLDER" : '[\/]*' > /dev/null ; then echo "# Subfolder detected" echo "# Creating folder tree" x=1 lit=1
array=($(echo $DLFOLDER | nawk -F"/" '{$1=$1; print}')) counter=${#array}
BEGINING=$LOCDIR
for ((i=0; i <= $counter; i++)) do BEGINING="$BEGINING/${array[${i}]}" echo "Creating folder $BEGINING"
mkdir -p "$BEGINING" >/dev/null 2>&1
if ! [ -w "$BEGINING" ] ; then echo " " echo ">> CRITICAL ERROR <<"
echo "# Permision denied to create folder $BEGINING or folder exist and its not writable" echo "# Leaving config generator" exit 2
fi done
exit 2 fi
DLFOLDER="$LOCDIR/$DLFOLDER"
fi
if ! [ -d $DLFOLDER ] ; then
echo "# Creating $DLFOLDER"
mkdir -p $DLFOLDER >/dev/null 2>&1
if ! [ -w $DLFOLDER ] ; then echo " " echo ">> CRITICAL ERROR <<" echo "# Permision denied to create folder $DLFOLDER" echo "# Leaving config generator" exit 2 fi
fi
echo " #Setting download folder to: $DLFOLDER"
echo ">> Step 4/6" echo " Max bandwitch to download in kB ( ex. 100 will limit the download speed to 100kB )"
echo " Default is no limit so if you dont want to limit it - just hit ENTER"
read -p " : " DLSPEED
if ! expr "$DLSPEED" : '[0-9]*$' > /dev/null ; then
DLSPEED="0"
echo "# Integer expected"
echo "# Setting bandwitch limit to : No limit" else DLSPEED="${DLSPEED}k" echo "# Setting bandwitch limit to : $DLSPEED"
fi
echo ">> Step 5/6" echo " Disk quotation in MB - when you want to stop download" echo " Default is 110"
echo " example:" echo " Free disk space in $DLFOLDER : 250 MB" echo " Download block at: 110" echo " When will be less than 110MB free space - modrapi will stop download of next file" echo " 110 MB is safe becouse max file size on rapidshare is ~100 MB"
read -p " : " DLQUOTE
if ! expr "$DLQUOTE" : '[0-9]*$' > /dev/null ; then echo "# Integer expected"
DLQUOTE=`expr 110 \* 1024000`
else DLQUOTE=`expr $DLQUOTE \* 1024000` fi
echo "# Setting download folder free space quote to : $DLQUOTE bytes"
echo ">> Step 6/6" echo " Do you want to see wget output with progress bar and all headers?" read -p " [y/N] : " DLOUTPUT
if [ "$DLOUTPUT" == "y" ] || [ "$DLOUTPUT" == "Y" ] ; then DLOUTPUT=""
echo "# Enabling WGET output" else DLOUTPUT="-q" echo "# Disabling WGET output"
fi
echo "# Setting download folder free space quote to : $DLQUOTE bytes"
echo "RAPIDSHARE_COM_LOGIN=\"$ULOGIN\"" > $CFG echo "RAPIDSHARE_COM_PASSW=\"$UPASSWORD\"" >> $CFG
echo "RAPIDSHARE_DL_PATH=\"$DLFOLDER\"" >> $CFG #echo "RAPIDSHARE_LOGIN_URI=\"https://ssl.rapidshare.com/cgi-bin/\"" >> $CFG echo "RAPIDSHARE_LOGIN_URI=\"http://rapidshare.com/cgi-bin/\"" >> $CFG echo "RAPIDSHARE_LOGIN_FILE=\"premium.cgi\"" >> $CFG echo "RAPIDSHARE_COM_DLSPEED=\"$DLSPEED\"" >> $CFG echo "RAPIDSHARE_HDD_QUOTE=\"$DLQUOTE\"" >> $CFG echo "RAPIDSHARE_WGET_OUTPUT=\"$DLOUTPUT\"" >> $CFG echo " " echo "----------------------------" echo " Configuration COMPLETED" echo " "
Logit "Configuration completed"
exit 2;
}
if ! [ -d $MODDIR ] ; then Logit "= Creating configuration directory" mkdir $MODDIR fi
if ! [ -e $MODCFG ] ; then Logit "= Creating configuration file"
touch $MODCFG
fi
if ! [ -e $MODSTORAGE ] ; then Logit "= Creating storage file"
touch $MODSTORAGE
fi
CFGC=`cat $MODCFG`
if [ -z "$CFGC" ] ; then Logit "= Starting configuration" MakeConfig "$MODCFG" exit 2; fi
source $MODCFG DLDIR="$RAPIDSHARE_DL_PATH"
- Main functions ########
function Relogin { L=$RAPIDSHARE_COM_LOGIN P=$RAPIDSHARE_COM_PASSW H=$RAPIDSHARE_LOGIN_URI F=$RAPIDSHARE_LOGIN_FILE LF=$MODLOGIN
echo " " echo "------------------------" echo " Relogin in progress " echo "-----------------------" echo " "
wget --no-check-certificate --save-cookies=$MODSES -q --post-data="accountid=$L&password=$P&premiumlogin=1" $H$F -O $LF
STATUS=`cat $MODLOGIN | grep 'Overview of the Account'`
STATUS2=`cat $MODLOGIN | grep 'is valid till'` #rm $LF
if [ -z "$STATUS" ] && [ -z "$STATUS2" ] ; then
if [ $1 -eq 1 ] ; then echo "Invalid relogin" echo "Are you sure that you wrote valid login and password?" echo "If Yes - try to change RAPIDSHARE_LOGIN_URI=\"https://ssl.rapidshare.com/cgi-bin/\" to RAPIDSHARE_LOGIN_URI=\"http://rapidshare.com/cgi-bin/\" in ~/.modrapi/modrapi.cfg" fi Logit "- Invalid relogin"
return 0 else if [ $1 -eq 1 ] ; then echo "Valid relogin" fi
Logit "+ Valid relogin" return 1
fi
}
function ClearSessionData() { cat /dev/null > $MODSES echo "Session cleared" Logit "= Session cleared" }
function StartRapidSession() {
L=$RAPIDSHARE_COM_LOGIN P=$RAPIDSHARE_COM_PASSW H=$RAPIDSHARE_LOGIN_URI F=$RAPIDSHARE_LOGIN_FILE LF=$MODLOGIN
echo "Login in progress" wget --no-check-certificate --save-cookies=$MODSES -q --post-data="accountid=$L&password=$P&premiumlogin=1" $H$F -O $LF
STATUS=`cat $LF | grep 'is valid till'` STATUS2=`cat $MODLOGIN | grep 'is valid till'`
rm $LF >/dev/null 2>&1
if [ -z "$STATUS" ] && [ -z "$STATUS2" ] ; then echo "Invalid Login data in your configuration file."
echo "Are you sure that you wrote valid login and password?" echo "If Yes - try to change RAPIDSHARE_LOGIN_URI=\"https://ssl.rapidshare.com/cgi-bin/\" to RAPIDSHARE_LOGIN_URI=\"http://rapidshare.com/cgi-bin/\" in ~/.modrapi/modrapi.cfg"
Logit "- Incorect login data" exit 2; else echo "Valid premium login" Logit "+ Valid login" fi }
function FreeSpaceCheck() { FSCHECK=`df --block-size=1 $RAPIDSHARE_DL_PATH | tail -1 | awk '{print$4}'`
if [ $FSCHECK -lt $RAPIDSHARE_HDD_QUOTE ] ; then echo " " echo "# Blocking download becouse there is no free space left" echo " " Logit "Blocking download | Free space $FSCHECK | Block size $RAPIDSHARE_HDD_QUOTE" exit 2; fi }
function GetFile() { FreeSpaceCheck
URL=$1 URL=${URL//\×/x}
FILE_NAME=`basename $URL`
FILE_NAME=${FILE_NAME//\×/x} FILE_NAME=${FILE_NAME//^M$/x}
echo "---" echo "Downloading file: $FILE_NAME"
DIR=$DLDIR FILE_PROGRESS="$DIR/$FILE_NAME.downloading" FILE_AFTER="$DIR/$FILE_NAME"
Checky "$FILE_NAME" return_v=$?
RFLAG=""
if ! [ "$return_v" -eq "0" ] ; then Checky "$FILE_PROGRESS" return_v=$?
if ! [ "$return_v" -eq "0" ] ; then echo "Status: File was downloaded earlier" Logit "- File $URL was downloaded earlier" return 0 else echo "-> Resume mode" RFLAG=" -c " fi fi
if [ $RAPIDSHARE_COM_DLSPEED != "0" ] ; then wget $RFLAG $RAPIDSHARE_WGET_OUTPUT --limit-rate=$RAPIDSHARE_COM_DLSPEED --load-cookies=$MODSES $URL -O $FILE_PROGRESS else wget $RFLAG $RAPIDSHARE_WGET_OUTPUT --load-cookies=$MODSES $URL -O $FILE_PROGRESS fi
if [ -s "$FILE_PROGRESS" ] ; then mv $FILE_PROGRESS $FILE_AFTER
if [ -s $FILE_AFTER ] && [ `ls -l $FILE_AFTER | awk '{print$5}'` -lt 15000 ] ; then
TESTER=`grep 'the file has been removed' $FILE_AFTER` TESTER2=`grep 'not be found' $FILE_AFTER` TESTER3=`grep '90 days without' $FILE_AFTER` TESTER4=`grep 'downloaded more than' $FILE_AFTER` if ! [ -z "$TESTER" ] ; then echo "Status: File removed from rapidshare servers" Logit "--- File $URL removed from rapidshare" elif ! [ -z "$TESTER2" ] ; then
echo "Status: File not found"
Logit "- File $URL not found"
elif ! [ -z "$TESTER4" ] ; then echo "Status: Download limit exceded" Logit "- File $URL not downloaded - limit exceded"
exit 2 elif ! [ -z "$TESTER3" ] && [ $2 -eq "1" ] ; then echo " " echo " >> Login and Password to rapidshare looks like invalid! " echo " " echo " >>>> Do you have direct downloads enabled in your rapidshare options? (Premium zone -> Settings -> direct downloads checkbox) <<<<" echo " " echo " Try # modrapi configure" echo " " echo "- Invalid session data" >> $LOG exit 2 elif ! [ -z "$TESTER3" ] ; then Relogin LOGGEDIN=$? if [ $LOGGEDIN -eq "1" ] ; then Logit "+ Valid Relogin" echo "Login corect!" echo " " GetFile "$URL" "1" else
echo " " echo " >> Login and Password to rapidshare looks like invalid!" echo " "
echo " >>>> Do you have direct downloads enabled in your rapidshare options? (Premium zone -> Settings -> direct downloads checkbox) <<<<" echo " "
echo " Try # modrapi configure"
echo " " Logit "- Incorect Relogin "
exit 2
fi else echo "Status: Target server unavailable" Logit "- Unavailable target server : $URL" fi rm $FILE_AFTER >/dev/null 2>&1 Logit "- Removing tmp file of: $FILE_AFTER" return 0
else echo "Status: Downloaded" Logit "+ File downloaded: $URL"
REMOVE=`cat $MODSTORAGE | sed "/${URL//\//\\/}/d"` echo "$REMOVE" > $MODSTORAGE
return 1 fi else echo "Status: Connection problem - skiping" Logit "- No response from server : $URL" #echo "$URL" >> $RLOG return 0 fi
}
- Main execution #######
function Add2Storage() { URL=$1;
if [ ${#URL} == 0 ] ; then echo "Usage: $ modrapi add VALID_URL" else echo $URL >> $MODSTORAGE echo "Import: 1 link imported" Logit "+ Imported: $URL" fi }
function LoadFromFile() { FILE=$1
if [ -r $FILE ] ; then value=0 lines=`wc -l $FILE | awk '{print $1}'` cnt=0 while [ $value -lt $lines ] ; do value=`expr $value + 1`
ACTUAL=`head -n $value $FILE | tail -1`
if [ "$ACTUAL" != "" ] && [ "$ACTUAL" != "\n" ] then cnt=`expr $cnt + 1` echo "$ACTUAL" >> $MODSTORAGE fi done
UPDATEFILE=`sed 's/^M//g' $MODSTORAGE` echo "$UPDATEFILE" > $MODSTORAGE echo "Import: $cnt link(s) imported" Logit "+ Import from file $FILE : $cnt link(s)"
else echo "Theres no file!" Logit "- Theres no file to import ( $FILE )" fi }
function LoadViaHttp() { if [ -e $MODTMP ] ; then rm $MODTMP fi
URL=$1
wget -E -q -U "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11" $URL -O $MODTMP
if [ -e $MODTMP ] ; then grep -oE "http://rapidshare.com/files/[0-9]{5,15}/[0-9a-zA-Z\.\_\-\×]{1,300}[.][0-9a-zA-Z]{2,4}" $MODTMP | sort -mu -o $MODHTTP LoadFromFile "$MODHTTP" else echo "Cant connect to $URL" Logit "- Cant connect to $URL" fi
rm $MODTMP >/dev/null 2>&1 rm $MODHTTP >/dev/null 2>&1
}
function ClearDB() {
cat /dev/null > $1 echo "Storage cleared"
Logit "= Storage cleared" }
function BeginDownload() { DB=$MODSTORAGE
if [ -s $DB ] ; then value=0 lines=`wc -l $DB | awk '{print $1}'`
CHECKER=`cat $DB`
if [ $lines -eq 0 ] || [ -z "$CHECKER" ] ; then echo "Link Database is empty" Logit "- Link database is empty" exit 2 fi
cnt=0
cnt_all=0
if ! [ -e $MODSES ] || ! [ -s $MODSES ] ; then ClearSessionData StartRapidSession fi
until [ `ls -l $DB | awk '{print$5}'` -eq 0 ] ; do ACTUAL=`head -n 1 $DB | grep -E "http://rapidshare.com/files/[0-9]{5,15}/[0-9a-zA-Z\.\_\-]{1,300}[.][0-9a-zA-Z]{2,4}"` if ! [ -z "$ACTUAL" ] ; then
GetFile "$ACTUAL" "0" return_val=$?
if ! [ "$return_val" -eq 1 ] ; then echo "$ACTUAL" >> $RLOG sed -i '1d' $DB fi
cnt=`expr $cnt + $return_val` cnt_all=`expr $cnt_all + 1`
else REASON=`ls -l $DB | awk '{print$5}'` echo "---" echo "Unrecognized line in DB file - removing" Logit "- Unrecognized line removed from DB: '$REASON'" sed -i '1d' $DB fi done
echo " " echo "========================================="
echo " Download stats:"
echo " $cnt from $cnt_all file(s) downloaded" echo "=========================================" echo " "
Logit "= Download session stats : $cnt / $cnt_all"
else echo "Link Database is empty"
Logit "- Link database is empty"
fi
}
function Usage() { echo " " echo "modrapi help:" echo " " echo " Usage:" echo " " echo " opt: configure" echo " Generates config file - modrapi will not work wihout it!" echo " " echo " opt: add <URL>" echo " Add <URL> to the end of links storage" echo " " echo " opt: file <PATH>" echo " Load urls listed one under another from file <PATH>" echo " ex. ./modrapi.sh file $HOME/mylinks.txt" echo " " echo " opt: load <URL>" echo " This is the best option :)" echo " Gets all rapidshare links listed on the webpage under <URL> and imports them to the links storage" echo " " echo " opt: clear" echo " delete all links listed in links storage" echo " " echo " opt: download" echo " Start download session -> all links - one by one" echo " "
echo " opt: relogin" echo " Start new session at rapidshare" echo " " echo " opt: removeitem <FRAZE>" echo " Removes links with <FRAZE> from modrapi DB" echo " " echo " opt: status" echo " Activity check" echo " " echo " opt: downloaded" echo " List of downloaded files" echo " "
echo " Remember to rate this script at:" echo " http://m0ds-ubuntu.blogspot.com/"
}
function CheckStatus() { WHOAMI=`whoami` CHECK=`ps auxwww | grep "$MODSES" | grep "$WHOAMI" | grep -v grep -c`
if [ "$CHECK" -lt 1 ] ; then echo "0" else echo "1" fi }
function CheckDownloaded() { LIST=`ls -sth $RAPIDSHARE_DL_PATH` echo "$LIST" }
function Remove() { LINKTODEL="$1"
REMOVE=`cat $MODSTORAGE | sed "/${LINKTODEL//\//\\/}/d"` echo "$REMOVE" > $MODSTORAGE
}
function Checky() {
LIST=`ls $RAPIDSHARE_DL_PATH | grep -c "$1"` return "$LIST"
}
case "$1" in
"add") Add2Storage "$2";; "file") LoadFromFile "$2";; "load") LoadViaHttp "$2";; "clear") ClearDB "$MODSTORAGE";; "download") BeginDownload ;; "configure") MakeConfig ;; "relogin") Relogin "1";; "status") CheckStatus;; "downloaded") CheckDownloaded;; "removeitem") Remove "$2";; "--help") Usage ;; "-h") Usage;; "-v") echo "$SCRIPT_VERSION";; "--version") echo "$SCRIPT_VERSION";; *) echo " Use --help or -h to see all available options"
esac </source>