X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=autodlctl;h=3f390cec8a16868f09157c49c7409c4b8dce51c6;hb=3bf0176fab726b379e83c56dd6e2a5c22e5f52d6;hp=6bac7514c677696d89169713bfe6cd9e0b37ddf5;hpb=9151870a67acce59580d3f92aa629bd75c95766e;p=utils.git diff --git a/autodlctl b/autodlctl index 6bac751..3f390ce 100755 --- a/autodlctl +++ b/autodlctl @@ -4,25 +4,28 @@ paths=(/home/pub/video/anime $HOME/dc/autodl/cur) 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" @@ -36,21 +39,22 @@ function getnext fsexpr="$fsexpr & ! S=$badsize" done fi - infofile="$d/.autodl/rtinfo" - args=(-e "$fsexpr" -t "$tag $curep" -I "$infofile") - if [ -e "$d/.autodl/wait" ]; then + 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 "$d/.autodl/uarg" ]; then - uarg="`cat "$d/.autodl/uarg"`" - elif [ -e "$d/.autodl/autouarg" ]; then - uarg="rename:$tag - %02i.avi:move:../autodl/cur/$tag" + 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 & @@ -58,6 +62,10 @@ function getnext 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 @@ -69,37 +77,43 @@ function getnext 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 >"$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