diff --git a/meow.sh b/meow.sh index e2d7e44..c1abbfc 100644 --- a/meow.sh +++ b/meow.sh @@ -1,12 +1,17 @@ #!/usr/bin/env bash SEP=$'\1' +# all timestamps are given in seconds since the epoch +declare -A groupinsane # unsanitized group names +declare -A groupregex +declare -A grouptime # last seen release + die() { - echo -E "$@" 1>&2 + echo -E "$@" >&2 exit 1 } -nullcheck() { +nullcheck() { # {group name} [[ -n "$1" ]] || die "Null group name"; } @@ -14,32 +19,28 @@ sanitize() { sed -e 's/[^0-9a-zA-Z_]/_/g' } -splittags() { +splittags() { # {tag} awk -v tag="$1" -f "$SRCDIR/splittags.awk" } -scrape() { - TZ=UTC0 awk -v g="$1" -v timestamp="${2:-0}" -v sep="$SEP" -f "$SRCDIR/scrape.awk" +scrape() { # {group name} {timestamp} + TZ=UTC0 awk -v g="$1" -v ts="${2:-0}" -v sep="$SEP" -f "$SRCDIR/scrape.awk" } -declare -A groupinsane # unsanitized group names -declare -A groupshows # regexes watch() { # {group name} [regex...] nullcheck "$1" - local gs="$(sanitize<<<"$1")" + local gs="$(sanitize<<<"$1")" regex= groupinsane[$gs]="$1" shift - while (( "$#" )); do - groupshows[$gs]+="|($1)" - shift + for regex; do + groupregex[$gs]+="|($regex)" done } -declare -A grouptimes # last times timestamp -touchgroup() { # {group name} {unix time} +touchgroup() { # {group name} {timestamp} nullcheck "$1" local gs="$(sanitize<<<"$1")" - grouptimes[$gs]="$2" + grouptime[$gs]="$2" } groupreleases() { # groupname [timestamp] @@ -52,14 +53,15 @@ groupreleases() { # groupname [timestamp] groupfilter() { # groupname regex [timestamp] groupreleases "$1" "${3:-}" | while IFS=$SEP read -r title etc; do - grep -P "$2" <<< "$title" 1>/dev/null && echo -E "$title$SEP$etc" + grep -P "$2" <<< "$title" >/dev/null && echo -E "$title$SEP$etc" done [ ${PIPESTATUS[0]} = 0 ] || exit 1 } cleanup() { - for gs in "${!grouptimes[@]}"; do - local v="${grouptimes[$gs]}" + local gs= v= + for gs in "${!grouptime[@]}"; do + v="${grouptime[$gs]}" echo -E "touchgroup $gs $v" >> times.sh [ -e "$gs.xml" ] && rm "$gs.xml" done @@ -67,15 +69,15 @@ cleanup() { } rungroup() { - local insane regex timestamp res recent + local insane= regex= timestamp= res= _= recent= insane="${groupinsane[$1]}" - regex="${groupshows[$1]:1}" - timestamp="${grouptimes[$1]}" + regex="${groupregex[$1]:1}" + timestamp="${grouptime[$1]}" res="$(groupfilter "$insane" "$regex" "$timestamp")" [ $? = 0 ] || return $? IFS=$SEP read -r _ _ recent <<< "$res" [ -n "$recent" ] && { - grouptimes[$1]="$recent" + grouptime[$1]="$recent" echo -E "$res" } return 0 @@ -83,7 +85,7 @@ rungroup() { runall() { trap cleanup INT - ret=0 - for gs in "${!groupshows[@]}"; do rungroup "$gs" || ret=1; done + local ret=0 gs= + for gs in "${!groupregex[@]}"; do rungroup "$gs" || ret=1; done cleanup $ret } diff --git a/scrape.awk b/scrape.awk index bc4c0f1..ca29b1f 100644 --- a/scrape.awk +++ b/scrape.awk @@ -31,7 +31,7 @@ function run(str) { pub=unescape(opentag($0, "pubDate")) # "date -d \""pub "\" +%s" | getline pubunix pubunix=hotdate(pub) - if (pubunix <= timestamp) return + if (pubunix <= ts) return torrent=unescape(opentag(str, "link")) print title sep torrent sep pubunix }