diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-06 14:25:00 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-06 14:25:00 +0200 |
commit | b3b957b92d66dcfa3452e377b1fa15b2342cd7b1 (patch) | |
tree | 1c444f585a511c89ea7357986327f6b8c2e9efc0 /odin/strm | |
parent | be500c469b5a6d8999bca710665dcbfdfd96282d (diff) | |
download | nixos-b3b957b92d66dcfa3452e377b1fa15b2342cd7b1.tar nixos-b3b957b92d66dcfa3452e377b1fa15b2342cd7b1.tar.gz nixos-b3b957b92d66dcfa3452e377b1fa15b2342cd7b1.tar.bz2 nixos-b3b957b92d66dcfa3452e377b1fa15b2342cd7b1.tar.xz nixos-b3b957b92d66dcfa3452e377b1fa15b2342cd7b1.zip |
send_media
Diffstat (limited to 'odin/strm')
-rw-r--r-- | odin/strm/send_media | 81 |
1 files changed, 81 insertions, 0 deletions
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 @@ | |||
1 | #!@zsh@/bin/zsh | ||
2 | |||
3 | logTag=${0:t} | ||
4 | |||
5 | exec 1> >(logger -t "$logTag" -p news.notice) | ||
6 | exec 2> >(logger -t "$logTag" -p news.error) | ||
7 | |||
8 | debug() { logger -t "$logTag" -p news.debug } | ||
9 | |||
10 | function notmuch { | ||
11 | msg1=1 | ||
12 | while true; do | ||
13 | result=$(env NOTMUCH_CONFIG=${HOME}/.notmuch-rss-config @notmuch@/bin/notmuch $@) | ||
14 | if ! [[ "$result" =~ "already locked" ]]; then | ||
15 | echo -nE "$result" | ||
16 | return | ||
17 | else | ||
18 | [[ $msg1 == "1" ]] && echo "Already locked" >&2 | ||
19 | msg1=0 | ||
20 | fi | ||
21 | sleep 2 | ||
22 | done | ||
23 | } | ||
24 | |||
25 | urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } | ||
26 | |||
27 | force=0 | ||
28 | if [[ "$1" == "-f" ]]; then | ||
29 | shift | ||
30 | force=1 | ||
31 | if [[ -n "$1" && "$1" -eq "$1" ]] 2>/dev/null; then | ||
32 | force="$1" | ||
33 | shift | ||
34 | fi | ||
35 | fi | ||
36 | |||
37 | # print $force | ||
38 | |||
39 | msg=1 | ||
40 | |||
41 | typeset -a checkedIds | ||
42 | checkedIds=() | ||
43 | typeset -a ids | ||
44 | ids=() | ||
45 | |||
46 | while { | ||
47 | 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 )") | ||
48 | ids=("${(f)results}") | ||
49 | for i in $checkedIds; do | ||
50 | ids=(${ids#$i}) | ||
51 | done | ||
52 | checkedIds=($checkedIds $ids) | ||
53 | } && [[ -n "${ids}" ]]; do | ||
54 | url="" | ||
55 | for id ($ids); do | ||
56 | message=$(notmuch search --output=files --duplicate=1 ${id}) | ||
57 | |||
58 | ( flock -sn 9 || { printf "Could not lock ā%sā\n" ${id} | debug; exit 0 } | ||
59 | |||
60 | url=$(notmuch show ${id} | sed -r '/<a[^>]+href="http:\/\/odin\.asgard\.yggdrasil\//!d; s!^.*<a[^>]+href="(http://odin\.asgard\.yggdrasil/[^"]+)".*$!\1!; s|http://([^/]+)/|/srv/media/|; q' | urldecode) | ||
61 | printf "Found ā%sā\n" "${url}" | debug | ||
62 | if [[ -z "${url}" || ! -e "${url}" ]]; then | ||
63 | echo "thread ${id} not associated with any file or url, tagging for retry" >&2 | ||
64 | # notmuch search --output=files --format=text ${(q)id} \ | ||
65 | # | xargs -n 1 basename \ | ||
66 | # | xargs -I '{}' -- sed -i "/{}/d" .youtube-cache | ||
67 | notmuch tag -cached -- ${id} | ||
68 | continue | ||
69 | fi | ||
70 | typeset -a args | ||
71 | args=("${url}") | ||
72 | if [[ "${force}" -gt 0 ]]; then | ||
73 | args=(-f $args) | ||
74 | force=$(($force - 1)) | ||
75 | fi | ||
76 | queue.hel $args && notmuch tag -unread -inbox -- ${(q)id} | ||
77 | ) 9<>"${message}" | ||
78 | done | ||
79 | done | ||
80 | |||
81 | [[ -z "${checkedIds}" ]] && queue.hel | ||