#!@zsh@/bin/zsh function notmuch { while true; do result=$(env NOTMUCH_CONFIG=${HOME}/.notmuch-rss-config @notmuch@/bin/notmuch "$@" 2>&1) if ! [[ $result =~ "already locked" ]]; then echo -nE $result return fi sleep 2 done } tagFile="" function cleanup { [[ -n "${tagFile}" ]] && rm -fv ${tagFile} } urldecode() { local x="${$(cat)//+/ }"; echo -e "${x//\%/\\x}" } @rollingdirectory@/bin/rolling-directory /srv/media/youtube 50Gi notmuch search --output=messages --format=text 'is:cached' | \ while read id; do untag=false url=$(notmuch show --format=raw "$id" | grep 'http://odin.asgard.yggdrasil/youtube' | sed -r 's|^.*href="http://odin.asgard.yggdrasil/youtube/([^"]+)".*$|\1|' | urldecode ) printf "%s\n ‘%s’\n" ${id} ${dir}/${url} if [[ -z "${url}" ]]; then printf " Could not extract filename.\n" untag=true fi if [[ -n "${url}" && ! -e "${dir}/${url}" ]]; then printf " File vanished\n" untag=true fi if ${untag}; then if [[ -z "${tagFile}" ]]; then tagFile=$(mktemp --tmpdir $$.tags.XXXXXXXXXX) printf "Using %s\n" ${tagFile} fi { printf "-cached -- %s\n" ${id} >> ${tagFile} } && printf " Tagging ‘-cached’...\n" fi done [[ -n "${tagFile}" ]] && notmuch tag --batch --input=${tagFile}