-
Notifications
You must be signed in to change notification settings - Fork 2
/
fix-download-location
executable file
·59 lines (54 loc) · 1.49 KB
/
fix-download-location
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
50
51
52
53
54
55
56
57
58
59
#!/bin/sh
. ./hib-utils.sh
exec 4<&0
prompt () {
read -p "$1" junk <&4 || exit 1
}
process_group () {
path="$1"
shift
for tor in "$@" ; do
# get torrents
eval $tor
found=$(transmission-remote -l | grep " $out")
if [ -z "$found" ] ; then
echo "$out not being downloaded yet. Adding $tor in $path ..."
prompt "^C to BREAK, [Enter] to proceed"
transmission-remote -w "$path" &&
transmission-remote -a $tor &&
echo "\tdone." || echo "\tproblems!" && echo $tor >&2
continue
fi
tornum="$(echo $found | cut -f1 -d\ )"
tornum="${tornum%\*}"
dpath="$(transmission-remote -t $tornum -i | grep Location: | cut -c13-)"
# remove optional final /
dpath="${dpath%/}"
if [ "$dpath" = "$path" ] ; then
echo "torrent $tornum ($out) set to correct path $path"
if [ -e "$path/$out" ] ; then
echo "\tand $out exists"
else
echo "\tbut $out does not exist; restarting torrent"
transmission-remote -t $tornum --start
fi
continue
fi
echo "$out is torrent $tornum,"
echo "\tplaced in $dpath,"
echo "\tshould be $path,"
echo "\tmoving ..."
prompt "^C to BREAK, [Enter] to proceed"
transmission-remote -t $tornum --start &&
transmission-remote -t $tornum --move $path
echo "\tdone."
prompt "[Enter] to continue"
done
}
awk '{if (sub(/\\$/,"")) printf "%s", $0; else print $0}' doit | grep add_torrent | while read add qpath tors ; do
# unquote path:
eval path=$qpath
# remove optional final /
path="${path%/}"
eval process_group "$path" $tors
done