function getnext
{
+ cd "$1/.autodl/"
+ tag="$2"
echo "checking $tag"
- sexpr="`cat "$d/.autodl/sexpr"`"
+ sexpr="`cat sexpr`"
unset badsizes
- if [ -r "$d/.autodl/badlist" ]; then
- read curep <"$d/.autodl/badlist"
+ if [ -r "badlist" ]; then
+ read curep <"badlist"
echo "downloading bad files, curep $curep"
epfrom=badlist
- elif [ -r "$d/.autodl/curep" ]; then
- curep="`cat "$d/.autodl/curep"`"
+ elif [ -r curep ]; then
+ curep="`cat curep`"
echo "downloading series, curep $curep"
epfrom=curep
else
echo "no available episode of $tag" >&2
echo "$tag" >>"$HOME/dc/autodl/faulty"
+ touch disabled
return 1
fi
unset badsizesl
- if [ -r "$d/.autodl/badsizes" ]; then
- badsizesl="$(sed -n "s/^0*$curep \(.*\)$/\1/p" "$d/.autodl/badsizes")"
+ if [ -r badsizes ]; then
+ badsizesl="$(sed -n "s/^0*$curep \([^#]*\)\( *#.*\)\?$/\1/p" badsizes)"
fi
if [ -n "$badsizesl" ]; then
read -a badsizes <<<"$badsizesl"
fsexpr="$fsexpr & ! S=$badsize"
done
fi
- infofile="$d/.autodl/rtinfo"
- args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile")
- if [ -r "$d/.autodl/uarg" ]; then
- uarg="`cat "$d/.autodl/uarg"`"
- elif [ -e "$d/.autodl/autouarg" ]; then
- uarg="rename:$tag - %02i.avi:move:../autodl/cur/$tag"
+ infofile=rtinfo
+ estatfile=estat
+ args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile" -E "$estatfile" -x "curep=$curep")
+ if [ -e wait ]; then
+ args=("${args[@]}" -w)
+ fi
+ if [ -r uarg ]; then
+ uarg="`cat uarg`"
+ elif [ -e autouarg ]; then
+ uarg="rename:$tag - %02i.ext:move:../autodl/cur/$tag"
fi
if [ -n "$uarg" ]; then
fuarg="`printf "$uarg" "$curep"`"
args=("${args[@]}" -a "$fuarg")
fi
- outfile="$d/.autodl/output"
+ outfile=output
echo "trying to download -- autodl ${args[@]}"
intr=n
autodl "${args[@]}" >"$outfile" 2>&1 &
trap "intr=y; kill -INT $pid" USR1 INT
wait $pid
stat=$?
+ if [ -r "$estatfile" ]; then
+ estat="`cat "$estatfile"`"
+ rm -f "$estatfile"
+ fi
if [ "$intr" = y ]; then
echo "$tag interrupted"
else
echo "Connection error on $tag"
elif [ "$stat" -eq 3 ]; then
echo "Configuration error, disabling $tag"
- cp "$outfile" "$d/.autodl/conferr"
- touch "$d/.autodl/disabled"
+ cp "$outfile" conferr
+ touch disabled
echo "$tag" >>"$HOME/dc/autodl/faulty"
fi
else
- echo "episode $curep of $tag done"
+ echo "episode $curep of $tag done (estat: \"$estat\")"
case "$epfrom" in
badlist)
echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/baddone"
- egrep -v "^$curep( |\$)" "$d/.autodl/badlist" >"$d/.autodl/newbadlist"
- mv -f "$d/.autodl/newbadlist" "$d/.autodl/badlist"
- if [ `wc -l <"$d/.autodl/badlist"` -eq 0 ]; then
- rm "$d/.autodl/badlist"
- if [ -r "$d/.autodl/curep" ]; then
- if [ -r "$d/.autodl/maxep" ] && [ "`cat "$d/.autodl/curep"`" -gt "`cat "$d/.autodl/maxep"`" ]; then
- touch "$d/.autodl/disabled"
+ egrep -v "^$curep( |\$)" badlist >newbadlist
+ mv -f newbadlist badlist
+ if [ `wc -l <badlist` -eq 0 ]; then
+ rm badlist
+ if [ -r curep ]; then
+ if [ -r maxep ] && [ "`cat curep`" -gt "`cat maxep`" ]; then
+ touch disabled
fi
else
- touch "$d/.autodl/disabled"
+ touch disabled
fi
echo "$tag has no more bad episodes"
echo "$tag" >>"$HOME/dc/autodl/badmaxed"
fi
;;
curep)
- echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
- let curep++
- echo "$curep" >"$d/.autodl/curep"
- if [ -r "$d/.autodl/maxep" ]; then
- if [ "$curep" -gt "`cat "$d/.autodl/maxep"`" ]; then
- touch "$d/.autodl/disabled"
+ if [ "$estat" = dbl ]; then
+ echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
+ echo -en "${tag}\n$((${curep} + 1))\n" >>"$HOME/dc/autodl/done"
+ let curep+=2
+ else
+ echo -en "${tag}\n${curep}\n" >>"$HOME/dc/autodl/done"
+ let curep++
+ fi
+ echo "$curep" >curep
+ if [ -r maxep ]; then
+ if [ "$curep" -gt "`cat maxep`" ]; then
+ touch disabled
echo "$tag has reached max"
echo "$tag" >>"$HOME/dc/autodl/maxed"
fi
pid="`cat "$HOME/dc/autodl/run/$tag"`"
echo "sending SIGUSR1 to $pid"
kill -USR1 "$pid"
+ while [ -e "$HOME/dc/autodl/run/$tag" ]; do
+ echo "waiting for it to exit"
+ sleep 1
+ done
else
echo "could not find pid for $tag"
fi