3 paths=(/home/pub/video/anime $HOME/dc/autodl/cur)
12 if [ -r "badlist" ]; then
14 echo "downloading bad files, curep $curep"
16 elif [ -r curep ]; then
18 echo "downloading series, curep $curep"
21 echo "no available episode of $tag" >&2
22 echo "$tag" >>"$HOME/dc/autodl/faulty"
27 if [ -r badsizes ]; then
28 badsizesl="$(sed -n "s/^0*$curep \([^#]*\)\( *#.*\)\?$/\1/p" badsizes)"
30 if [ -n "$badsizesl" ]; then
31 read -a badsizes <<<"$badsizesl"
33 echo "found bad size list: ${badsizes[@]}"
36 fsexpr="`printf "$sexpr" "$curep"`"
37 if [ "${#badsizes[@]}" -gt 0 ]; then
38 for badsize in "${badsizes[@]}"; do
39 fsexpr="$fsexpr & ! S=$badsize"
44 args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile" -E "$estatfile" -x "curep=$curep")
46 args=("${args[@]}" -w)
50 elif [ -e autouarg ]; then
51 uarg="rename:$tag - %02i.ext:move:../autodl/cur/$tag"
53 if [ -n "$uarg" ]; then
54 fuarg="`printf "$uarg" "$curep"`"
55 args=("${args[@]}" -a "$fuarg")
58 echo "trying to download -- autodl ${args[@]}"
60 autodl "${args[@]}" >"$outfile" 2>&1 &
62 trap "intr=y; kill -INT $pid" USR1 INT
65 if [ -r "$estatfile" ]; then
66 estat="`cat "$estatfile"`"
69 if [ "$intr" = y ]; then
70 echo "$tag interrupted"
72 if [ "$stat" -ne 0 ]; then
73 if [ "$stat" -eq 1 ]; then
74 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
75 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
76 elif [ "$stat" -eq 2 ]; then
77 echo "Connection error on $tag"
78 elif [ "$stat" -eq 3 ]; then
79 echo "Configuration error, disabling $tag"
82 echo "$tag" >>"$HOME/dc/autodl/faulty"
85 echo "episode $curep of $tag done (estat: \"$estat\")"
88 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
89 egrep -v "^$curep( |\$)" badlist >newbadlist
90 mv -f newbadlist badlist
91 if [ `wc -l <badlist` -eq 0 ]; then
94 if [ -r maxep ] && [ "`cat curep`" -gt "`cat maxep`" ]; then
100 echo "$tag has no more bad episodes"
101 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
105 if [ "$estat" = dbl ]; then
106 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
107 echo -en "${tag}\n$((${curep} + 1))\n" >>"$HOME/dc/autodl/done"
110 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
114 if [ -r maxep ]; then
115 if [ "$curep" -gt "`cat maxep`" ]; then
117 echo "$tag has reached max"
118 echo "$tag" >>"$HOME/dc/autodl/maxed"
126 rm -f "$HOME/dc/autodl/run/$tag"
129 for dir in $HOME/dc/autodl{,/cur,/run}; do
130 if [ -e "$dir" ]; then
131 if [ ! -d "$dir" ]; then
132 echo "$dir is not a directory, please remedy and restart" >&2
136 mkdir "$dir" || exit 1
140 while [ $# -gt 0 ]; do
145 pid="$(cat "$HOME/dc/autodl/run/master")"
146 if [ -z "$pid" ]; then
147 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
154 echo "autodlctl: unrecognized option: \"$arg\"" >&2
162 trap "done=y" INT QUIT TERM
163 echo $$ >"$HOME/dc/autodl/run/master"
164 while [ "$done" != y ]; do
165 for pidfile in $HOME/dc/autodl/run/*; do
166 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
167 pid="`cat "$pidfile"`"
168 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
169 echo "removing stale pidfile $pidfile"
173 for p in "${paths[@]}"; do
175 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
176 if [ -r "$d/.autodl/tag" ]; then
177 tag="`cat "$d/.autodl/tag"`"
179 tag="`basename "$d"`"
182 if [ -e "$d/.autodl/disable" ]; then
183 echo "disabling $tag per user request"
185 touch "$d/.autodl/disabled"
186 rm -f "$d/.autodl/disable"
187 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
188 pid="`cat "$HOME/dc/autodl/run/$tag"`"
189 echo "sending SIGUSR1 to $pid"
192 echo "could not find pid for $tag"
195 if [ -e "$d/.autodl/restart" ]; then
196 echo "restarting $tag per user request"
197 rm -f "$d/.autodl/restart"
198 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
199 pid="`cat "$HOME/dc/autodl/run/$tag"`"
200 echo "sending SIGUSR1 to $pid"
202 while [ -e "$HOME/dc/autodl/run/$tag" ]; do
203 echo "waiting for it to exit"
207 echo "could not find pid for $tag"
210 if [ $start = y ]; then
211 if [ ! -r "$d/.autodl/sexpr" ]; then
212 touch "$d/.autodl/disabled"
213 echo "$tag lacks sexpr" >&2
214 echo "$tag" >>"$HOME/dc/autodl/faulty"
216 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
217 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
218 getnext "$d" "$tag" &
221 echo "$pid" >"$HOME/dc/autodl/run/$tag"
232 for pidfile in $HOME/dc/autodl/run/*; do
233 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
234 if [ "$(basename "$pidfile")" = master ]; then continue; fi
235 pid="`cat "$pidfile"`"
236 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
240 rm -f "$HOME/dc/autodl/run/master"