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 args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile")
41 if [ -e "$d/.autodl/wait" ]; then
42 args=("${args[@]}" -w)
44 if [ -r "$d/.autodl/uarg" ]; then
45 uarg="`cat "$d/.autodl/uarg"`"
46 elif [ -e "$d/.autodl/autouarg" ]; then
47 uarg="rename:$tag - %02i.avi:move:../autodl/cur/$tag"
49 if [ -n "$uarg" ]; then
50 fuarg="`printf "$uarg" "$curep"`"
51 args=("${args[@]}" -a "$fuarg")
53 outfile="$d/.autodl/output"
54 echo "trying to download -- autodl ${args[@]}"
56 autodl "${args[@]}" >"$outfile" 2>&1 &
58 trap "intr=y; kill -INT $pid" USR1 INT
61 if [ "$intr" = y ]; then
62 echo "$tag interrupted"
64 if [ "$stat" -ne 0 ]; then
65 if [ "$stat" -eq 1 ]; then
66 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
67 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
68 elif [ "$stat" -eq 2 ]; then
69 echo "Connection error on $tag"
70 elif [ "$stat" -eq 3 ]; then
71 echo "Configuration error, disabling $tag"
72 cp "$outfile" "$d/.autodl/conferr"
73 touch "$d/.autodl/disabled"
74 echo "$tag" >>"$HOME/dc/autodl/faulty"
77 echo "episode $curep of $tag done"
80 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
81 egrep -v "^$curep( |\$)" "$d/.autodl/badlist" >"$d/.autodl/newbadlist"
82 mv -f "$d/.autodl/newbadlist" "$d/.autodl/badlist"
83 if [ `wc -l <"$d/.autodl/badlist"` -eq 0 ]; then
84 rm "$d/.autodl/badlist"
85 if [ -r "$d/.autodl/curep" ]; then
86 if [ -r "$d/.autodl/maxep" ] && [ "`cat "$d/.autodl/curep"`" -gt "`cat "$d/.autodl/maxep"`" ]; then
87 touch "$d/.autodl/disabled"
90 touch "$d/.autodl/disabled"
92 echo "$tag has no more bad episodes"
93 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
97 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
99 echo "$curep" >"$d/.autodl/curep"
100 if [ -r "$d/.autodl/maxep" ]; then
101 if [ "$curep" -gt "`cat "$d/.autodl/maxep"`" ]; then
102 touch "$d/.autodl/disabled"
103 echo "$tag has reached max"
104 echo "$tag" >>"$HOME/dc/autodl/maxed"
112 rm -f "$HOME/dc/autodl/run/$tag"
115 for dir in $HOME/dc/autodl{,/cur,/run}; do
116 if [ -e "$dir" ]; then
117 if [ ! -d "$dir" ]; then
118 echo "$dir is not a directory, please remedy and restart" >&2
122 mkdir "$dir" || exit 1
126 while [ $# -gt 0 ]; do
131 pid="$(cat "$HOME/dc/autodl/run/master")"
132 if [ -z "$pid" ]; then
133 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
140 echo "autodlctl: unrecognized option: \"$arg\"" >&2
148 trap "done=y" INT QUIT TERM
149 echo $$ >"$HOME/dc/autodl/run/master"
150 while [ "$done" != y ]; do
151 for pidfile in $HOME/dc/autodl/run/*; do
152 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
153 pid="`cat "$pidfile"`"
154 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
155 echo "removing stale pidfile $pidfile"
159 for p in "${paths[@]}"; do
161 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
162 if [ -r "$d/.autodl/tag" ]; then
163 tag="`cat "$d/.autodl/tag"`"
165 tag="`basename "$d"`"
168 if [ -e "$d/.autodl/disable" ]; then
169 echo "disabling $tag per user request"
171 touch "$d/.autodl/disabled"
172 rm -f "$d/.autodl/disable"
173 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
174 pid="`cat "$HOME/dc/autodl/run/$tag"`"
175 echo "sending SIGUSR1 to $pid"
178 echo "could not find pid for $tag"
181 if [ -e "$d/.autodl/restart" ]; then
182 echo "restarting $tag per user request"
183 rm -f "$d/.autodl/restart"
184 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
185 pid="`cat "$HOME/dc/autodl/run/$tag"`"
186 echo "sending SIGUSR1 to $pid"
188 while [ -e "$HOME/dc/autodl/run/$tag" ]; do
189 echo "waiting for it to exit"
193 echo "could not find pid for $tag"
196 if [ $start = y ]; then
197 if [ ! -r "$d/.autodl/sexpr" ]; then
198 touch "$d/.autodl/disabled"
199 echo "$tag lacks sexpr" >&2
200 echo "$tag" >>"$HOME/dc/autodl/faulty"
202 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
203 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
204 getnext "$d" "$tag" &
207 echo "$pid" >"$HOME/dc/autodl/run/$tag"
218 for pidfile in $HOME/dc/autodl/run/*; do
219 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
220 if [ "$(basename "$pidfile")" = master ]; then continue; fi
221 pid="`cat "$pidfile"`"
222 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
226 rm -f "$HOME/dc/autodl/run/master"