diff --git a/crawl.py b/crawl.py index 4f19dd6..c30be7e 100755 --- a/crawl.py +++ b/crawl.py @@ -1,6 +1,6 @@ ################################################################################ # Author: Poka (poka@p2p.legal) -# Version: 0.0.1 +# Version: 0.0.2 # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) # Git: https://git.p2p.legal/axiom-team/astroport ################################################################################ @@ -53,11 +53,8 @@ else: print("Start to remove tracker ...") time.sleep(1) -ID = subprocess.Popen(["./trans-ctl.sh -l | grep -vE 'Sum:|ID Done' | tail -n1 | awk '{ print $1 }'"], shell=True, executable="/bin/bash", stdout=subprocess.PIPE).communicate()[0].strip().decode('ascii') print("Wait 10 seconds to get peers before remove tracker...") time.sleep(10) -subprocess.call(["./trans-ctl.sh", "rmtracker", ID]) - - +subprocess.call(["./trans-ctl.sh", "rmtracker", name]) print("Done") diff --git a/trans-ctl.sh b/trans-ctl.sh index afc7e41..8e47ae6 100755 --- a/trans-ctl.sh +++ b/trans-ctl.sh @@ -13,7 +13,9 @@ transcmd="transmission-remote --auth $transUser:$transPwd" getid() { if [[ -z $2 ]]; then - $transcmd --list | grep -vE 'Sum:|ID Done' | tail -n1 | awk '{ print $1 }' + result=$($transcmd --list | grep -vE 'Sum:|ID Done' | tail -n1 | awk '{ print $1 }') + elif [[ $2 =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then + result=$2 else j=0 for i in "${@:2}"; do @@ -21,7 +23,11 @@ getid() { result=$(echo "$result" | grep -vE 'Sum:|ID Done' | grep -i "$i") ((j++)) done + fi + if [[ $result ]]; then echo "$result" | awk '{ print $1 }' + else + echo "No torrent found" fi } @@ -34,10 +40,12 @@ case "$1" in echo "Please precise an torrentID or title of the torrent you want to anonymize" else if [[ ! "$2" =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then - idt=$($transcmd --list | grep -vE 'Sum:|ID Done' | grep -i "${@:2}" | awk '{ print $1 }') + idt=$(getid "$@") else idt=$2 fi + nbrID=$(echo "$idt" | wc -l) + [[ $nbrID > 1 ]] && echo "You selected $nbrID torrents, please choose just one" && exit 1 [[ $idt ]] && rmtk=$($transcmd -t $idt --tracker-remove http://ygg.peer2peer.cc:8080) [[ $rmtk =~ "Error: invalid argument" ]] && echo "Tracker still removed on this torrent" && exit 1 [[ ! $idt && ! $rmtk =~ "Error: invalid argument" ]] && echo "No torrent found" @@ -47,7 +55,8 @@ case "$1" in getid "$@" ;; remove) - echo "todo" + idt=$(getid $1) + $transcmd -t $idt --remove-and-delete > /dev/null && echo "Torrent $idt removed." || echo "Failed to remove $1" ;; *) cmd="$@"