diff --git a/run b/run index 71286f6..633be0e 100755 --- a/run +++ b/run @@ -5,33 +5,33 @@ SRCDIR="$(readlink -f "$(dirname "$0")" )" declare -a actions while getopts 'aph' opt; do - case $opt in - a) actions+=(addtorrent);; - p) actions+=(prettify);; - ?) echo -E "usage: $0 [-ap]" 1>&2;; - esac + case $opt in + a) actions+=(addtorrent);; + p) actions+=(prettify);; + ?) echo -E "usage: $0 [-ap]" 1>&2;; + esac done prettify() { - echo -E "$1"$'\n'"dl:"$'\t'"$2"$'\n'"at:"$'\t'"$(date -d @"$3")" + echo -E "$1"$'\n'"dl:"$'\t'"$2"$'\n'"at:"$'\t'"$(date -d @"$3")" } declare -a torrents addtorrent() { - torrents+=("$2") + torrents+=("$2") } runactions() { - [ ${#actions} = 0 ] && { - cat - return - } - while IFS=$SEP read -r title torrent time; do - for a in "${actions[@]}"; do - "$a" "$title" "$torrent" "$time" + [ ${#actions} = 0 ] && { + cat + return + } + while IFS=$SEP read -r title torrent time; do + for a in "${actions[@]}"; do + "$a" "$title" "$torrent" "$time" + done done - done - for t in "${torrents[@]}"; do transmission-remote -a "$t"; done + for t in "${torrents[@]}"; do transmission-remote -a "$t"; done } . "$SRCDIR/meow.sh" diff --git a/scrape.awk b/scrape.awk index ca29b1f..0a1e78e 100644 --- a/scrape.awk +++ b/scrape.awk @@ -1,39 +1,39 @@ function opentag(str, tag) { - topen="<"tag">" - tclose="" - len=length(tag) - begin=index(str, topen) - end=index(str, tclose) - return (begin && end) ? substr(str, begin+len+2, end-begin-len-2) : "" + topen="<"tag">" + tclose="" + len=length(tag) + begin=index(str, topen) + end=index(str, tclose) + return (begin && end) ? substr(str, begin+len+2, end-begin-len-2) : "" } function unescape(str) { - while (match(str, /&#([0-9]+);/, b)) - str=substr(str, 1, RSTART-1) sprintf("%c",b[1]) substr(str, RSTART+RLENGTH) - return str + while (match(str, /&#([0-9]+);/, b)) + str=substr(str, 1, RSTART-1) sprintf("%c",b[1]) substr(str, RSTART+RLENGTH) + return str } function hotdate(str) { - split(str, d, "[ :]") - return mktime(d[4]" "months[d[3]]" "d[2]" "d[5]" "d[6]" "d[7]) + split(str, d, "[ :]") + return mktime(d[4]" "months[d[3]]" "d[2]" "d[5]" "d[6]" "d[7]) } BEGIN{ - # http://stackoverflow.com/a/2123002 - m=split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",d,"|") - for(o=1;o<=m;o++) months[d[o]]=sprintf("%02d",o) - glen=length(g) + # http://stackoverflow.com/a/2123002 + m=split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",d,"|") + for(o=1;o<=m;o++) months[d[o]]=sprintf("%02d",o) + glen=length(g) } function run(str) { - title=unescape(opentag(str, "title")) - if (substr(title,1,glen+2) != "["g"]") return - pub=unescape(opentag($0, "pubDate")) -# "date -d \""pub "\" +%s" | getline pubunix - pubunix=hotdate(pub) - if (pubunix <= ts) return - torrent=unescape(opentag(str, "link")) - print title sep torrent sep pubunix + title=unescape(opentag(str, "title")) + if (substr(title,1,glen+2) != "["g"]") return + pub=unescape(opentag($0, "pubDate")) +# "date -d \""pub "\" +%s" | getline pubunix + pubunix=hotdate(pub) + if (pubunix <= ts) return + torrent=unescape(opentag(str, "link")) + print title sep torrent sep pubunix } {run($0)} diff --git a/splittags.awk b/splittags.awk index 689f54a..7dcf6c4 100644 --- a/splittags.awk +++ b/splittags.awk @@ -1,13 +1,13 @@ { - str=$0 - topen="<"tag">" - tclose="" - len=length(tag) - for (;;) { - begin=index(str, topen) - end=index(str,tclose) - if (!(begin || end)) break - print substr(str, begin+len+2, end-begin-len-2) - str=substr(str, end+len+3) - } + str=$0 + topen="<"tag">" + tclose="" + len=length(tag) + for (;;) { + begin=index(str, topen) + end=index(str,tclose) + if (!(begin || end)) break + print substr(str, begin+len+2, end-begin-len-2) + str=substr(str, end+len+3) + } }