Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # This script will delete torrents from
- # uTorrent once they have been completed
- # and has the status "Finished".
- #
- # ----------------------------------- #
- CURL="/usr/bin/curl"
- UTORRENTURL="http://.213.174.4:8080/gui/"
- USERNAME="admin"
- PASSWORD=""
- TEMPFILE="/tmp/torrentlist.json"
- REMOVECMD="removedata" # remove | removedata
- # ----------------------------------- #
- # First authenticate and get session cookie
- TOKEN=`${CURL} -u ${USERNAME}:${PASSWORD} -G -s -c cookie.txt -n ${UTORRENTURL}token.html | sed 's/<[^<>]*>//g'`
- # Put all available torrents into a temporary file
- ${CURL} -u ${USERNAME}:${PASSWORD} -G -s -n -b cookie.txt -d token=${TOKEN} -d list=1 ${UTORRENTURL} > ${TEMPFILE}
- # Get current cache id from temporary file
- CID=`grep 'torrentc' ${TEMPFILE} | cut -d ":" -f3 | tr -cd '[:alnum:]'`
- # Loop through the temporary file and find all Finished torrents
- while read HASHES; do
- # Get the hash value from all available torrents with status "Finished"
- HASH=`echo ${HASHES} | grep '\[\"' | grep 'Finished' | tr -cd '[:alnum:]''[=,=]''[:space:]' | cut -d "," -f1`
- # If HASH have a value, it's supposed to be deleted
- if [[ -n "${HASH}" ]]; then
- echo -n "Removing torrent: "
- echo ${HASHES} | grep '\[\"' | grep 'Finished' | tr -cd '[:alnum:]''[=,=]''[=.=]''[=-=]''[:space:]' | cut -d "," -f3
- ${CURL} -u ${USERNAME}:${PASSWORD} -G -s -n -b cookie.txt -d token=${TOKEN} -d action=${REMOVECMD} -d hash=${HASH} ${UTORRENTURL} 2>&1 >/dev/null
- fi
- done < ${TEMPFILE}
- # Clean up
- rm cookie.txt
- rm ${TEMPFILE}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement