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"
21 touch "$d/.autodl/disabled"
25 if [ -r "$d/.autodl/badsizes" ]; then
26 badsizesl="$(sed -n "s/^0*$curep \([^#]*\)\( *#.*\)\?$/\1/p" "$d/.autodl/badsizes")"
28 if [ -n "$badsizesl" ]; then
29 read -a badsizes <<<"$badsizesl"
31 echo "found bad size list: ${badsizes[@]}"
34 fsexpr="`printf "$sexpr" "$curep"`"
35 if [ "${#badsizes[@]}" -gt 0 ]; then
36 for badsize in "${badsizes[@]}"; do
37 fsexpr="$fsexpr & ! S=$badsize"
40 infofile="$d/.autodl/rtinfo"
41 estatfile="$d/.autodl/estat"
42 args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile" -E "$estatfile" -x "curep=$curep")
43 if [ -e "$d/.autodl/wait" ]; then
44 args=("${args[@]}" -w)
46 if [ -r "$d/.autodl/uarg" ]; then
47 uarg="`cat "$d/.autodl/uarg"`"
48 elif [ -e "$d/.autodl/autouarg" ]; then
49 uarg="rename:$tag - %02i.avi:move:../autodl/cur/$tag"
51 if [ -n "$uarg" ]; then
52 fuarg="`printf "$uarg" "$curep"`"
53 args=("${args[@]}" -a "$fuarg")
55 outfile="$d/.autodl/output"
56 echo "trying to download -- autodl ${args[@]}"
58 autodl "${args[@]}" >"$outfile" 2>&1 &
60 trap "intr=y; kill -INT $pid" USR1 INT
63 if [ -r "$estatfile" ]; then
64 estat="`cat "$estatfile"`"
67 if [ "$intr" = y ]; then
68 echo "$tag interrupted"
70 if [ "$stat" -ne 0 ]; then
71 if [ "$stat" -eq 1 ]; then
72 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
73 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
74 elif [ "$stat" -eq 2 ]; then
75 echo "Connection error on $tag"
76 elif [ "$stat" -eq 3 ]; then
77 echo "Configuration error, disabling $tag"
78 cp "$outfile" "$d/.autodl/conferr"
79 touch "$d/.autodl/disabled"
80 echo "$tag" >>"$HOME/dc/autodl/faulty"
83 echo "episode $curep of $tag done (estat: \"$estat\")"
86 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
87 egrep -v "^$curep( |\$)" "$d/.autodl/badlist" >"$d/.autodl/newbadlist"
88 mv -f "$d/.autodl/newbadlist" "$d/.autodl/badlist"
89 if [ `wc -l <"$d/.autodl/badlist"` -eq 0 ]; then
90 rm "$d/.autodl/badlist"
91 if [ -r "$d/.autodl/curep" ]; then
92 if [ -r "$d/.autodl/maxep" ] && [ "`cat "$d/.autodl/curep"`" -gt "`cat "$d/.autodl/maxep"`" ]; then
93 touch "$d/.autodl/disabled"
96 touch "$d/.autodl/disabled"
98 echo "$tag has no more bad episodes"
99 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
103 if [ "$estat" = dbl ]; then
104 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
105 echo -en "${tag}\n$((${curep} + 1))\n" >>"$HOME/dc/autodl/done"
108 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
111 echo "$curep" >"$d/.autodl/curep"
112 if [ -r "$d/.autodl/maxep" ]; then
113 if [ "$curep" -gt "`cat "$d/.autodl/maxep"`" ]; then
114 touch "$d/.autodl/disabled"
115 echo "$tag has reached max"
116 echo "$tag" >>"$HOME/dc/autodl/maxed"
124 rm -f "$HOME/dc/autodl/run/$tag"
127 for dir in $HOME/dc/autodl{,/cur,/run}; do
128 if [ -e "$dir" ]; then
129 if [ ! -d "$dir" ]; then
130 echo "$dir is not a directory, please remedy and restart" >&2
134 mkdir "$dir" || exit 1
138 while [ $# -gt 0 ]; do
143 pid="$(cat "$HOME/dc/autodl/run/master")"
144 if [ -z "$pid" ]; then
145 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
152 echo "autodlctl: unrecognized option: \"$arg\"" >&2
160 trap "done=y" INT QUIT TERM
161 echo $$ >"$HOME/dc/autodl/run/master"
162 while [ "$done" != y ]; do
163 for pidfile in $HOME/dc/autodl/run/*; do
164 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
165 pid="`cat "$pidfile"`"
166 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
167 echo "removing stale pidfile $pidfile"
171 for p in "${paths[@]}"; do
173 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
174 if [ -r "$d/.autodl/tag" ]; then
175 tag="`cat "$d/.autodl/tag"`"
177 tag="`basename "$d"`"
180 if [ -e "$d/.autodl/disable" ]; then
181 echo "disabling $tag per user request"
183 touch "$d/.autodl/disabled"
184 rm -f "$d/.autodl/disable"
185 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
186 pid="`cat "$HOME/dc/autodl/run/$tag"`"
187 echo "sending SIGUSR1 to $pid"
190 echo "could not find pid for $tag"
193 if [ -e "$d/.autodl/restart" ]; then
194 echo "restarting $tag per user request"
195 rm -f "$d/.autodl/restart"
196 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
197 pid="`cat "$HOME/dc/autodl/run/$tag"`"
198 echo "sending SIGUSR1 to $pid"
200 while [ -e "$HOME/dc/autodl/run/$tag" ]; do
201 echo "waiting for it to exit"
205 echo "could not find pid for $tag"
208 if [ $start = y ]; then
209 if [ ! -r "$d/.autodl/sexpr" ]; then
210 touch "$d/.autodl/disabled"
211 echo "$tag lacks sexpr" >&2
212 echo "$tag" >>"$HOME/dc/autodl/faulty"
214 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
215 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
216 getnext "$d" "$tag" &
219 echo "$pid" >"$HOME/dc/autodl/run/$tag"
230 for pidfile in $HOME/dc/autodl/run/*; do
231 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
232 if [ "$(basename "$pidfile")" = master ]; then continue; fi
233 pid="`cat "$pidfile"`"
234 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
238 rm -f "$HOME/dc/autodl/run/master"