[download]

local/bin/torrents

   1 #!/bin/bash
   2 
   3 f=~/.cache/${0##*/}
   4 
   5 [[ -s $f ]] && [[ $(date +%F) == $(date +%F -r $f) ]] ||
   6 curl -sf https://ngosang.github.io/trackerslist/trackers_best.txt | sed '/^$/d' > $f
   7 
   8 ################################################################################
   9 
  10 [[ $1 == -t || $1 == --trackers ]] && {
  11     pidof -q transmission{,-gtk} || exit
  12 
  13     transmission-remote -l |
  14     sed '1d; $d; s/\s\+\s/\t/g' |
  15     cut -f 2,10 |
  16     while read id name; do
  17         echo "$name:"
  18         cat $f | while read url; do
  19             transmission-remote -t $id -it | grep -qw "${url%/*}" && continue
  20             transmission-remote -t $id -td "$url" >&- && echo " + $url"
  21         done
  22     done
  23 
  24     exit
  25 }
  26 
  27 ################################################################################
  28 
  29 [[ $@ ]] && exec aria2c "$@" \
  30 --enable-rpc --seed-time=0 --console-log-level=error  \
  31 --bt-tracker-timeout=1  --bt-tracker-connect-timeout=1 \
  32 --bt-exclude-tracker=\* --bt-tracker="$(tr -s \\n , $f)"
  33 
  34 ################################################################################
  35 
  36 print(){ # {{{
  37     while IFS=$'\t' read progress status name; do
  38         progress=${progress%%%} progress=${progress%.*}
  39         printf '%s\t%s\t%s\n' "${status^}" $progress% "$name"
  40     done
  41 } # }}}
  42 
  43 pidof -q transmission{,-gtk} &&
  44 transmission-remote -l | sed '1d; $d; s/\s\+\s/\t/g' |
  45 cut -f 3,9,10 | sort -k 1,1nr | print Transmission
  46 
  47 pidof -q qbittorrent &&
  48 curl -s http://127.0.0.1:9092/api/v2/sync/maindata |
  49 jq -r '.torrents[] | [.priority, .progress * 100, .state, .name] | @tsv' |
  50 sort -n | cut -f 2,3,4 | print qBittorrent
  51 
  52 pidof -q aria2c &&
  53 aria2p show | sed 1d | while read _ status progress _ _ _ _ _ name
  54 do printf '%s\t%s\t%s\n' $progress $status "$name"; done | print Aria2c
  55 
  56 pidof -q transmission{,-gtk} qbittorrent aria2c