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 | |
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')
-rw-r--r-- | odin/strm.nix | 3 | ||||
-rw-r--r-- | odin/strm/send_media | 81 |
2 files changed, 83 insertions, 1 deletions
diff --git a/odin/strm.nix b/odin/strm.nix index 33e605af..36d0e876 100644 --- a/odin/strm.nix +++ b/odin/strm.nix | |||
@@ -11,11 +11,12 @@ stdenv.mkDerivation { | |||
11 | buildPhase = '' | 11 | buildPhase = '' |
12 | substituteAllInPlace download_youtube | 12 | substituteAllInPlace download_youtube |
13 | substituteAllInPlace cleanup_youtube | 13 | substituteAllInPlace cleanup_youtube |
14 | substituteAllInPlace send_media | ||
14 | ''; | 15 | ''; |
15 | 16 | ||
16 | installPhase = '' | 17 | installPhase = '' |
17 | mkdir -p $out/bin | 18 | mkdir -p $out/bin |
18 | 19 | ||
19 | install -m 755 -t $out/bin download_youtube cleanup_youtube | 20 | install -m 755 -t $out/bin download_youtube cleanup_youtube send_media |
20 | ''; | 21 | ''; |
21 | } | 22 | } |
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 | ||