trm (2298B)
1 #!/usr/bin/zsh 2 3 4 stop() { 5 vpn stop 6 pgrep transmission | xargs kill -9 7 notify-send "Transmission" "Stopped" 8 } 9 10 finish() { 11 # notifies me when torrent finished downloading and then remove it so it doenst seed 12 13 file=$(transmission-remote -l | grep 100% | awk '{printf $10}') 14 confirm=$(printf "yes\nno" | dmenu -p "Remove Torrent $file ?" ) 15 if [[ $confirm == "yes" ]]; then 16 transmission-remote -l |\ 17 awk '$2 == "100%"{ system("transmission-remote -t " $1 " --remove") }' &&\ 18 notify-send "Torrent finished downloading" "$file" 19 fi 20 21 } 22 23 start() { 24 var=$(nmcli | grep wlp3s0:\ connect | awk '{printf $4}') 25 #declare -a allowed=( DasBoot Popovic ) 26 27 #for item in "${allowed[@]}"; do 28 # [[ $var == "$item" ]] &&\ 29 vpn start &\ 30 transmission-daemon -g /home/miksa/.config/transmission-daemon/ --foreground --log-info 2<&1 |\ 31 while read line; do 32 echo $line |\ 33 grep -v "announcer.c:\|platform.c:\|announce done (tr-dht.c:" |\ 34 grep -v "Saved.*variant.c:" |\ 35 while read line; do 36 echo $line | grep -q started &&\ 37 notify-send "Transmission Started" " " 38 echo $line | systemd-cat --identifier="TransWrap" --priority=5 39 done 2>&1 > /dev/null 40 done&disown; 41 exit 0 42 43 # [[ $var != "$item" ]] && pkill -3 transmission-daemon ; exit 1 44 45 #done 46 } 47 48 restart() { 49 trm stop && trm start 50 } 51 52 magnet() { 53 LINK="$1" 54 55 if [ -z "$LINK" ]; then 56 notify-send "Error" "need magnet link" 57 fi 58 59 HOST="localhost" 60 PORT="9091" 61 62 ss -tuna | grep 9091 || trm start &&\ 63 confirm=$(printf "yes\nno" | dmenu -p "Add torrent?" ) 64 65 if [[ $confirm == "yes" ]]; then 66 SESSID=$(curl "http://$HOST:$PORT/transmission/rpc" | sed 's/.*<code>//g;s/<\/code>.*//g') 67 add=$(curl --silent --header "$SESSID" \ 68 "http://$HOST:$PORT/transmission/rpc"\ 69 -d "{\"method\":\"torrent-add\",\"arguments\":{\"filename\":\"${LINK}\"}}") 70 71 name=$(echo $add | jq -r '.arguments[].name') &&\ 72 notify-send "Succsess File" "$name downloading" ||\ 73 notify-send "Error" "something went wrong" 74 fi 75 } 76 77 "$@"