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"
23 badsizesl="$(sed -n "s/^$curep \(.*\)$/\1/p" "$d/.autodl/badsizes")"
24 if [ -n "$badsizesl" ]; then
25 read -a badsizes <<<"$badsizesl"
27 echo "found bad size list: ${badsizes[@]}"
30 fsexpr="`printf "$sexpr" "$curep"`"
31 if [ "${#badsizes[@]}" -gt 0 ]; then
32 for badsize in "${badsizes[@]}"; do
33 fsexpr="$fsexpr & ! S=$badsize"
36 infofile="$d/.autodl/rtinfo"
37 args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile")
38 if [ -r "$d/.autodl/uarg" ]; then
39 uarg="`cat "$d/.autodl/uarg"`"
40 elif [ -e "$d/.autodl/autouarg" ]; then
41 uarg="rename:$tag - %02i.avi:move:../autodl/cur/$tag"
43 if [ -n "$uarg" ]; then
44 fuarg="`printf "$uarg" "$curep"`"
45 args=("${args[@]}" -a "$fuarg")
47 outfile="`mktemp /tmp/autodlXXXXXX`"
48 echo "trying to download -- autodl ${args[@]}"
50 autodl "${args[@]}" >"$outfile" 2>&1 &
52 trap "intr=y; kill -INT $pid" USR1 INT
55 if [ "$intr" = y ]; then
56 echo "$tag interrupted"
58 if [ "$stat" -ne 0 ]; then
59 echo "Failure for $tag" >>"$HOME/dc/autodl/errorlog"
60 tail -n 20 "$outfile" >>"$HOME/dc/autodl/errorlog"
62 echo "episode $curep of $tag done"
65 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
66 egrep -v "^$curep( |\$)" "$d/.autodl/badlist" >"$d/.autodl/newbadlist"
67 mv -f "$d/.autodl/newbadlist" "$d/.autodl/badlist"
68 if [ `wc -l <"$d/.autodl/badlist"` -eq 0 ]; then
69 rm "$d/.autodl/badlist"
70 if [ -r "$d/.autodl/curep" ]; then
71 if [ -r "$d/.autodl/maxep" ] && [ "`cat "$d/.autodl/curep"`" -gt "`cat "$d/.autodl/maxep"`" ]; then
72 touch "$d/.autodl/disabled"
75 touch "$d/.autodl/disabled"
77 echo "$tag has no more bad episodes"
78 echo "$tag" >>"$HOME/dc/autodl/badmaxed"
82 echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
84 echo "$curep" >"$d/.autodl/curep"
85 if [ -r "$d/.autodl/maxep" ]; then
86 if [ "$curep" -gt "`cat "$d/.autodl/maxep"`" ]; then
87 touch "$d/.autodl/disabled"
88 echo "$tag has reached max"
89 echo "$tag" >>"$HOME/dc/autodl/maxed"
97 rm -f "$HOME/dc/autodl/run/$tag"
100 for dir in $HOME/dc/autodl{,/cur,/run}; do
101 if [ -e "$dir" ]; then
102 if [ ! -d "$dir" ]; then
103 echo "$dir is not a directory, please remedy and restart" >&2
107 mkdir "$dir" || exit 1
111 while [ $# -gt 0 ]; do
116 pid="$(cat "$HOME/dc/autodl/run/master")"
117 if [ -z "$pid" ]; then
118 echo "autodlctl: could not read a PID from $HOME/dc/autodl/run/master" >&2
125 echo "autodlctl: unrecognized option: \"$arg\"" >&2
133 trap "done=y" INT QUIT TERM
134 echo $$ >"$HOME/dc/autodl/run/master"
135 while [ "$done" != y ]; do
136 for pidfile in $HOME/dc/autodl/run/*; do
137 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
138 pid="`cat "$pidfile"`"
139 if [ -d /proc/1 -a ! -d "/proc/$pid" ]; then
140 echo "removing stale pidfile $pidfile"
144 for p in "${paths[@]}"; do
146 if [ -d "$d/.autodl" -a ! -e "$d/.autodl/disabled" ]; then
147 if [ -r "$d/.autodl/tag" ]; then
148 tag="`cat "$d/.autodl/tag"`"
150 tag="`basename "$d"`"
152 if [ -e "$d/.autodl/disable" ]; then
153 echo "disabling $tag per user request"
154 touch "$d/.autodl/disabled"
155 rm -f "$d/.autodl/disable"
156 if [ -r "$HOME/dc/autodl/run/$tag" ]; then
157 pid="`cat "$HOME/dc/autodl/run/$tag"`"
158 echo "sending SIGUSR1 to $pid"
161 echo "could not find pid for $tag"
163 elif [ ! -r "$d/.autodl/sexpr" ]; then
164 touch "$d/.autodl/disabled"
165 echo "$tag lacks sexpr" >&2
166 echo "$tag" >>"$HOME/dc/autodl/faulty"
168 if [ ! -e "$HOME/dc/autodl/run/$tag" ]; then
169 if [ $((`date +%s` - $lastget)) -gt 20 ]; then
170 getnext "$d" "$tag" &
173 echo "$pid" >"$HOME/dc/autodl/run/$tag"
183 for pidfile in $HOME/dc/autodl/run/*; do
184 if [ "$pidfile" = "$HOME/dc/autodl/run/*" ]; then break; fi
185 if [ "$(basename "$pidfile")" = master ]; then continue; fi
186 pid="`cat "$pidfile"`"
187 echo "sending SIGUSR1 to $pid for `basename "$pidfile"`"
191 rm -f "$HOME/dc/autodl/run/master"