3 paths=(/home/pub/video/anime $HOME/dc/autodl/cur)
7 if [ -r badlist ]; then
8 echo badlist `head -n 1 badlist`
13 if [ "`cat curep`" -le "`cat maxep`" ]; then
14 echo curep `cat curep`
18 echo curep `cat curep`
34 if [ "${epinfo[0]}" = none ]; then
35 echo "no available episode of $tag" >&2
36 echo "$tag" >>"$HOME/dc/autodl/faulty"
43 if [ -r badsizes ]; then
44 badsizesl="$(sed -n "s/^0*$curep \([^#]*\)\( *#.*\)\?$/\1/p" badsizes)"
46 if [ -n "$badsizesl" ]; then
47 read -a badsizes <<<"$badsizesl"
49 echo "found bad size list: ${badsizes[@]}"
52 fsexpr="`printf "$sexpr" "$curep"`"
53 if [ "${#badsizes[@]}" -gt 0 ]; then
54 for badsize in "${badsizes[@]}"; do
55 fsexpr="$fsexpr & ! S=$badsize"
60 args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile" -E "$estatfile" -x "curep=$curep")
62 args=("${args[@]}" -w)
66 elif [ -e autouarg ]; then
67 uarg="rename:$tag - %02i.ext:move:../autodl/cur/$tag"
69 if [ -n "$uarg" ]; then
70 fuarg="`printf "$uarg" "$curep"`"
71 args=("${args[@]}" -a "$fuarg")
74 echo "trying to download -- autodl ${args[@]}"
76 autodl "${args[@]}" >"$outfile" 2>&1 &
78 trap "intr=y; kill -INT $pid" USR1 INT
81 if [ -r "$estatfile" ]; then
82 estat="`cat "$estatfile"`"
85 if [ "$intr" = y ]; then
86 echo "$tag interrupted"
88 if [ "$stat" -ne 0 ]; then
89 if [ "$stat" -eq 1 ]; then
90 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
91 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
92 elif [ "$stat" -eq 2 ]; then
93 echo "Connection error on $tag"
94 elif [ "$stat" -eq 3 ]; then
95 echo "Configuration error, disabling $tag"
98 echo "$tag" >>"$HOME/dc/autodl/faulty"
101 echo "episode $curep of $tag done (estat: \"$estat\")"
104 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
105 egrep -v "^$curep( |\$)" badlist >newbadlist
106 mv -f newbadlist badlist
107 if [ `wc -l <badlist` -eq 0 ]; then
109 echo "$tag has no more bad episodes"
110 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
114 if [ "$estat" = dbl ]; then
115 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
116 echo -en "${tag}\n$((${curep} + 1))\n" >>"$HOME/dc/autodl/done"
119 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
122 echo "$nextep" >curep
123 if [ -r maxep ]; then
124 if [ "$nextep" -gt "`cat maxep`" ]; then
125 echo "$tag has reached max"
126 echo "$tag" >>"$HOME/dc/autodl/maxed"
131 if [ "$estat" = bad ]; then
132 echo "episode reported as bad, adding to badlist"
133 echo "$curep" >>badlist
136 echo "no more episodes to download from $tag"
142 rm -f "$HOME/dc/autodl/run/$tag"
145 for dir in $HOME/dc/autodl{,/cur,/run}; do
146 if [ -e "$dir" ]; then
147 if [ ! -d "$dir" ]; then
148 echo "$dir is not a directory, please remedy and restart" >&2
152 mkdir "$dir" || exit 1
156 while [ $# -gt 0 ]; do
161 pid="$(cat "$HOME/dc/autodl/run/master")"
162 if [ -z "$pid" ]; then
163 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
170 echo "autodlctl: unrecognized option: \"$arg\"" >&2
178 trap "done=y" INT QUIT TERM
179 echo $$ >"$HOME/dc/autodl/run/master"
180 while [ "$done" != y ]; do
181 for pidfile in $HOME/dc/autodl/run/*; do
182 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
183 pid="`cat "$pidfile"`"
184 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
185 echo "removing stale pidfile $pidfile"
189 for p in "${paths[@]}"; do
191 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
192 if [ -r "$d/.autodl/tag" ]; then
193 tag="`cat "$d/.autodl/tag"`"
195 tag="`basename "$d"`"
198 if [ -e "$d/.autodl/disable" ]; then
199 echo "disabling $tag per user request"
201 touch "$d/.autodl/disabled"
202 rm -f "$d/.autodl/disable"
203 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
204 pid="`cat "$HOME/dc/autodl/run/$tag"`"
205 echo "sending SIGUSR1 to $pid"
208 echo "could not find pid for $tag"
211 if [ -e "$d/.autodl/restart" ]; then
212 echo "restarting $tag per user request"
213 rm -f "$d/.autodl/restart"
214 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
215 pid="`cat "$HOME/dc/autodl/run/$tag"`"
216 echo "sending SIGUSR1 to $pid"
218 while [ -e "$HOME/dc/autodl/run/$tag" ]; do
219 echo "waiting for it to exit"
223 echo "could not find pid for $tag"
226 if [ $start = y ]; then
227 if [ ! -r "$d/.autodl/sexpr" ]; then
228 touch "$d/.autodl/disabled"
229 echo "$tag lacks sexpr" >&2
230 echo "$tag" >>"$HOME/dc/autodl/faulty"
232 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
233 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
234 getnext "$d" "$tag" &
237 echo "$pid" >"$HOME/dc/autodl/run/$tag"
248 for pidfile in $HOME/dc/autodl/run/*; do
249 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
250 if [ "$(basename "$pidfile")" = master ]; then continue; fi
251 pid="`cat "$pidfile"`"
252 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
256 rm -f "$HOME/dc/autodl/run/master"