summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odin/strm.nix3
-rw-r--r--odin/strm/send_media81
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
3logTag=${0:t}
4
5exec 1> >(logger -t "$logTag" -p news.notice)
6exec 2> >(logger -t "$logTag" -p news.error)
7
8debug() { logger -t "$logTag" -p news.debug }
9
10function 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
25urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
26
27force=0
28if [[ "$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
35fi
36
37# print $force
38
39msg=1
40
41typeset -a checkedIds
42checkedIds=()
43typeset -a ids
44ids=()
45
46while {
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
79done
80
81[[ -z "${checkedIds}" ]] && queue.hel