paths=(/home/pub/video/anime $HOME/dc/autodl/cur)
+function findcurep
+{
+ if [ -r badlist ]; then
+ echo badlist `head -n 1 curep`
+ return 0
+ fi
+ if [ -r curep ]; then
+ if [ -r maxep ]; then
+ if [ "`cat curep`" -le "`cat maxep`" ]; then
+ echo curep `cat curep`
+ fi
+ else
+ echo curep `cat curep`
+ fi
+ return 0
+ fi
+ echo none
+ return 1
+}
+
function getnext
{
cd "$1/.autodl/"
echo "checking $tag"
sexpr="`cat sexpr`"
unset badsizes
- if [ -r "badlist" ]; then
- read curep <"badlist"
- echo "downloading bad files, curep $curep"
- epfrom=badlist
- elif [ -r curep ]; then
- curep="`cat curep`"
- echo "downloading series, curep $curep"
- epfrom=curep
- else
+ epinfo=(`findcurep`)
+ if [ "${epinfo[0]}" = none ]; then
echo "no available episode of $tag" >&2
echo "$tag" >>"$HOME/dc/autodl/faulty"
touch disabled
return 1
fi
+ epfrom="${epinfo[0]}"
+ curep="${epinfo[1]}"
unset badsizesl
if [ -r badsizes ]; then
badsizesl="$(sed -n "s/^0*$curep \([^#]*\)\( *#.*\)\?$/\1/p" badsizes)"
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 disabled
- fi
echo "$tag has no more bad episodes"
echo "$tag" >>"$HOME/dc/autodl/badmaxed"
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
fi
;;
esac
+ if ! findcurep; then
+ echo "no more episodes to download from $tag"
+ touch disabled
+ fi
fi
fi
rm -f "$outfile"