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 [ -r "$d/.autodl/uarg" ]; then
42 uarg="`cat "$d/.autodl/uarg"`"
43 elif [ -e "$d/.autodl/autouarg" ]; then
44 uarg="rename:$tag - %02i.avi:move:../autodl/cur/$tag"
46 if [ -n "$uarg" ]; then
47 fuarg="`printf "$uarg" "$curep"`"
48 args=("${args[@]}" -a "$fuarg")
50 outfile="$d/.autodl/output"
51 echo "trying to download -- autodl ${args[@]}"
53 autodl "${args[@]}" >"$outfile" 2>&1 &
55 trap "intr=y; kill -INT $pid" USR1 INT
58 if [ "$intr" = y ]; then
59 echo "$tag interrupted"
61 if [ "$stat" -ne 0 ]; then
62 if [ "$stat" -eq 1 ]; then
63 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
64 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
65 elif [ "$stat" -eq 2 ]; then
66 echo "Connection error on $tag"
67 elif [ "$stat" -eq 3 ]; then
68 echo "Configuration error, disabling $tag"
69 cp "$outfile" "$d/.autodl/conferr"
70 touch "$d/.autodl/disabled"
73 echo "episode $curep of $tag done"
76 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
77 egrep -v "^$curep( |\$)" "$d/.autodl/badlist" >"$d/.autodl/newbadlist"
78 mv -f "$d/.autodl/newbadlist" "$d/.autodl/badlist"
79 if [ `wc -l <"$d/.autodl/badlist"` -eq 0 ]; then
80 rm "$d/.autodl/badlist"
81 if [ -r "$d/.autodl/curep" ]; then
82 if [ -r "$d/.autodl/maxep" ] && [ "`cat "$d/.autodl/curep"`" -gt "`cat "$d/.autodl/maxep"`" ]; then
83 touch "$d/.autodl/disabled"
86 touch "$d/.autodl/disabled"
88 echo "$tag has no more bad episodes"
89 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
93 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
95 echo "$curep" >"$d/.autodl/curep"
96 if [ -r "$d/.autodl/maxep" ]; then
97 if [ "$curep" -gt "`cat "$d/.autodl/maxep"`" ]; then
98 touch "$d/.autodl/disabled"
99 echo "$tag has reached max"
100 echo "$tag" >>"$HOME/dc/autodl/maxed"
108 rm -f "$HOME/dc/autodl/run/$tag"
111 for dir in $HOME/dc/autodl{,/cur,/run}; do
112 if [ -e "$dir" ]; then
113 if [ ! -d "$dir" ]; then
114 echo "$dir is not a directory, please remedy and restart" >&2
118 mkdir "$dir" || exit 1
122 while [ $# -gt 0 ]; do
127 pid="$(cat "$HOME/dc/autodl/run/master")"
128 if [ -z "$pid" ]; then
129 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
136 echo "autodlctl: unrecognized option: \"$arg\"" >&2
144 trap "done=y" INT QUIT TERM
145 echo $$ >"$HOME/dc/autodl/run/master"
146 while [ "$done" != y ]; do
147 for pidfile in $HOME/dc/autodl/run/*; do
148 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
149 pid="`cat "$pidfile"`"
150 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
151 echo "removing stale pidfile $pidfile"
155 for p in "${paths[@]}"; do
157 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
158 if [ -r "$d/.autodl/tag" ]; then
159 tag="`cat "$d/.autodl/tag"`"
161 tag="`basename "$d"`"
163 if [ -e "$d/.autodl/disable" ]; then
164 echo "disabling $tag per user request"
165 touch "$d/.autodl/disabled"
166 rm -f "$d/.autodl/disable"
167 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
168 pid="`cat "$HOME/dc/autodl/run/$tag"`"
169 echo "sending SIGUSR1 to $pid"
172 echo "could not find pid for $tag"
174 elif [ ! -r "$d/.autodl/sexpr" ]; then
175 touch "$d/.autodl/disabled"
176 echo "$tag lacks sexpr" >&2
177 echo "$tag" >>"$HOME/dc/autodl/faulty"
179 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
180 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
181 getnext "$d" "$tag" &
184 echo "$pid" >"$HOME/dc/autodl/run/$tag"
194 for pidfile in $HOME/dc/autodl/run/*; do
195 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
196 if [ "$(basename "$pidfile")" = master ]; then continue; fi
197 pid="`cat "$pidfile"`"
198 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
202 rm -f "$HOME/dc/autodl/run/master"