3 paths=(/home/pub/video/anime $HOME/dc/autodl/cur)
8 sexpr="`cat "$d/.autodl/sexpr"`"
10 if [ -r "$d/.autodl/badlist" ]; then
11 read curep <"$d/.autodl/badlist"
12 echo "downloading bad files, curep $curep"
14 elif [ -r "$d/.autodl/curep" ]; then
15 curep="`cat "$d/.autodl/curep"`"
16 echo "downloading series, curep $curep"
19 echo "no available episode of $tag" >&2
20 echo "$tag" >>"$HOME/dc/autodl/faulty"
24 if [ -r "$d/.autodl/badsizes" ]; then
25 badsizesl="$(sed -n "s/^0*$curep \([^#]*\)\( *#.*\)\?$/\1/p" "$d/.autodl/badsizes")"
27 if [ -n "$badsizesl" ]; then
28 read -a badsizes <<<"$badsizesl"
30 echo "found bad size list: ${badsizes[@]}"
33 fsexpr="`printf "$sexpr" "$curep"`"
34 if [ "${#badsizes[@]}" -gt 0 ]; then
35 for badsize in "${badsizes[@]}"; do
36 fsexpr="$fsexpr & ! S=$badsize"
39 infofile="$d/.autodl/rtinfo"
40 estatfile="$d/.autodl/estat"
41 args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile" -E "$estatfile" -x "curep=$curep")
42 if [ -e "$d/.autodl/wait" ]; then
43 args=("${args[@]}" -w)
45 if [ -r "$d/.autodl/uarg" ]; then
46 uarg="`cat "$d/.autodl/uarg"`"
47 elif [ -e "$d/.autodl/autouarg" ]; then
48 uarg="rename:$tag - %02i.avi:move:../autodl/cur/$tag"
50 if [ -n "$uarg" ]; then
51 fuarg="`printf "$uarg" "$curep"`"
52 args=("${args[@]}" -a "$fuarg")
54 outfile="$d/.autodl/output"
55 echo "trying to download -- autodl ${args[@]}"
57 autodl "${args[@]}" >"$outfile" 2>&1 &
59 trap "intr=y; kill -INT $pid" USR1 INT
62 if [ -r "$estatfile" ]; then
63 estat="`cat "$estatfile"`"
66 if [ "$intr" = y ]; then
67 echo "$tag interrupted"
69 if [ "$stat" -ne 0 ]; then
70 if [ "$stat" -eq 1 ]; then
71 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
72 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
73 elif [ "$stat" -eq 2 ]; then
74 echo "Connection error on $tag"
75 elif [ "$stat" -eq 3 ]; then
76 echo "Configuration error, disabling $tag"
77 cp "$outfile" "$d/.autodl/conferr"
78 touch "$d/.autodl/disabled"
79 echo "$tag" >>"$HOME/dc/autodl/faulty"
82 echo "episode $curep of $tag done (estat: \"$estat\")"
85 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
86 egrep -v "^$curep( |\$)" "$d/.autodl/badlist" >"$d/.autodl/newbadlist"
87 mv -f "$d/.autodl/newbadlist" "$d/.autodl/badlist"
88 if [ `wc -l <"$d/.autodl/badlist"` -eq 0 ]; then
89 rm "$d/.autodl/badlist"
90 if [ -r "$d/.autodl/curep" ]; then
91 if [ -r "$d/.autodl/maxep" ] && [ "`cat "$d/.autodl/curep"`" -gt "`cat "$d/.autodl/maxep"`" ]; then
92 touch "$d/.autodl/disabled"
95 touch "$d/.autodl/disabled"
97 echo "$tag has no more bad episodes"
98 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
102 if [ "$estat" = dbl ]; then
103 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
104 echo -en "${tag}\n$((${curep} + 1))\n" >>"$HOME/dc/autodl/done"
107 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
110 echo "$curep" >"$d/.autodl/curep"
111 if [ -r "$d/.autodl/maxep" ]; then
112 if [ "$curep" -gt "`cat "$d/.autodl/maxep"`" ]; then
113 touch "$d/.autodl/disabled"
114 echo "$tag has reached max"
115 echo "$tag" >>"$HOME/dc/autodl/maxed"
123 rm -f "$HOME/dc/autodl/run/$tag"
126 for dir in $HOME/dc/autodl{,/cur,/run}; do
127 if [ -e "$dir" ]; then
128 if [ ! -d "$dir" ]; then
129 echo "$dir is not a directory, please remedy and restart" >&2
133 mkdir "$dir" || exit 1
137 while [ $# -gt 0 ]; do
142 pid="$(cat "$HOME/dc/autodl/run/master")"
143 if [ -z "$pid" ]; then
144 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
151 echo "autodlctl: unrecognized option: \"$arg\"" >&2
159 trap "done=y" INT QUIT TERM
160 echo $$ >"$HOME/dc/autodl/run/master"
161 while [ "$done" != y ]; do
162 for pidfile in $HOME/dc/autodl/run/*; do
163 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
164 pid="`cat "$pidfile"`"
165 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
166 echo "removing stale pidfile $pidfile"
170 for p in "${paths[@]}"; do
172 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
173 if [ -r "$d/.autodl/tag" ]; then
174 tag="`cat "$d/.autodl/tag"`"
176 tag="`basename "$d"`"
179 if [ -e "$d/.autodl/disable" ]; then
180 echo "disabling $tag per user request"
182 touch "$d/.autodl/disabled"
183 rm -f "$d/.autodl/disable"
184 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
185 pid="`cat "$HOME/dc/autodl/run/$tag"`"
186 echo "sending SIGUSR1 to $pid"
189 echo "could not find pid for $tag"
192 if [ -e "$d/.autodl/restart" ]; then
193 echo "restarting $tag per user request"
194 rm -f "$d/.autodl/restart"
195 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
196 pid="`cat "$HOME/dc/autodl/run/$tag"`"
197 echo "sending SIGUSR1 to $pid"
199 while [ -e "$HOME/dc/autodl/run/$tag" ]; do
200 echo "waiting for it to exit"
204 echo "could not find pid for $tag"
207 if [ $start = y ]; then
208 if [ ! -r "$d/.autodl/sexpr" ]; then
209 touch "$d/.autodl/disabled"
210 echo "$tag lacks sexpr" >&2
211 echo "$tag" >>"$HOME/dc/autodl/faulty"
213 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
214 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
215 getnext "$d" "$tag" &
218 echo "$pid" >"$HOME/dc/autodl/run/$tag"
229 for pidfile in $HOME/dc/autodl/run/*; do
230 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
231 if [ "$(basename "$pidfile")" = master ]; then continue; fi
232 pid="`cat "$pidfile"`"
233 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
237 rm -f "$HOME/dc/autodl/run/master"