Big improvments on trans-ctl.sh library

This commit is contained in:
poka 2020-03-20 18:11:08 +01:00
parent c1fd9e7002
commit 06e1a72d03
2 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,6 @@
################################################################################ ################################################################################
# Author: Poka (poka@p2p.legal) # Author: Poka (poka@p2p.legal)
# Version: 0.0.1 # Version: 0.0.2
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
# Git: https://git.p2p.legal/axiom-team/astroport # Git: https://git.p2p.legal/axiom-team/astroport
################################################################################ ################################################################################
@ -53,11 +53,8 @@ else:
print("Start to remove tracker ...") print("Start to remove tracker ...")
time.sleep(1) 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...") print("Wait 10 seconds to get peers before remove tracker...")
time.sleep(10) time.sleep(10)
subprocess.call(["./trans-ctl.sh", "rmtracker", ID]) subprocess.call(["./trans-ctl.sh", "rmtracker", name])
print("Done") print("Done")

View File

@ -13,7 +13,9 @@ transcmd="transmission-remote --auth $transUser:$transPwd"
getid() { getid() {
if [[ -z $2 ]]; then 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 else
j=0 j=0
for i in "${@:2}"; do for i in "${@:2}"; do
@ -21,7 +23,11 @@ getid() {
result=$(echo "$result" | grep -vE 'Sum:|ID Done' | grep -i "$i") result=$(echo "$result" | grep -vE 'Sum:|ID Done' | grep -i "$i")
((j++)) ((j++))
done done
fi
if [[ $result ]]; then
echo "$result" | awk '{ print $1 }' echo "$result" | awk '{ print $1 }'
else
echo "No torrent found"
fi fi
} }
@ -34,10 +40,12 @@ case "$1" in
echo "Please precise an torrentID or title of the torrent you want to anonymize" echo "Please precise an torrentID or title of the torrent you want to anonymize"
else else
if [[ ! "$2" =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then if [[ ! "$2" =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then
idt=$($transcmd --list | grep -vE 'Sum:|ID Done' | grep -i "${@:2}" | awk '{ print $1 }') idt=$(getid "$@")
else else
idt=$2 idt=$2
fi 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) [[ $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 [[ $rmtk =~ "Error: invalid argument" ]] && echo "Tracker still removed on this torrent" && exit 1
[[ ! $idt && ! $rmtk =~ "Error: invalid argument" ]] && echo "No torrent found" [[ ! $idt && ! $rmtk =~ "Error: invalid argument" ]] && echo "No torrent found"
@ -47,7 +55,8 @@ case "$1" in
getid "$@" getid "$@"
;; ;;
remove) remove)
echo "todo" idt=$(getid $1)
$transcmd -t $idt --remove-and-delete > /dev/null && echo "Torrent $idt removed." || echo "Failed to remove $1"
;; ;;
*) *)
cmd="$@" cmd="$@"