Find next ep more flexibly.
authorfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Wed, 31 May 2006 00:39:43 +0000 (00:39 +0000)
committerfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Wed, 31 May 2006 00:39:43 +0000 (00:39 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@633 959494ce-11ee-0310-bf91-de5d638817bd

autodlctl

index 3f390ce..004f5cf 100755 (executable)
--- a/autodlctl
+++ b/autodlctl
@@ -2,6 +2,26 @@
 
 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/"
@@ -9,20 +29,15 @@ function getnext
     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)"
@@ -90,13 +105,6 @@ function getnext
                    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
@@ -113,13 +121,16 @@ function getnext
                    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"