Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # This script will delete torrents from
  4. # uTorrent once they have been completed
  5. # and has the status "Finished".
  6. #
  7.  
  8. # ----------------------------------- #
  9. CURL="/usr/bin/curl"
  10. UTORRENTURL="http://.213.174.4:8080/gui/"
  11. USERNAME="admin"
  12. PASSWORD=""
  13. TEMPFILE="/tmp/torrentlist.json"
  14. REMOVECMD="removedata" # remove | removedata
  15. # ----------------------------------- #
  16.  
  17. # First authenticate and get session cookie
  18. TOKEN=`${CURL} -u ${USERNAME}:${PASSWORD} -G -s -c cookie.txt -n ${UTORRENTURL}token.html | sed 's/<[^<>]*>//g'`
  19.  
  20. # Put all available torrents into a temporary file
  21. ${CURL} -u ${USERNAME}:${PASSWORD} -G -s -n -b cookie.txt -d token=${TOKEN} -d list=1 ${UTORRENTURL} > ${TEMPFILE}
  22.  
  23. # Get current cache id from temporary file
  24. CID=`grep 'torrentc' ${TEMPFILE} | cut -d ":" -f3 | tr -cd '[:alnum:]'`
  25.  
  26. # Loop through the temporary file and find all Finished torrents
  27. while read HASHES; do
  28. # Get the hash value from all available torrents with status "Finished"
  29. HASH=`echo ${HASHES} | grep '\[\"' | grep 'Finished' | tr -cd '[:alnum:]''[=,=]''[:space:]' | cut -d "," -f1`
  30.  
  31. # If HASH have a value, it's supposed to be deleted
  32. if [[ -n "${HASH}" ]]; then
  33. echo -n "Removing torrent: "
  34. echo ${HASHES} | grep '\[\"' | grep 'Finished' | tr -cd '[:alnum:]''[=,=]''[=.=]''[=-=]''[:space:]' | cut -d "," -f3
  35. ${CURL} -u ${USERNAME}:${PASSWORD} -G -s -n -b cookie.txt -d token=${TOKEN} -d action=${REMOVECMD} -d hash=${HASH} ${UTORRENTURL} 2>&1 >/dev/null
  36. fi
  37. done < ${TEMPFILE}
  38.  
  39. # Clean up
  40. rm cookie.txt
  41. rm ${TEMPFILE}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement