3 paths=(/home/pub/video/anime $HOME/dc/autodl/cur)
7 if [ -r badlist ]; then
8 echo badlist `head -n 1 curep`
13 if [ "`cat curep`" -le "`cat maxep`" ]; then
14 echo curep `cat curep`
17 echo curep `cat curep`
33 if [ "${epinfo[0]}" = none ]; then
34 echo "no available episode of $tag" >&2
35 echo "$tag" >>"$HOME/dc/autodl/faulty"
42 if [ -r badsizes ]; then
43 badsizesl="$(sed -n "s/^0*$curep \([^#]*\)\( *#.*\)\?$/\1/p" badsizes)"
45 if [ -n "$badsizesl" ]; then
46 read -a badsizes <<<"$badsizesl"
48 echo "found bad size list: ${badsizes[@]}"
51 fsexpr="`printf "$sexpr" "$curep"`"
52 if [ "${#badsizes[@]}" -gt 0 ]; then
53 for badsize in "${badsizes[@]}"; do
54 fsexpr="$fsexpr & ! S=$badsize"
59 args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile" -E "$estatfile" -x "curep=$curep")
61 args=("${args[@]}" -w)
65 elif [ -e autouarg ]; then
66 uarg="rename:$tag - %02i.ext:move:../autodl/cur/$tag"
68 if [ -n "$uarg" ]; then
69 fuarg="`printf "$uarg" "$curep"`"
70 args=("${args[@]}" -a "$fuarg")
73 echo "trying to download -- autodl ${args[@]}"
75 autodl "${args[@]}" >"$outfile" 2>&1 &
77 trap "intr=y; kill -INT $pid" USR1 INT
80 if [ -r "$estatfile" ]; then
81 estat="`cat "$estatfile"`"
84 if [ "$intr" = y ]; then
85 echo "$tag interrupted"
87 if [ "$stat" -ne 0 ]; then
88 if [ "$stat" -eq 1 ]; then
89 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
90 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
91 elif [ "$stat" -eq 2 ]; then
92 echo "Connection error on $tag"
93 elif [ "$stat" -eq 3 ]; then
94 echo "Configuration error, disabling $tag"
97 echo "$tag" >>"$HOME/dc/autodl/faulty"
100 echo "episode $curep of $tag done (estat: \"$estat\")"
103 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
104 egrep -v "^$curep( |\$)" badlist >newbadlist
105 mv -f newbadlist badlist
106 if [ `wc -l <badlist` -eq 0 ]; then
108 echo "$tag has no more bad episodes"
109 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
113 if [ "$estat" = dbl ]; then
114 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
115 echo -en "${tag}\n$((${curep} + 1))\n" >>"$HOME/dc/autodl/done"
118 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
121 echo "$nextep" >curep
122 if [ -r maxep ]; then
123 if [ "$nextep" -gt "`cat maxep`" ]; then
124 echo "$tag has reached max"
125 echo "$tag" >>"$HOME/dc/autodl/maxed"
130 if [ "$estat" = bad ]; then
131 echo "episode reported as bad, adding to badlist"
132 echo "$curep" >>badlist
135 echo "no more episodes to download from $tag"
141 rm -f "$HOME/dc/autodl/run/$tag"
144 for dir in $HOME/dc/autodl{,/cur,/run}; do
145 if [ -e "$dir" ]; then
146 if [ ! -d "$dir" ]; then
147 echo "$dir is not a directory, please remedy and restart" >&2
151 mkdir "$dir" || exit 1
155 while [ $# -gt 0 ]; do
160 pid="$(cat "$HOME/dc/autodl/run/master")"
161 if [ -z "$pid" ]; then
162 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
169 echo "autodlctl: unrecognized option: \"$arg\"" >&2
177 trap "done=y" INT QUIT TERM
178 echo $$ >"$HOME/dc/autodl/run/master"
179 while [ "$done" != y ]; do
180 for pidfile in $HOME/dc/autodl/run/*; do
181 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
182 pid="`cat "$pidfile"`"
183 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
184 echo "removing stale pidfile $pidfile"
188 for p in "${paths[@]}"; do
190 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
191 if [ -r "$d/.autodl/tag" ]; then
192 tag="`cat "$d/.autodl/tag"`"
194 tag="`basename "$d"`"
197 if [ -e "$d/.autodl/disable" ]; then
198 echo "disabling $tag per user request"
200 touch "$d/.autodl/disabled"
201 rm -f "$d/.autodl/disable"
202 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
203 pid="`cat "$HOME/dc/autodl/run/$tag"`"
204 echo "sending SIGUSR1 to $pid"
207 echo "could not find pid for $tag"
210 if [ -e "$d/.autodl/restart" ]; then
211 echo "restarting $tag per user request"
212 rm -f "$d/.autodl/restart"
213 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
214 pid="`cat "$HOME/dc/autodl/run/$tag"`"
215 echo "sending SIGUSR1 to $pid"
217 while [ -e "$HOME/dc/autodl/run/$tag" ]; do
218 echo "waiting for it to exit"
222 echo "could not find pid for $tag"
225 if [ $start = y ]; then
226 if [ ! -r "$d/.autodl/sexpr" ]; then
227 touch "$d/.autodl/disabled"
228 echo "$tag lacks sexpr" >&2
229 echo "$tag" >>"$HOME/dc/autodl/faulty"
231 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
232 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
233 getnext "$d" "$tag" &
236 echo "$pid" >"$HOME/dc/autodl/run/$tag"
247 for pidfile in $HOME/dc/autodl/run/*; do
248 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
249 if [ "$(basename "$pidfile")" = master ]; then continue; fi
250 pid="`cat "$pidfile"`"
251 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
255 rm -f "$HOME/dc/autodl/run/master"