Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # VARIABLES
- user="admin"
- password="admin"
- server="10.10.3.3"
- port="8080"
- # Don't change anything below this line (unless you know what you're doing)
- WGET_PARAMS_INITIAL="--save-cookies cookies.txt --keep-session-cookies"
- WGET_INITIAL="wget $WGET_PARAMS_INITIAL"
- WGET="wget --load-cookies cookies.txt"
- # Get the auth token.
- resp1=`$WGET_INITIAL --http-user=$user --http-password=$password -q -O - http://$server:$port/gui/token.html`
- token=`echo -e "$resp1" | awk -F'[<>]' '/<div[^>]*id=[\"'"'"']*token[\"'"'"'][^>]*>([^<]*)<\/div>/ { print $5 }'`
- # Get the list of finished torrents
- resp2=`$WGET --http-user=$user --http-password=$password -q -O - http://$server:$port/gui/?list=1\&token=$token`
- # Substring it to the start of the torrents list.
- ndx=`echo -e "$resp2" | tr "\n" " " | awk '{ndx=match($0, /,"torrents": \[/); print ndx }'`
- sstr=${resp2:ndx}
- # Look at each line and identify the torrent listing.
- rx='^\[\"[^"]*\",[0-9]'
- IFS="
- "
- #echo Processing Line: $sstr
- for line in $sstr
- do
- # If this line matches a torrent item in the torrents property...
- if [[ "$line" =~ $rx ]]; then
- # Tokenize the fields.
- lineTokens=(`echo -e "$line" | sed -e 's/\[//g;s/\]//g;s/"//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' `)
- torrent=${lineTokens[2]}
- size=${lineTokens[3]}
- percent=${lineTokens[4]}
- downloaded=${lineTokens[5]}
- echo TORRENT: $torrent
- echo " SIZE: '$size'"
- echo " PERCENT: '$percent'"
- echo " DOWNLOADED: $downloaded"
- # Double check that this is a torrent listing and that it's finished.
- if [[ "$percent" == "1000" ]]; then
- # Make the call to remove the torrent.
- TORRENT=${lineTokens[2]}
- removeAction="remove"
- resp3=`wget --load-cookies cookies.txt --http-user=$user --http-password=$password -q -O - http://$server:$port/gui/?action=$removeAction\&token=$token\&hash=${lineTokens[0]}`
- if [[ "$resp3" == "" ]]; then
- echo "Error removing torrent: ${lineTokens[2]} (id: ${lineTokens[0]})"
- fi
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement