4-space indentation
This commit is contained in:
parent
d0c7974729
commit
d833f2e810
94
meow.sh
94
meow.sh
|
@ -2,88 +2,88 @@
|
||||||
SEP=$'\1'
|
SEP=$'\1'
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
echo -E "$@" 1>&2
|
echo -E "$@" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
nullcheck() {
|
nullcheck() {
|
||||||
[[ -n "$1" ]] || die "Null group name";
|
[[ -n "$1" ]] || die "Null group name";
|
||||||
}
|
}
|
||||||
|
|
||||||
sanitize() {
|
sanitize() {
|
||||||
sed -e 's/[^0-9a-zA-Z_]/_/g'
|
sed -e 's/[^0-9a-zA-Z_]/_/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
splittags() {
|
splittags() {
|
||||||
awk -v tag="$1" -f "$SRCDIR/splittags.awk"
|
awk -v tag="$1" -f "$SRCDIR/splittags.awk"
|
||||||
}
|
}
|
||||||
|
|
||||||
scrape() {
|
scrape() {
|
||||||
TZ=UTC0 awk -v g="$1" -v timestamp="${2:-0}" -v sep="$SEP" -f "$SRCDIR/scrape.awk"
|
TZ=UTC0 awk -v g="$1" -v timestamp="${2:-0}" -v sep="$SEP" -f "$SRCDIR/scrape.awk"
|
||||||
}
|
}
|
||||||
|
|
||||||
declare -A groupinsane # unsanitized group names
|
declare -A groupinsane # unsanitized group names
|
||||||
declare -A groupshows # regexes
|
declare -A groupshows # regexes
|
||||||
watch() { # {group name} [regex...]
|
watch() { # {group name} [regex...]
|
||||||
nullcheck "$1"
|
nullcheck "$1"
|
||||||
local gs="$(sanitize<<<"$1")"
|
local gs="$(sanitize<<<"$1")"
|
||||||
groupinsane[$gs]="$1"
|
groupinsane[$gs]="$1"
|
||||||
shift
|
|
||||||
while (( "$#" )); do
|
|
||||||
groupshows[$gs]+="|($1)"
|
|
||||||
shift
|
shift
|
||||||
done
|
while (( "$#" )); do
|
||||||
|
groupshows[$gs]+="|($1)"
|
||||||
|
shift
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
declare -A grouptimes # last times timestamp
|
declare -A grouptimes # last times timestamp
|
||||||
touchgroup() { # {group name} {unix time}
|
touchgroup() { # {group name} {unix time}
|
||||||
nullcheck "$1"
|
nullcheck "$1"
|
||||||
local gs="$(sanitize<<<"$1")"
|
local gs="$(sanitize<<<"$1")"
|
||||||
grouptimes[$gs]="$2"
|
grouptimes[$gs]="$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
groupreleases() { # groupname [timestamp]
|
groupreleases() { # groupname [timestamp]
|
||||||
nullcheck "$1"
|
nullcheck "$1"
|
||||||
# TODO: escapeurl $1
|
# TODO: escapeurl $1
|
||||||
local URL="http://www.nyaa.eu/?page=search&term=%5B$1%5D&page=rss"
|
local URL="http://www.nyaa.eu/?page=search&term=%5B$1%5D&page=rss"
|
||||||
curl -LsS "$URL" > "$1.xml" || die "Failed to retrieve releases for $1"
|
curl -LsS "$URL" > "$1.xml" || die "Failed to retrieve releases for $1"
|
||||||
tr -d '\r\n'"$SEP" < "$1.xml" | splittags item | scrape "$1" "${2:-}"
|
tr -d '\r\n'"$SEP" < "$1.xml" | splittags item | scrape "$1" "${2:-}"
|
||||||
}
|
}
|
||||||
|
|
||||||
groupfilter() { # groupname regex [timestamp]
|
groupfilter() { # groupname regex [timestamp]
|
||||||
groupreleases "$1" "${3:-}" | while IFS=$SEP read -r title etc; do
|
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" 1>/dev/null && echo -E "$title$SEP$etc"
|
||||||
done
|
done
|
||||||
[ ${PIPESTATUS[0]} = 0 ] || exit 1
|
[ ${PIPESTATUS[0]} = 0 ] || exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
for gs in "${!grouptimes[@]}"; do
|
for gs in "${!grouptimes[@]}"; do
|
||||||
local v="${grouptimes[$gs]}"
|
local v="${grouptimes[$gs]}"
|
||||||
echo -E "touchgroup $gs $v" >> times.sh
|
echo -E "touchgroup $gs $v" >> times.sh
|
||||||
[ -e "$gs.xml" ] && rm "$gs.xml"
|
[ -e "$gs.xml" ] && rm "$gs.xml"
|
||||||
done
|
done
|
||||||
exit ${1:-1}
|
exit ${1:-1}
|
||||||
}
|
}
|
||||||
|
|
||||||
rungroup() {
|
rungroup() {
|
||||||
local insane regex timestamp res recent
|
local insane regex timestamp res recent
|
||||||
insane="${groupinsane[$1]}"
|
insane="${groupinsane[$1]}"
|
||||||
regex="${groupshows[$1]:1}"
|
regex="${groupshows[$1]:1}"
|
||||||
timestamp="${grouptimes[$1]}"
|
timestamp="${grouptimes[$1]}"
|
||||||
res="$(groupfilter "$insane" "$regex" "$timestamp")"
|
res="$(groupfilter "$insane" "$regex" "$timestamp")"
|
||||||
[ $? = 0 ] || return $?
|
[ $? = 0 ] || return $?
|
||||||
IFS=$SEP read -r _ _ recent <<< "$res"
|
IFS=$SEP read -r _ _ recent <<< "$res"
|
||||||
[ -n "$recent" ] && {
|
[ -n "$recent" ] && {
|
||||||
grouptimes[$1]="$recent"
|
grouptimes[$1]="$recent"
|
||||||
echo -E "$res"
|
echo -E "$res"
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
runall() {
|
runall() {
|
||||||
trap cleanup INT
|
trap cleanup INT
|
||||||
ret=0
|
ret=0
|
||||||
for gs in "${!groupshows[@]}"; do rungroup "$gs" || ret=1; done
|
for gs in "${!groupshows[@]}"; do rungroup "$gs" || ret=1; done
|
||||||
cleanup $ret
|
cleanup $ret
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user