From b3b957b92d66dcfa3452e377b1fa15b2342cd7b1 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 6 Apr 2018 14:25:00 +0200 Subject: send_media --- odin/strm/send_media | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 odin/strm/send_media (limited to 'odin/strm') diff --git a/odin/strm/send_media b/odin/strm/send_media new file mode 100644 index 00000000..4f3e576b --- /dev/null +++ b/odin/strm/send_media @@ -0,0 +1,81 @@ +#!@zsh@/bin/zsh + +logTag=${0:t} + +exec 1> >(logger -t "$logTag" -p news.notice) +exec 2> >(logger -t "$logTag" -p news.error) + +debug() { logger -t "$logTag" -p news.debug } + +function notmuch { + msg1=1 + while true; do + result=$(env NOTMUCH_CONFIG=${HOME}/.notmuch-rss-config @notmuch@/bin/notmuch $@) + if ! [[ "$result" =~ "already locked" ]]; then + echo -nE "$result" + return + else + [[ $msg1 == "1" ]] && echo "Already locked" >&2 + msg1=0 + fi + sleep 2 + done +} + +urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } + +force=0 +if [[ "$1" == "-f" ]]; then + shift + force=1 + if [[ -n "$1" && "$1" -eq "$1" ]] 2>/dev/null; then + force="$1" + shift + fi +fi + +# print $force + +msg=1 + +typeset -a checkedIds +checkedIds=() +typeset -a ids +ids=() + +while { + results=$(notmuch search --sort=oldest-first --output=messages "( tag:inbox AND is:cached AND is:media ) AND NOT ( tag:killed OR tag:failed OR tag:tv )") + ids=("${(f)results}") + for i in $checkedIds; do + ids=(${ids#$i}) + done + checkedIds=($checkedIds $ids) +} && [[ -n "${ids}" ]]; do + url="" + for id ($ids); do + message=$(notmuch search --output=files --duplicate=1 ${id}) + + ( flock -sn 9 || { printf "Could not lock ā€˜%sā€™\n" ${id} | debug; exit 0 } + + url=$(notmuch show ${id} | sed -r '/]+href="http:\/\/odin\.asgard\.yggdrasil\//!d; s!^.*]+href="(http://odin\.asgard\.yggdrasil/[^"]+)".*$!\1!; s|http://([^/]+)/|/srv/media/|; q' | urldecode) + printf "Found ā€˜%sā€™\n" "${url}" | debug + if [[ -z "${url}" || ! -e "${url}" ]]; then + echo "thread ${id} not associated with any file or url, tagging for retry" >&2 + # notmuch search --output=files --format=text ${(q)id} \ + # | xargs -n 1 basename \ + # | xargs -I '{}' -- sed -i "/{}/d" .youtube-cache + notmuch tag -cached -- ${id} + continue + fi + typeset -a args + args=("${url}") + if [[ "${force}" -gt 0 ]]; then + args=(-f $args) + force=$(($force - 1)) + fi + queue.hel $args && notmuch tag -unread -inbox -- ${(q)id} + ) 9<>"${message}" + done +done + +[[ -z "${checkedIds}" ]] && queue.hel -- cgit v1.2.3