-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-torrent
executable file
·49 lines (42 loc) · 1019 Bytes
/
check-torrent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
## rerun on each .torrent
if [[ $# -eq 0 ]]; then
find -mindepth 1 -maxdepth 1 -name '*torrent' -print0 | xargs -0 -n1 $0
exit
fi
dots() {
awk '/^Check/ {
gsub("Check.*: ", "");
printf "."
} END { print "" } '
}
### undots() {
### let n=0
### while read i; do
### if [[ $i =~ ^Check ]]; then
### echo -ne "\b \b"
### fi
### if [[ -n $1 ]] && [[ $n -ge $1 ]]; then break; fi
### (( n++ ))
### done
### echo
### }
###
### find-extents() {
### local x=$( timeout --foreground 2 ctorrent -c "$1" 2>/dev/null \
### | awk '/Check/{ gsub(".*/","", $0); print $0 ; exit }')
### if [[ -z $x ]]; then x=69; fi
### echo $x
### }
###
### N=`find-extents "$1"`
### for ((i=0; i<N; i++)); do echo -n .; done
### ctorrent -c "$1" | tee >( undots $N ) > $f
f=$(mktemp /tmp/check-torrent-XXX)
ctorrent -c "$1" | tee >( dots ) > $f
percent=`
(
grep -e ^Already -e ^Directory $f | awk '!_[$0]++'
grep -e Already/Total: $f
) | grep -o '[0-9]\+%' | sort -u`
echo Torrent $percent: $1